<commit_before><?php

namespace Rize;

use Rize\UriTemplate\Node;
use Rize\UriTemplate\Parser;

/**
 * URI Template
 */
class UriTemplate
{
             /**
              * @var Rize\UriTemplate\Parser
              */
    protected $parser,
              $parsed = array(),
              $base_uri,
              $params = array();

    public function __construct($base_uri = '', $params = array(), Node\Parser $parser = null)
    {
        $this->base_uri = $base_uri;
        $this->params   = $params;
        $this->parser   = $parser ?: $this->createNodeParser();
    }

    /**
     * Expands URI Template
     *
     * @param string $uri_template  URI Template
     * @param array  $params        URI Template's parameters
     */
    public function expand($uri, $params = array())
    {
        $params += $this->params;
        $uri     = $this->base_uri.$uri;
        $result  = array();

        # quick check
        if (($start = strpos($uri, '{')) === false) {
            return $uri;
        }

        $parser = $this->parser;
        $nodes  = $parser->parse($uri);

        foreach($nodes as $node) {
            $result[] = $node->expand($parser, $params);
        }

        return implode('', $result);
    }

    /**
     * Extracts variables from URI
     *
     * @param  string $uri
     * @return array  params
     */
    public function extract($template, $uri = null)
    {
        $params = array();
        $nodes  = $this->parser->parse($template);

        $regex = array();

        foreach($nodes as $node) {

            # uri'll be truncated from the start when a match is found
            list($uri, $params) = $node->match($this->parser, $uri, $params);
        }

        return $params;
    }

    protected function createNodeParser()
    {
        static $parser;

        if ($parser) {
            return $parser;
        }

        return $parser = new Parser;
    }
}<commit_msg>Remove another unused var<commit_after><?php

namespace Rize;

use Rize\UriTemplate\Node;
use Rize\UriTemplate\Parser;

/**
 * URI Template
 */
class UriTemplate
{
             /**
              * @var Rize\UriTemplate\Parser
              */
    protected $parser,
              $parsed = array(),
              $base_uri,
              $params = array();

    public function __construct($base_uri = '', $params = array(), Node\Parser $parser = null)
    {
        $this->base_uri = $base_uri;
        $this->params   = $params;
        $this->parser   = $parser ?: $this->createNodeParser();
    }

    /**
     * Expands URI Template
     *
     * @param string $uri_template  URI Template
     * @param array  $params        URI Template's parameters
     */
    public function expand($uri, $params = array())
    {
        $params += $this->params;
        $uri     = $this->base_uri.$uri;
        $result  = array();

        # quick check
        if (($start = strpos($uri, '{')) === false) {
            return $uri;
        }

        $parser = $this->parser;
        $nodes  = $parser->parse($uri);

        foreach($nodes as $node) {
            $result[] = $node->expand($parser, $params);
        }

        return implode('', $result);
    }

    /**
     * Extracts variables from URI
     *
     * @param  string $uri
     * @return array  params
     */
    public function extract($template, $uri = null)
    {
        $params = array();
        $nodes  = $this->parser->parse($template);

        foreach($nodes as $node) {

            # uri'll be truncated from the start when a match is found
            list($uri, $params) = $node->match($this->parser, $uri, $params);
        }

        return $params;
    }

    protected function createNodeParser()
    {
        static $parser;

        if ($parser) {
            return $parser;
        }

        return $parser = new Parser;
    }
}
{'fraction_non_alphanumeric': 0.14270860410709643, 'fraction_numerical': 0.0, 'mean_word_length': 1.7098591549295774, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, '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': '2610185', 'n_tokens_mistral': 1132, 'n_tokens_neox': 1095, 'n_words': 273}