<commit_before><?php
/**
 * @author    <NAME> <<EMAIL>>
 * @copyright Copyright (c) 2016, Darvin Studio
 * @link      https://www.darvin-studio.ru
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Darvin\MenuBundle\DependencyInjection\Compiler;

use Darvin\MenuBundle\Builder\Builder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\DefinitionDecorator;

/**
 * Create builders compiler pass
 */
class CreateBuildersPass implements CompilerPassInterface
{
    const PARENT_ID             = 'darvin_menu.abstract_builder';
    const PARENT_ID_BREADCRUMBS = 'darvin_menu.abstract_breadcrumbs_builder';

    const TAG_BUILDER = 'darvin_menu.builder';

    /**
     * {@inheritdoc}
     */
    public function process(ContainerBuilder $container)
    {
        $definitions = [];

        foreach ($this->getMenuConfig($container)->getMenus() as $menu) {
            $definitions[$menu->getBuilderId()] = $this->buildDefinition(self::PARENT_ID, $menu->getAlias(), $menu->getBuilderAlias());

            if ($menu->isBreadcrumbsEnabled()) {
                $definitions[$menu->getBreadcrumbsBuilderId()] = $this->buildDefinition(
                    self::PARENT_ID_BREADCRUMBS,
                    $menu->getAlias(),
                    $menu->getBreadcrumbsBuilderAlias()
                );
            }
        }

        $container->addDefinitions($definitions);
    }

    /**
     * @param string $parentId     Parent service ID
     * @param string $menuAlias    Menu alias
     * @param string $builderAlias Builder alias
     *
     * @return \Symfony\Component\DependencyInjection\Definition
     */
    private function buildDefinition($parentId, $menuAlias, $builderAlias)
    {
        return (new DefinitionDecorator($parentId))<commit_msg>Check if service definition already exists in create builders compiler pass.<commit_after><?php
/**
 * @author    <NAME> <<EMAIL>>
 * @copyright Copyright (c) 2016, Darvin Studio
 * @link      https://www.darvin-studio.ru
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Darvin\MenuBundle\DependencyInjection\Compiler;

use Darvin\MenuBundle\Builder\Builder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\DefinitionDecorator;

/**
 * Create builders compiler pass
 */
class CreateBuildersPass implements CompilerPassInterface
{
    const PARENT_ID             = 'darvin_menu.abstract_builder';
    const PARENT_ID_BREADCRUMBS = 'darvin_menu.abstract_breadcrumbs_builder';

    const TAG_BUILDER = 'darvin_menu.builder';

    /**
     * {@inheritdoc}
     */
    public function process(ContainerBuilder $container)
    {
        $definitions = [];

        foreach ($this->getMenuConfig($container)->getMenus() as $menu) {
            $definitions[$menu->getBuilderId()] = $this->buildDefinition(self::PARENT_ID, $menu->getAlias(), $menu->getBuilderAlias());

            if ($menu->isBreadcrumbsEnabled()) {
                $definitions[$menu->getBreadcrumbsBuilderId()] = $this->buildDefinition(
                    self::PARENT_ID_BREADCRUMBS,
                    $menu->getAlias(),
                    $menu->getBreadcrumbsBuilderAlias()
                );
            }
        }
        foreach ($definitions as $id => $attr) {
            if ($container->hasDefinition($id)) {
                throw new \InvalidArgumentException(sprintf('Service "%s" already exists. Please change menu alias.', $id));
            }
        }

        $container->addDefinitions($definitions);
    }

    /**
     * @param string $parentId     Parent service ID
     * @param string $menuAlias    Menu alias
     * @param string $builderAlias Builder alias
     *
     * @return \Symfony\Component\DependencyInjection\Definition
     */
    private function buildDefinition($parentId, $menuAlias, $builderAlias)
    {
        return (new DefinitionDecorator($parentId))
{'fraction_non_alphanumeric': 0.1106548026465891, 'fraction_numerical': 0.0018252338580880675, 'mean_word_length': 3.08574091332712, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 35, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '4621166', 'n_tokens_mistral': 1199, 'n_tokens_neox': 1168, 'n_words': 243}