<commit_before><?php

namespace Smrtr;

/**
 * Class HaltoRouter
 *
 * This is a fork of https://github.com/dannyvankooten/AltoRouter with hostname matching built in
 * and basepath functionality stripped out.
 *
 * @package Smrtr
 * @author <NAME>
 */
class HaltoRouter
{
    /**
     * @var array
     */
    protected $routes = array();

    /**
     * @var array
     */
    protected $namedRoutes = array();

    /**
     * @var array
     */
    protected $httpHostGroups = array();

    /**
     * Add a hostname to a hostgroup (creates the hostgroup if it doesn't exist).
     *
     * @param string $hostname
     * @param string $hostGroup
     *
     * @return $this
     *
     * @throws HaltoRouterException
     */
    public function addHostname($hostname, $hostGroup)
    {
        if (!is_string($hostGroup)) {
            throw new HaltoRouterException("Invalid hostgroup name");
        }

        if (!is_string($hostname)) {
            throw new HaltoRouterException("Invalid hostname");
        }

        if (!array_key_exists($hostGroup, $this->httpHostGroups)) {
            $this->httpHostGroups[$hostGroup] = array();
        }

        if (!in_array($hostname, $this->httpHostGroups[$hostGroup])) {
            $this->httpHostGroups[$hostGroup][] = $hostname;
        }

        return $this;
    }

    /**
     * Add an array of hostnames to a hostgroup (creates the hostgroup if it doesn't exist).
     *
     * @param array $hostnames
     * @param string $hostGroup
     *
     * @return $this
     *
     * @throws HaltoRouterException
     */
    public function addHostnames(array $hostnames, $hostGroup)
    {
        if (!is_string($hostGroup)) {
            throw new HaltoRouterException("Invalid hostgroup name");
        }

        if (!is_array($hostnames)) {
            throw new HaltoRouterException("Array of hostnames expected");
        }

        if (!array_key_exists($hostGroup, $this->httpHostGroups)) {
            $this->httpHostGroups[$hostGroup] = array();
        }

        foreach ($hostnames as $hostname) {
            if (!is_string($hostname)) {
                continue;
            }
            if (!in_array($hostname, $this->httpHostGroups[$hostGroup])) {
                $this->httpHostGroups[$hostGroup][] = $hostname;
            }
        }

        return $this;
    }

    /**
     * @return array
     */
    public function getHostgroups()
    {
        return $this->httpHostGroups;
    }

    /**
     * Add a route mapping to the router.
     *
     * @param string $method One, or a pipe-separated list, of Http Methods (GET|POST|PUT|DELETE)
     * @param string $route The route. Custom regex starts with @. You can use pre-set regex filters, like [i:id]
     * @param mixed  $target The target where this route should point to. Can be anything.
     * @param string $name Optional name of the route. Supply if you want to reverse route this url in your application.
     * @param string $hostGroup Optional hostGroup bound to route - the route will only match requests on these hosts.
     * @param bool   $prepend Optional
     *
     * @return $this
     *
     * @throws HaltoRouterException
     */
    public function map($method, $route, $target, $name = null, $hostGroup = null, $prepend = false)
    {
        $route = rtrim($route, '/');
        if (!$hostGroup) {
            $hostGroup = null;
        }

        if ($prepend) {
            array_unshift($this->routes, array($method, $route, $target, $name, $hostGroup));
        } else {
            $this->routes[] = array($method, $route, $target, $name, $hostGroup);
        }

        if ($name) {<commit_msg>Fixed test case for empty route<commit_after><?php

namespace Smrtr;

/**
 * Class HaltoRouter
 *
 * This is a fork of https://github.com/dannyvankooten/AltoRouter with hostname matching built in
 * and basepath functionality stripped out.
 *
 * @package Smrtr
 * @author <NAME>
 */
class HaltoRouter
{
    /**
     * @var array
     */
    protected $routes = array();

    /**
     * @var array
     */
    protected $namedRoutes = array();

    /**
     * @var array
     */
    protected $httpHostGroups = array();

    /**
     * Add a hostname to a hostgroup (creates the hostgroup if it doesn't exist).
     *
     * @param string $hostname
     * @param string $hostGroup
     *
     * @return $this
     *
     * @throws HaltoRouterException
     */
    public function addHostname($hostname, $hostGroup)
    {
        if (!is_string($hostGroup)) {
            throw new HaltoRouterException("Invalid hostgroup name");
        }

        if (!is_string($hostname)) {
            throw new HaltoRouterException("Invalid hostname");
        }

        if (!array_key_exists($hostGroup, $this->httpHostGroups)) {
            $this->httpHostGroups[$hostGroup] = array();
        }

        if (!in_array($hostname, $this->httpHostGroups[$hostGroup])) {
            $this->httpHostGroups[$hostGroup][] = $hostname;
        }

        return $this;
    }

    /**
     * Add an array of hostnames to a hostgroup (creates the hostgroup if it doesn't exist).
     *
     * @param array $hostnames
     * @param string $hostGroup
     *
     * @return $this
     *
     * @throws HaltoRouterException
     */
    public function addHostnames(array $hostnames, $hostGroup)
    {
        if (!is_string($hostGroup)) {
            throw new HaltoRouterException("Invalid hostgroup name");
        }

        if (!is_array($hostnames)) {
            throw new HaltoRouterException("Array of hostnames expected");
        }

        if (!array_key_exists($hostGroup, $this->httpHostGroups)) {
            $this->httpHostGroups[$hostGroup] = array();
        }

        foreach ($hostnames as $hostname) {
            if (!is_string($hostname)) {
                continue;
            }
            if (!in_array($hostname, $this->httpHostGroups[$hostGroup])) {
                $this->httpHostGroups[$hostGroup][] = $hostname;
            }
        }

        return $this;
    }

    /**
     * @return array
     */
    public function getHostgroups()
    {
        return $this->httpHostGroups;
    }

    /**
     * Add a route mapping to the router.
     *
     * @param string $method One, or a pipe-separated list, of Http Methods (GET|POST|PUT|DELETE)
     * @param string $route The route. Custom regex starts with @. You can use pre-set regex filters, like [i:id]
     * @param mixed  $target The target where this route should point to. Can be anything.
     * @param string $name Optional name of the route. Supply if you want to reverse route this url in your application.
     * @param string $hostGroup Optional hostGroup bound to route - the route will only match requests on these hosts.
     * @param bool   $prepend Optional
     *
     * @return $this
     *
     * @throws HaltoRouterException
     */
    public function map($method, $route, $target, $name = null, $hostGroup = null, $prepend = false)
    {
        if (!$hostGroup) {
            $hostGroup = null;
        }

        if ($prepend) {
            array_unshift($this->routes, array($method, $route, $target, $name, $hostGroup));
        } else {
            $this->routes[] = array($method, $route, $target, $name, $hostGroup);
        }

        if ($name) {
{'fraction_non_alphanumeric': 0.1213532392822901, 'fraction_numerical': 0.0, 'mean_word_length': 2.1514889943892963, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 27, 'https://': 2, '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': '1429856', 'n_tokens_mistral': 2094, 'n_tokens_neox': 2075, 'n_words': 591}