Clean up, return key/value pairs

@param  array $matched
@return array
@access protected
423
protected function clearPairs(/*# array */ $matched)/*# : array */
    {
        $pairs = [];
        foreach ($matched as $m) {
            // source another env file
            if (isset($m[5])) {
                $file = trim($m[5]);
                $pairs[$file] = $this->source_marker;

            // value found
            } elseif (isset($m[3])) {
                $pairs[$m[1]] = $m[3];

            // no value defined
            } else {
                $pairs[$m[1]] = '';
            }
        }
        return $pairs;
    }
1204115
public static function selectMatchList(
        $matchState
    ) {
        $matchState = (object) $matchState;

        $matchList = [];
        foreach ($matchState->match as $matchKey => $matchItem) {
            $matchList[$matchKey] = $matchItem;
        }

        return $matchList;
    }
604363
protected function getMatchArgs(array $match)
    {
        // Remove the first element, the matching regex
        array_shift($match);

        // Iterate through the arguments and remove any unwanted slashes
        foreach ($match as &$arg) {
            $arg = trim($arg, '/');
        }

        return $match;
    }
1215337
private function resolveTag(array $match)
    {
        $tagReflector = $this->createLinkOrSeeTagFromRegexMatch($match);
        if (!$tagReflector instanceof See && !$tagReflector instanceof Link) {
            return $match;
        }

        $link = $this->getLinkText($tagReflector);
        $description = (string) $tagReflector->getDescription();

        if ($this->isUrl($link)) {
            return $this->generateMarkdownLink($link, $description ?: $link);
        }

        $link = $this->resolveQsen($link);
        $element = $this->findElement($link);
        if (!$element) {
            return (string) $link;
        }

        return $this->resolveElement($element, $link, $description);
    }
1355566
private static function compileFound($routes, $matched){
    $route_vars = [];
    foreach($routes as $pos => $raw){
      $root = "R$pos";
      if(isset($matched[$root])){
        $root_length = strlen($root);
        $route_vars[$routes[$pos]] = [];
        foreach($matched as $key => $match){
          if(!is_numeric($key) && $key !== $root && $key !== 'all_urls'){
            $new_key = substr($key, $root_length+1);
            $route_vars[$routes[$pos]][$new_key] = array_pop($match);
          }
        }
      }
    }
    return $route_vars;
  }
1298710
protected function convertKeys(array $meta) {
        $return = [];
        foreach ($meta as $key => $value) {
            if (is_array($value)) {
                $value = $this->convertKeys($value);
            }
            $newKey = strtolower($key);
            $newKey = preg_replace('/[^\w+]/', '_', $newKey);
            $return[$newKey] = $value;
        }
        return $return;
    }
908699
protected function matchToKeys(array $matches)
    {
        $parameterNames = $this->parameterNames();

        if (count($parameterNames) == 0) {
            return array();
        }

        $parameters = array_intersect_key($matches, array_flip($parameterNames));

        return array_filter($parameters, function ($value)
        {
            return is_string($value) && (strlen($value) > 0);
        });
    }
786913
protected static function cleanPre($matches)
    {
        if (is_array($matches))
        {
            $text = $matches[1] . $matches[2] . "</pre>";
        }
        else
        {
            $text = $matches;
        }

        $text = str_replace('<br />', '', $text);
        $text = str_replace('<p>', "\n", $text);
        $text = str_replace('</p>', '', $text);

        return $text;
    }
552180
private function extractValues(array $values, $prefix, $removePrefixFromKeys = true)
    {
        if (empty($values)) {
            return array();
        }

        $validKeys = array_filter(array_keys($values), function($name) use ($prefix) {
            return (0 === strpos($name, $prefix));
        });

        $results = array_intersect_key($values, array_flip($validKeys));
        if (!$removePrefixFromKeys) {
            return $results;
        }

        return array_combine(
            array_map(function($key) use ($prefix) {
                return str_replace($prefix, '', $key);
            }, array_keys($results)), $results
        );
    }
432370
public function asArray($mixed): ?array
    {
        $data = $this->_simpleXml($mixed);
        return $data ? $this->_asArray($data) : null;
    }
200475
public function keys($pattern = null) {

        $keys = array();
        $stmt = $this->connection->query("SELECT `key` FROM ".$this->table." ORDER BY `key`;");
        $res  = $stmt->fetchAll(\PDO::FETCH_ASSOC);

        if (!$pattern) {

            foreach ($res as $record) {
                $keys[] = $record["key"];
            }

        } else {

            $matcher = function_exists('fnmatch') ? 'fnmatch': function($pattern, $string){
                return preg_match("#^".strtr(preg_quote($pattern, '#'), array('\*' => '.*', '\?' => '.'))."$#i", $string);
            };

            foreach ($res as $record) {
                if($matcher($pattern, $record["key"])) {
                    $keys[] = $record["key"];
                }
            }
        }

        return $keys;
    }
846956
protected function createRegex($matched)
	{
		$startSlash = $matched[1] ? true : false;
		$param      = $matched[2];
		$optional   = $matched[3] ? true : false;
		$pattern    = $matched[4] ?: null;

		$pattern = $this->conditions[$param] ?: $pattern ?: '[^/]+';

		$this->paramNames[] = $param;

		if ($startSlash)
		{
			$regex = ($optional ? "(/" : '/') .'(?P<' . $param . '>' . $pattern . ')'. ($optional ? ')?' : '');
		}
		else
		{
			$regex = '(?P<' . $param . '>' . $pattern . ')'. ($optional ? '?' : '');
		}

		return $regex;
	}
164654
public static function getAllMatchingNames($value): array
    {
        $enumerables = self::getCache();
        $result = array_keys($enumerables, $value, true);
    
        if ([] === $result) {
            throw EnumerableException::valueNotFound();
        }
    
        return $result;
    }
470109
protected function getParameter($matches)
    {
        $params = $this->parseAttr($matches[3]);

        if( ! is_array($params))
        {
            $params = [$params];
        }

        return $params;
    }
1302031
protected function removeNumericAndEmpty(array &$matches)
    {
        foreach ($matches as $idx => $val) {
            if (is_int($idx) || '' === $val) {
                unset($matches[$idx]);
            }
        }
    }
1209492
public function match(string $event): array
    {
        $matches = [];

        //do the obvious match
        if (isset($this->observers[$event])) {
            $matches[$event] = array(
                'event' => $event,
                'pattern' => $event,
                'variables' => []
            );
        }

        //deal with regexp
        foreach ($this->regex as $pattern) {
            //if it matches
            if (preg_match_all($pattern, $event, $match)) {
                $variables = [];

                if (is_array($match) && !empty($match)) {
                    //flatten
                    $variables = call_user_func_array('array_merge', $match);
                    array_shift($variables);
                }

                $matches[$pattern] = array(
                    'event' => $event,
                    'pattern' => $pattern,
                    'variables' => $variables
                );
            }
        }

        return array_values($matches);
    }
473368
public static function popValues(
        array $arr,
        $match = false,
        bool $strict = false
    ): array
    {
        $func = Compare::getMethod($strict);
        $len = count($arr);
        while ($len > 0 && call_user_func($func, end($arr), $match)) {
            array_pop($arr);
            $len--;
        }
        return $arr;
    }