<commit_before><?php

/**
 * Matcher Class File
 * 
 * PHP version 5.4
 * 
 * @category   artax
 * @package    core
 * @author     <NAME> <<EMAIL>>
 */

namespace artax {
  
  /**
   * Matcher Class
   * 
   * @category   artax
   * @package    core
   * @author     <NAME> <<EMAIL>>
   */
  class Matcher implements MatcherInterface
  {
    /**
     * @var RouteList
     */
    protected $routeList;
    
    /**
     * Route-matched controller name
     * @var string
     */
    protected $controller;
    
    /**
     * Ordered array of route-matched arguments
     * @var array
     */
    protected $args;
    
    /**
     * 
     */
    public function __construct(RouteList $routeList)
    {
      $this->args = [];
      $this->routeList = $routeList;
    }
    
    /**
     * Find a match for the requested resource target
     * 
     * @return bool Returns `TRUE` if a matching controller was found or `FALSE`
     *              if no match was located.
     */
    public function match(RequestInterface $request)
    {
      $match = FALSE;
      if ($this->routeList) {
        foreach ($this->routeList as $route) {
          if ($this->matchRoute($request, $route)) {
            $match = TRUE;
            break;
          }
        }
      }
      return $match;
    }
    
    /**
     * Determine if the specified route alias matches a route's pattern
     * 
     * If a regex match is found any controller arguments specified in the
     * route constraints array are stored in $this->matchedArgs for retrieval
     * on controller method invocation.
     * 
     * @param RequestInterface $request The request to match
     * @param RouteInterface   $route   The route object to match against
     * 
     * @return bool Returns `TRUE` on match or `FALSE` if no match
     */
    protected function matchRoute(RequestInterface $request, RouteInterface $route)
    {
      if ( ! preg_match($route->getPattern(), $request->getTarget(), $match)) {
        return FALSE;
      } else {
        $this->controller = $route->getController();
        if ($constraints = $route->getConstraints()) {
          $arr = array_intersect_key($match, $constraints);
          $this->args = array_values($arr)[0];
        }
        return TRUE;
      }
    }
    
    /**
     * Retrieve the matched route's dot-notation controller string
     * 
     * @return string
     */
    public function getController()
    {
      return $this->controller;<commit_msg>[Matcher] Fixed matcher argument parsing bug<commit_after><?php

/**
 * Matcher Class File
 * 
 * PHP version 5.4
 * 
 * @category   artax
 * @package    core
 * @author     <NAME> <<EMAIL>>
 */

namespace artax {
  
  /**
   * Matcher Class
   * 
   * @category   artax
   * @package    core
   * @author     <NAME> <<EMAIL>>
   */
  class Matcher implements MatcherInterface
  {
    /**
     * @var RouteList
     */
    protected $routeList;
    
    /**
     * Route-matched controller name
     * @var string
     */
    protected $controller;
    
    /**
     * Ordered array of route-matched arguments
     * @var array
     */
    protected $args;
    
    /**
     * 
     */
    public function __construct(RouteList $routeList)
    {
      $this->args = [];
      $this->routeList = $routeList;
    }
    
    /**
     * Find a match for the requested resource target
     * 
     * @return bool Returns `TRUE` if a matching controller was found or `FALSE`
     *              if no match was located.
     */
    public function match(RequestInterface $request)
    {
      $match = FALSE;
      if ($this->routeList) {
        foreach ($this->routeList as $route) {
          if ($this->matchRoute($request, $route)) {
            $match = TRUE;
            break;
          }
        }
      }
      return $match;
    }
    
    /**
     * Determine if the specified route alias matches a route's pattern
     * 
     * If a regex match is found any controller arguments specified in the
     * route constraints array are stored in $this->matchedArgs for retrieval
     * on controller method invocation.
     * 
     * @param RequestInterface $request The request to match
     * @param RouteInterface   $route   The route object to match against
     * 
     * @return bool Returns `TRUE` on match or `FALSE` if no match
     */
    protected function matchRoute(RequestInterface $request, RouteInterface $route)
    {
      if ( ! preg_match($route->getPattern(), $request->getTarget(), $match)) {
        return FALSE;
      } else {
        $this->controller = $route->getController();
        $constraints = $route->getConstraints();
        
        if ($constraints) {
          $arr = array_intersect_key($match, $constraints);
          $this->args = array_values($arr);
        }
        return TRUE;
      }
    }
    
    /**
     * Retrieve the matched route's dot-notation controller string
     * 
     * @return string
     */
    public function getController()
    {
      return $this->controller;
{'fraction_non_alphanumeric': 0.11060091834697544, 'fraction_numerical': 0.0009982032341784787, 'mean_word_length': 1.9127906976744187, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 41, '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': '5248129', 'n_tokens_mistral': 1415, 'n_tokens_neox': 1382, 'n_words': 409}