<commit_before><?php

namespace SymfonyBundles\BundleDependency;

use Symfony\Component\DependencyInjection\ContainerBuilder;

trait BundleDependency
{

    /**
     * @var bool
     */
    private $booted = false;

    /**
     * @var array
     */
    private $bundles = [];

    /**
     * @var array
     */
    private $instances = [];

    /**
     * {@inheritdoc}
     */
    public function build(ContainerBuilder $container)
    {
        $this->registerBundleDependencies($container);
    }

    /**
     * Register the bundle dependencies.
     *
     * @param ContainerBuilder $container
     *
     * @return void
     */
    protected function registerBundleDependencies(ContainerBuilder $container)
    {
        if (true === $this->booted) {
            return;
        }

        $this->bundles = $container->getParameter('kernel.bundles');

        $this->createBundles($this->getBundleDependencies());

        $container->setParameter('kernel.bundles', $this->bundles);

        $this->initializeBundles($container);

        $this->booted = true;
    }

    /**
     * Creating the instances of bundle dependencies.
     *
     * @param array $dependencies
     *
     * @return void
     */
    protected function createBundles(array $dependencies)
    {
        foreach ($dependencies as $bundleClass) {
            $name = substr($bundleClass, strrpos($bundleClass, '\\') + 1);

            if (false === isset($this->bundles[$name])) {
                $bundle = new $bundleClass();
                $this->bundles[$name] = $bundleClass;
                $this->instances[$name] = $bundle;

                if ($bundle instanceof BundleDependencyInterface) {
                    $this->createBundles($bundle->getBundleDependencies());
                }
            }
        }
    }

    /**
     * @param ContainerBuilder $container
     *
     * @return void
     */
    protected function initializeBundles(ContainerBuilder $container)
    {
        $extensions = [];

        foreach ($this->instances as $bundle) {
            if ($extension = $bundle->getContainerExtension()) {
                $container->registerExtension($extension);
                $extension->load([], $container);

                $extensions[] = $extension->getAlias();
            }

            $bundle->build($container);
        }

        foreach ($this->instances as $bundle) {
            $bundle->setContainer($container);
            $bundle->boot();
        }
    }

    /**
     * {@inheritdoc}
     */
    abstract public function getBundleDependencies();
}<commit_msg>Remove local variable which never used<commit_after><?php

namespace SymfonyBundles\BundleDependency;

use Symfony\Component\DependencyInjection\ContainerBuilder;

trait BundleDependency
{

    /**
     * @var bool
     */
    private $booted = false;

    /**
     * @var array
     */
    private $bundles = [];

    /**
     * @var array
     */
    private $instances = [];

    /**
     * {@inheritdoc}
     */
    public function build(ContainerBuilder $container)
    {
        $this->registerBundleDependencies($container);
    }

    /**
     * Register the bundle dependencies.
     *
     * @param ContainerBuilder $container
     *
     * @return void
     */
    protected function registerBundleDependencies(ContainerBuilder $container)
    {
        if (true === $this->booted) {
            return;
        }

        $this->bundles = $container->getParameter('kernel.bundles');

        $this->createBundles($this->getBundleDependencies());

        $container->setParameter('kernel.bundles', $this->bundles);

        $this->initializeBundles($container);

        $this->booted = true;
    }

    /**
     * Creating the instances of bundle dependencies.
     *
     * @param array $dependencies
     *
     * @return void
     */
    protected function createBundles(array $dependencies)
    {
        foreach ($dependencies as $bundleClass) {
            $name = substr($bundleClass, strrpos($bundleClass, '\\') + 1);

            if (false === isset($this->bundles[$name])) {
                $bundle = new $bundleClass();
                $this->bundles[$name] = $bundleClass;
                $this->instances[$name] = $bundle;

                if ($bundle instanceof BundleDependencyInterface) {
                    $this->createBundles($bundle->getBundleDependencies());
                }
            }
        }
    }

    /**
     * @param ContainerBuilder $container
     *
     * @return void
     */
    protected function initializeBundles(ContainerBuilder $container)
    {
        foreach ($this->instances as $bundle) {
            if ($extension = $bundle->getContainerExtension()) {
                $container->registerExtension($extension);

                $extension->load([], $container);
            }

            $bundle->build($container);
        }

        foreach ($this->instances as $bundle) {
            $bundle->setContainer($container);
            $bundle->boot();
        }
    }

    /**
     * {@inheritdoc}
     */
    abstract public function getBundleDependencies();
}
{'fraction_non_alphanumeric': 0.13405088062622308, 'fraction_numerical': 0.0003913894324853229, 'mean_word_length': 1.9715116279069766, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 50, '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': '5283450', 'n_tokens_mistral': 1380, 'n_tokens_neox': 1306, 'n_words': 248}