<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\Bundle\FrameworkBundle\Debug;

use Symfony\Bundle\FrameworkBundle\ContainerAwareEventDispatcher;
use Symfony\Component\HttpKernel\Log\LoggerInterface;
use Symfony\Component\HttpKernel\Debug\TraceableEventDispatcherInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\Event;

/**
 * Extends the ContainerAwareEventDispatcher to add some debugging tools.
 *
 * @author <NAME> <<EMAIL>>
 */
class TraceableEventDispatcher extends ContainerAwareEventDispatcher implements TraceableEventDispatcherInterface
{
    private $logger;
    private $called;
    private $container;

    /**
     * Constructor.
     *
     * @param ContainerInterface $container A ContainerInterface instance
     * @param LoggerInterface    $logger    A LoggerInterface instance
     */
    public function __construct(ContainerInterface $container, LoggerInterface $logger = null)
    {
        parent::__construct($container);

        $this->container = $container;
        $this->logger = $logger;
        $this->called = array();
    }

    /**
     * {@inheritDoc}
     *
     * @throws \RuntimeException if the listener method is not callable
     */
    public function addListener($eventName, $listener, $priority = 0)
    {
        if (!is_callable($listener)) {
            if (is_string($listener)) {
                $type = '[string] '.$listener;
            } elseif (is_array($listener)) {
                $type = '[array] '.$listener[0].', '.$listener[1];
            } elseif (is_object($listener)) {
                $type = '[object] '.get_class($listener);
            } else {
                $type = '[?] '.var_export($listener, true);
            }
            $msg = sprintf('The given callback (%s) for event "%s" is not callable.', $type, $eventName);
            if (null !== $this->logger) {
                $this->logger->err($msg);
            }
            throw new \RuntimeException($msg);
        }

        parent::addListener($eventName, $listener, $priority);
    }

    /**
     * {@inheritDoc}
     */
    protected function doDispatch($listeners, $eventName, Event $event)
    {
        foreach ($listeners as $listener) {
            // TODO: remove this before final release, temporary transitional code
            if (is_object($listener) && method_exists($listener, $eventName)) {
                $listener->$eventName($event);
                trigger_error('Event listeners should now be registered using a complete callback as the listener instead of just an instance. Adjust your code ASAP.', E_USER_DEPRECATED);
            } else {
                // only this call should remain
                call_user_func($listener, $event);
            }

            $info = $this->getListenerInfo($listener, $eventName);

            if (null !== $this->logger) {
                $this->logger->debug(sprintf('Notified event "%s" to listener "%s".', $eventName, $info['pretty']));
            }

            $this->called[$eventName.'.'.$info['pretty']] = $info;

            if ($event->isPropagationStopped()) {
                if (null !== $this->logger) {
                    $this->logger->debug(sprintf('Listener "%s" stopped propagation of the event "%s".', $info['pretty'], $eventName));

                    $skippedListeners = $this->getListeners($eventName);
                    $skipped = false;

                    foreach ($skippedListeners as $skippedListener) {
                        if ($skipped) {
                            $typeDef = is_object($skippedListener)
                                ? get_class($skippedListener)
                                : is_array($skippedListener)
                                    ? is_object($skippedListener[0])
                                        ? get_class($skippedListener[0])
                                        : implode('::', $skippedListener)
                                    : implode('::', $skippedListener);
                            $this->logger->debug(sprintf('Listener "%s" was not called for event "%s".', $typeDef, $eventName));
                        }

                        if ($skippedListener === $listener) {
                            $skipped = true;
                        }
                    }
                }

                break;
            }
        }
    }

    /**
     * {@inheritDoc}
     */
    public function getCalledListeners()
    {
        return $this->called;
    }

    /**<commit_msg>[FrameworkBundle] Improved code readability<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\Bundle\FrameworkBundle\Debug;

use Symfony\Bundle\FrameworkBundle\ContainerAwareEventDispatcher;
use Symfony\Component\HttpKernel\Log\LoggerInterface;
use Symfony\Component\HttpKernel\Debug\TraceableEventDispatcherInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\Event;

/**
 * Extends the ContainerAwareEventDispatcher to add some debugging tools.
 *
 * @author <NAME> <<EMAIL>>
 */
class TraceableEventDispatcher extends ContainerAwareEventDispatcher implements TraceableEventDispatcherInterface
{
    private $logger;
    private $called;
    private $container;

    /**
     * Constructor.
     *
     * @param ContainerInterface $container A ContainerInterface instance
     * @param LoggerInterface    $logger    A LoggerInterface instance
     */
    public function __construct(ContainerInterface $container, LoggerInterface $logger = null)
    {
        parent::__construct($container);

        $this->container = $container;
        $this->logger = $logger;
        $this->called = array();
    }

    /**
     * {@inheritDoc}
     *
     * @throws \RuntimeException if the listener method is not callable
     */
    public function addListener($eventName, $listener, $priority = 0)
    {
        if (!is_callable($listener)) {
            if (is_string($listener)) {
                $typeDefinition = '[string] '.$listener;
            } elseif (is_array($listener)) {
                $typeDefinition = '[array] '.$listener[0].', '.$listener[1];
            } elseif (is_object($listener)) {
                $typeDefinition = '[object] '.get_class($listener);
            } else {
                $typeDefinition = '[?] '.var_export($listener, true);
            }
            $msg = sprintf('The given callback (%s) for event "%s" is not callable.', $typeDefinition, $eventName);
            if (null !== $this->logger) {
                $this->logger->err($msg);
            }
            throw new \RuntimeException($msg);
        }

        parent::addListener($eventName, $listener, $priority);
    }

    /**
     * {@inheritDoc}
     */
    protected function doDispatch($listeners, $eventName, Event $event)
    {
        foreach ($listeners as $listener) {
            // TODO: remove this before final release, temporary transitional code
            if (is_object($listener) && method_exists($listener, $eventName)) {
                $listener->$eventName($event);
                trigger_error('Event listeners should now be registered using a complete callback as the listener instead of just an instance. Adjust your code ASAP.', E_USER_DEPRECATED);
            } else {
                // only this call should remain
                call_user_func($listener, $event);
            }

            $info = $this->getListenerInfo($listener, $eventName);

            if (null !== $this->logger) {
                $this->logger->debug(sprintf('Notified event "%s" to listener "%s".', $eventName, $info['pretty']));
            }

            $this->called[$eventName.'.'.$info['pretty']] = $info;

            if ($event->isPropagationStopped()) {
                if (null !== $this->logger) {
                    $this->logger->debug(sprintf('Listener "%s" stopped propagation of the event "%s".', $info['pretty'], $eventName));

                    $skippedListeners = $this->getListeners($eventName);
                    $skipped = false;

                    foreach ($skippedListeners as $skippedListener) {
                        if ($skipped) {
                            if (is_object($skippedListener)) {
                                $typeDefinition = get_class($skippedListener);
                            } elseif (is_array($skippedListener)) {
                                if (is_object($skippedListener[0])) {
                                    $typeDefinition = get_class($skippedListener);
                                } else {
                                    $typeDefinition = implode('::', $skippedListener);
                                }
                            } else {
                                $typeDefinition = $skippedListener;
                            }
                            $this->logger->debug(sprintf('Listener "%s" was not called for event "%s".', $typeDefinition, $eventName));
                        }

                        if ($skippedListener === $listener) {
                            $skipped = true;
                        }
                    }
                }

                break;
            }
        }
    }

    /**
     * {@inheritDoc}
     */
    public function getCalledListeners()
    {
        return $this->called;
    }

    /**
{'fraction_non_alphanumeric': 0.12100082034454471, 'fraction_numerical': 0.0009228876127973749, 'mean_word_length': 1.8484228971962617, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3751733', 'n_tokens_mistral': 2472, 'n_tokens_neox': 2382, 'n_words': 576}