<commit_before><?php

namespace Flagbit\Bundle\MetricsBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

class MetricsCollectorPass implements CompilerPassInterface
{
    /**
     * You can modify the container here before it is dumped to PHP code.
     *
     * @param ContainerBuilder $container
     *
     * @api
     */
    public function process(ContainerBuilder $container)
    {
        $ourFancyCollectorDefinition = $container->findDefinition('flagbit_metrics.collector');

        foreach ($container->findTaggedServiceIds('metrics.provider') as $id => $tags) {
            $collectors = array();
            foreach($tags as $attributes) {
                // FIXME collector is optional!

                $collectors[] = new Reference('beberlei_metrics.collector.' . $attributes['collector']);
            }

            $ourFancyCollectorDefinition->addMethodCall('addMetricsProvider', array(new Reference($id), $collectors));
        }
    }
}<commit_msg>Improved metrics collector pass error handling<commit_after><?php

namespace Flagbit\Bundle\MetricsBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

class MetricsCollectorPass implements CompilerPassInterface
{
    /**
     * Add tagged metrics.provider services to flagbit_metrics.collector service
     *
     * @param ContainerBuilder $container
     */
    public function process(ContainerBuilder $container)
    {
        if (false === $container->hasDefinition('flagbit_metrics.collector')) {
            return;
        }

        $definition = $container->getDefinition('flagbit_metrics.collector');

        foreach ($container->findTaggedServiceIds('metrics.provider') as $id => $tags) {
            $collectors = array();
            foreach($tags as $attributes) {
                // FIXME collector is optional!
                if (!isset($attributes['collector'])) {
                    throw new \InvalidArgumentException(sprintf(
                            'Metrics provider service "%s" must have an collector attribute in oder to specify a collector',
                            $id
                        ));
                }
                if ($container->hasDefinition('beberlei_metrics.collector.' . $attributes['collector'])) {
                    $collectors[] = new Reference('beberlei_metrics.collector.' . $attributes['collector']);
                }
            }

            if (!empty($collectors)) {
                $definition->addMethodCall('addMetricsProvider', array(new Reference($id), $collectors));
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.1042817679558011, 'fraction_numerical': 0.0, 'mean_word_length': 2.70460358056266, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '5007406', 'n_tokens_mistral': 710, 'n_tokens_neox': 684, 'n_words': 144}