<commit_before><?php

/*
 * This file is part of the APYBreadcrumbTrailBundle.
 *
 * (c) Abhoryo <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace APY\BreadcrumbTrailBundle\BreadcrumbTrail;

use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

class Trail implements \IteratorAggregate, \Countable
{
    /**
     * @var Breadcrumb[] Array of breadcrumbs
     */
    private $breadcrumbs;

    /**
     * @var UrlGeneratorInterface URL generator class
     */
    private $router;

    /**
     * Constructor.
     *
     * @param UrlGeneratorInterface $router URL generator class
     */
    public function __construct(UrlGeneratorInterface $router)
    {
        $this->router = $router;
        $this->breadcrumbs = new \SplObjectStorage();
    }

    /**
     * Add breadcrumb
     *
     * @param mixed   $breadcrumb_or_title  A Breadcrumb instance or the title of the breadcrumb
     * @param string  $routeName            The name of the route
     * @param mixed   $routeParameters      An array of parameters for the route
     * @param Boolean $routeAbsolute        Whether to generate an absolute URL
     * @return BreadcrumbTrail
     */
    function add($breadcrumb_or_title, $routeName = null, $routeParameters = array(), $routeAbsolute = false)
    {
        if ($breadcrumb_or_title instanceof Breadcrumb) {
            $this->breadcrumbs->attach($breadcrumb_or_title);
        } else {
            if (!is_string($breadcrumb_or_title)) {
                throw new \InvalidArgumentException('The title of a breadcrumb must be a string.');
            }

            $url = null;
            if ( !is_null($routeName) ) {
                if (is_null($this->router->getRouteCollection()->get($routeName)) )  {
                    throw new \InvalidArgumentException('You must define a existed route for your breadcrumb.');
                }
                $url = $this->router->generate($routeName, $routeParameters, $routeAbsolute);
            }

            $this->breadcrumbs->attach(new Breadcrumb($breadcrumb_or_title, $url));
        }

        return $this;
    }

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

    /**
     * {@inheritDoc}
     */
    public function getIterator() {
        return $this->breadcrumbs;
    }
}<commit_msg>Fix #1 (1/2)<commit_after><?php

/*
 * This file is part of the APYBreadcrumbTrailBundle.
 *
 * (c) Abhoryo <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace APY\BreadcrumbTrailBundle\BreadcrumbTrail;

use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

class Trail implements \IteratorAggregate, \Countable
{
    /**
     * @var Breadcrumb[] Array of breadcrumbs
     */
    private $breadcrumbs;

    /**
     * @var UrlGeneratorInterface URL generator class
     */
    private $router;

    /**
     * Constructor.
     *
     * @param UrlGeneratorInterface $router URL generator class
     */
    public function __construct(UrlGeneratorInterface $router)
    {
        $this->router = $router;
        $this->breadcrumbs = new \SplObjectStorage();
    }

    /**
     * Add breadcrumb
     *
     * @param mixed   $breadcrumb_or_title  A Breadcrumb instance or the title of the breadcrumb
     * @param string  $routeName            The name of the route
     * @param mixed   $routeParameters      An array of parameters for the route
     * @param Boolean $routeAbsolute        Whether to generate an absolute URL
     * @return self
     */
    function add($breadcrumb_or_title, $routeName = null, $routeParameters = array(), $routeAbsolute = false)
    {
        if ($breadcrumb_or_title instanceof Breadcrumb) {
            $this->breadcrumbs->attach($breadcrumb_or_title);
        } else {
            if (!is_string($breadcrumb_or_title)) {
                throw new \InvalidArgumentException('The title of a breadcrumb must be a string.');
            }

            $url = null;
            if ( !is_null($routeName) ) {
                if (is_null($this->router->getRouteCollection()->get($routeName)) )  {
                    throw new \InvalidArgumentException('You must define a existed route for your breadcrumb.');
                }
                $url = $this->router->generate($routeName, $routeParameters, $routeAbsolute);
            }

            $this->breadcrumbs->attach(new Breadcrumb($breadcrumb_or_title, $url));
        }

        return $this;
    }

    /**
     * Reset the trail
     *
     * @return self
     */
    public function reset() {
        $this->breadcrumbs->removeAll($this->breadcrumbs);

        return $this;
    }

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

    /**
     * {@inheritDoc}
     */
    public function getIterator() {
        return $this->breadcrumbs;
    }
}
{'fraction_non_alphanumeric': 0.10802286615414942, 'fraction_numerical': 0.0005913660555884093, 'mean_word_length': 2.27143778207608, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 38, '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': '889926', 'n_tokens_mistral': 1452, 'n_tokens_neox': 1432, 'n_words': 367}