<commit_before><?php

namespace Ibuildings\QaTools\Core\Application\Compiler;

use Ibuildings\QaTools\Core\Exception\LogicException;
use Ibuildings\QaTools\Core\Project\ProjectType;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;

final class RegisterConfiguratorsCompilerPass implements CompilerPassInterface
{
    public function process(ContainerBuilder $container)
    {
        $configuratorRegistryDefinition = $container->findDefinition('qa_tools.configurator_registry');
        $taggedConfigurators = $container->findTaggedServiceIds('qa_tools.tool');

        foreach ($taggedConfigurators as $configurator => $tags) {
            foreach ($tags as $tag) {
                if (!isset($tag['project_type'])) {
                    throw new LogicException(sprintf(
                        'Cannot register Configurator "%s" for a ProjectType: property "project_type" not found on tag',
                        $configurator
                    ));
                }

                $projectType = new ProjectType($tag['project_type']);

                $projectTypeDefinition = new Definition(ProjectType::class, [$projectType->getProjectType()]);
                $container->setDefinition(
                    'qa_tools.project.project_type.' . $projectType->getProjectType(),
                    $projectTypeDefinition
                );

                $configuratorRegistryDefinition->addMethodCall(
                    'registerFor',
                    [
                        new Reference($configurator),
                        $projectTypeDefinition,
                    ]
                );<commit_msg>Don't register project types as public services unneededly<commit_after><?php

namespace Ibuildings\QaTools\Core\Application\Compiler;

use Ibuildings\QaTools\Core\Exception\LogicException;
use Ibuildings\QaTools\Core\Project\ProjectType;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;

final class RegisterConfiguratorsCompilerPass implements CompilerPassInterface
{
    public function process(ContainerBuilder $container)
    {
        $configuratorRegistryDefinition = $container->findDefinition('qa_tools.configurator_registry');
        $taggedConfigurators = $container->findTaggedServiceIds('qa_tools.tool');

        foreach ($taggedConfigurators as $configurator => $tags) {
            foreach ($tags as $tag) {
                if (!isset($tag['project_type'])) {
                    throw new LogicException(sprintf(
                        'Cannot register Configurator "%s" for a ProjectType: property "project_type" not found on tag',
                        $configurator
                    ));
                }

                $projectType = new ProjectType($tag['project_type']);
                $projectTypeDefinition = new Definition(ProjectType::class, [$projectType->getProjectType()]);

                $configuratorRegistryDefinition->addMethodCall(
                    'registerFor',
                    [
                        new Reference($configurator),
                        $projectTypeDefinition,
                    ]
                );
{'fraction_non_alphanumeric': 0.08944954128440367, 'fraction_numerical': 0.0, 'mean_word_length': 2.4785643070787637, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '6440460', 'n_tokens_mistral': 842, 'n_tokens_neox': 797, 'n_words': 149}