<?php

declare(strict_types=1);

namespace Overblog\GraphQLBundle\Definition;

use Overblog\GraphQLBundle\Definition\ConfigProcessor\ConfigProcessorInterface;

final class ConfigProcessor
{
    /**
     * @var ConfigProcessorInterface[]
     */
    private array $processors;

    public function __construct(iterable $processors)
    {
        foreach ($processors as $processor) {
            $this->register($processor);
        }
    }

    public function getProcessors(): array
    {
        return $this->processors;
    }

    public function register(ConfigProcessorInterface $configProcessor): void
    {
        $this->processors[] = $configProcessor;
    }

    /**
     * @phpstan-template T of array
     * @phpstan-param T $config
     * @phpstan-return T
     */
    public function process(array $config): array
    {
        foreach ($this->processors as $processor) {
            $config = $processor->process($config);
        }

        return $config;
    }
}

<?php

declare(strict_types=1);

namespace Overblog\GraphQLBundle\Definition;

use Overblog\GraphQLBundle\Definition\ConfigProcessor\ConfigProcessorInterface;

final class ConfigProcessor
{
    /**
     * @var ConfigProcessorInterface[]
     */
    private array $processors = [];

    public function __construct(iterable $processors)
    {
        foreach ($processors as $processor) {
            $this->register($processor);
        }
    }

    public function getProcessors(): array
    {
        return $this->processors;
    }

    public function register(ConfigProcessorInterface $configProcessor): void
    {
        $this->processors[] = $configProcessor;
    }

    /**
     * @phpstan-template T of array
     * @phpstan-param T $config
     * @phpstan-return T
     */
    public function process(array $config): array
    {
        foreach ($this->processors as $processor) {
            $config = $processor->process($config);
        }

        return $config;
    }
}

Define default value for `$processors`
Define default value for `$processors`

This makes it possible to initialize a `ConfigProcessor` that has no processors.

Solves this error:

Typed property Overblog\GraphQLBundle\Definition\ConfigProcessor::$processors must not be accessed before initialization.