<commit_before><?php

/*
 * This file is part of the Symfony package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Validator\NodeVisitor;

use Symfony\Component\Validator\Node\ClassNode;
use Symfony\Component\Validator\Node\Node;
use Symfony\Component\Validator\ObjectInitializerInterface;

/**
 * @since  %%NextVersion%%
 * @author <NAME> <<EMAIL>>
 */
class ObjectInitializer extends AbstractVisitor
{
    /**
     * @var ObjectInitializerInterface[]
     */
    private $initializers;

    public function __construct(array $initializers)
    {
        foreach ($initializers as $initializer) {
            if (!$initializer instanceof ObjectInitializerInterface) {
                throw new \LogicException('Validator initializers must implement ObjectInitializerInterface.');
            }
        }

        $this->initializers = $initializers;
    }

    public function enterNode(Node $node)
    {
        if (!$node instanceof ClassNode) {
            return;
        }

        foreach ($this->initializers as $initializer) {
            $initializer->initialize($node->value);
        }
    }
}<commit_msg>[Validator] Throw exception if ObjectInitializer is constructed without visitors<commit_after><?php

/*
 * This file is part of the Symfony package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Validator\NodeVisitor;

use Symfony\Component\Validator\Node\ClassNode;
use Symfony\Component\Validator\Node\Node;
use Symfony\Component\Validator\ObjectInitializerInterface;

/**
 * @since  %%NextVersion%%
 * @author <NAME> <<EMAIL>>
 */
class ObjectInitializer extends AbstractVisitor
{
    /**
     * @var ObjectInitializerInterface[]
     */
    private $initializers;

    public function __construct(array $initializers)
    {
        foreach ($initializers as $initializer) {
            if (!$initializer instanceof ObjectInitializerInterface) {
                throw new \InvalidArgumentException('Validator initializers must implement ObjectInitializerInterface.');
            }
        }

        // If no initializer is present, this visitor should not even be created
        if (0 === count($initializers)) {
            throw new \InvalidArgumentException('Please pass at least one initializer.');
        }

        $this->initializers = $initializers;
    }

    public function enterNode(Node $node)
    {
        if (!$node instanceof ClassNode) {
            return;
        }

        foreach ($this->initializers as $initializer) {
            $initializer->initialize($node->value);
        }
    }
}
{'fraction_non_alphanumeric': 0.10336283185840708, 'fraction_numerical': 0.00035398230088495576, 'mean_word_length': 2.8872077028885834, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2210058', 'n_tokens_mistral': 725, 'n_tokens_neox': 716, 'n_words': 205}