get the matches from an output line

@param string $remoteString remote line output

@throws \InvalidArgumentException
@return array
437606
public static function getMatches($remoteString)
    {
        $matches = [];
        preg_match('/^(\S+)\s*(\S[^\( ]+)\s*\((.+)\)$/', trim($remoteString), $matches);
        if (!count($matches)) {
            throw new \InvalidArgumentException(sprintf('the remote string is not valid: %s', $remoteString));
        }

        return array_map('trim', $matches);
    }
1172597
protected function doMatch($actual)
    {
        if (!is_string($actual)) {
            throw new \InvalidArgumentException('SubStringMatcher requires string value');
        }

        return strpos($actual, $this->expected) !== false;
    }
127253
public static function parse($expression)
    {
        if (trim($expression) === '') {
            throw new InvalidArgumentException('Console command definition is empty.');
        }

        preg_match('/[^\s]+/', $expression, $matches);

        if (isset($matches[0])) {
            $name = $matches[0];
        } else {
            throw new InvalidArgumentException('Unable to determine command name from signature.');
        }

        preg_match_all('/\{\s*(.*?)\s*\}/', $expression, $matches);

        $tokens = isset($matches[1]) ? $matches[1] : [];

        if (count($tokens)) {
            return array_merge([$name], static::parameters($tokens));
        }

        return [$name, [], []];
    }
1372665
static public function getRemoteClass($localClass) {

            $remoteClass = false;
            $cb = false;
            $remoteClass = array_search($localClass,self::$maps);
            if (!$remoteClass && is_callable(self::$onGetRemoteClass)) {
                $cb = true;
                $remoteClass = call_user_func(self::$onGetRemoteClass,$localClass);
            }
            if (!$remoteClass) return false;
            if (!is_string($remoteClass) && $cb) {
                throw new Exception('Classname received from onGetRemoteClass should be a string or return false. ' . gettype($remoteClass) . ' was returned');
            }
            return $remoteClass; 

        }
1352473
public function getAction($matches = [])
    {
        if (!isset($this->route['controller'])) {
            return false;
        }
        $controller = $this->route['controller'];
        preg_match("/@(.*)/", $controller, $matches);
        if (!isset($matches[1])) {
            throw new RuntimeException('Unable to resolve action name from controller.');
        }
        return $matches[1];
    }
106211
private function parseSquash(string $string) : array
    {
        // As always, regexes to the rescue
        $matches = [];
        // @todo find out why using /^...$/ does not work capturing all groups
        if (!preg_match_all('/((\(\w+(?:\s+\w+)+\)\s*)+?)/ui', trim($string), $matches)) {
            throw new \InvalidArgumentException();
        }

        $ret = [];

        foreach ($matches[1] as $group) {
            $ret[] = array_filter(preg_split('/[\(\)\s]+/', $group));
        }

        return $ret;
    }
481039
protected function match(string $line, int $lineNumber, int $offset) : array
    {
        $restLine = substr($line, $offset);

        foreach ($this->terminals as $pattern => $name) {
            if (preg_match($pattern, $restLine, $matches)) {
                return [
                    $name,
                    $matches,
                ];
            }
        }

        throw new SyntaxErrorException(sprintf('Lexer error: unable to parse "%s" at line %s.', $line, $lineNumber));
    }
414735
private function getMatchStringParameterIndices($matchString, $pattern)
    {
        $indices = [];

        foreach ($pattern as $part) {
            if (!$this->isTokenPatternPart($part)) {
                $offset = 0;

                foreach ($indices as $currentIndex) {
                    $prefix = $currentIndex['prefix'];

                    if ($prefix == $part || substr_count($prefix, $part) || substr_count($part, $prefix)) {
                        $offset = $currentIndex['index'];
                    }
                }

                $indices[] = [
                    'prefix' => $part,
                    'index' => strpos($matchString, $part, $offset) + strlen($part)
                ];
            }
        }

        return $indices;
    }
908191
public static function matchSemVer($string)
    {
        // Array of matches for PCRE
        $matches = array();

        // Match the possible parts of a SemVer
        $matched = preg_match(
            self::$version,
            $string,
            $matches
        );

        // No match, invalid
        if (!$matched) {
            throw new InvalidArgumentException(
                '"' . $string . '" is not a valid SemVer'
            );
        }

        // Return matched array
        return $matches;
    }
15347
protected function collectRemotes()
    {
        $remotesResult = $this->executor->execute('git remote -v');

        if (count($remotesResult) === 0) {
            throw new \RuntimeException();
        }

        // parse command result
        $results = [];

        foreach ($remotesResult as $result) {
            if (strpos($result, ' ') !== false) {
                list($remote) = explode(' ', $result, 2);

                $results[] = $remote;
            }
        }

        // filter
        $results = array_unique($results);

        // create Remote instances
        $remotes = [];

        foreach ($results as $result) {
            if (strpos($result, "\t") !== false) {
                list($name, $url) = explode("\t", $result, 2);

                $remote = new RemoteInfo();
                $remotes[] = $remote->setName(trim($name))->setUrl(trim($url));
            }
        }

        return $remotes;
    }
710701
protected function doMatch($actual)
    {
        if (!is_string($actual)) {
            throw new \InvalidArgumentException('PatternMatcher expects a string');
        }

        return (bool) preg_match($this->expected, $actual);
    }
1206125
public static function parseRgbString(string $string) : array
    {
        if (!preg_match(self::REGEX_RGB, $string, $matches)) {
            throw InvalidArgumentException::format(
                    'Invalid rgb string passed to %s: expecting format "rgb(0-255, 0-255, 0-255)", "%s" given',
                    __METHOD__, $string
            );
        }

        return [(int)$matches[1], (int)$matches[2], (int)$matches[3]];
    }
391641
private function getQuotedParameterNormalisedError($htmlErrorString)
    {
        $parameterMatches = [];
        $matchCount = preg_match_all('/"([^"]?)+"/', $htmlErrorString, $parameterMatches);

        if ($matchCount === 0) {
            return null;
        }

        $normalisedError = new NormalisedError();
        $normalisedErrorString = $htmlErrorString;

        foreach ($parameterMatches[0] as $parameterIndex => $parameterMatch) {
            $normalisedErrorString = preg_replace(
                '/' . PregQuoter::quote($parameterMatch) . '/',
                '"%'.$parameterIndex.'"',
                $normalisedErrorString,
                1
            );
            $normalisedError->addParameter(trim($parameterMatch, '"'));
        }

        $normalisedError->setNormalForm($normalisedErrorString);

        return $normalisedError;
    }
1072984
public function getTransformations() {
        if ($this->transformations === null) {
            $this->transformations = [];

            $transformations = $this->query->get('t', []);

            if (!is_array($transformations)) {
                throw new InvalidArgumentException('Transformations must be specifed as an array', 400);
            }

            foreach ($transformations as $transformation) {
                if (!is_string($transformation)) {
                    throw new InvalidArgumentException('Invalid transformation', 400);
                }

                // See if the transformation has any parameters
                $pos = strpos($transformation, ':');
                $urlParams = '';

                if ($pos === false) {
                    // No params exist
                    $name = $transformation;
                } else {
                    list($name, $urlParams) = explode(':', $transformation, 2);
                }

                // Initialize params for the transformation
                $params = [];

                // Loop through the parameter string and assign params to an array
                $offset = 0;
                $pattern = '#(\w+)=(?:(.+?),\w+=|(.+?$))#';
                while (preg_match($pattern, $urlParams, $matches, PREG_OFFSET_CAPTURE, $offset)) {
                    $offset = $matches[2][1];
                    $paramName = $matches[1][0];
                    $paramValue = isset($matches[3]) ? $matches[3][0] : $matches[2][0];
                    $params[$paramName] = $paramValue;
                }

                $this->transformations[] = [
                    'name'   => $name,
                    'params' => $params,
                ];
            }
        }

        return $this->transformations;
    }
552139
protected static function __match(array $patterns)
    {
        return function (...$args) use ($patterns) {
            $parameterTypes = array_map(self::getType(), $args);

            try {
                $keysToValues = Arrays::zip(array_keys($patterns), array_values($patterns));

                list($key, $matchingPattern) = Arrays::first(
                    Pattern::patternApplies($parameterTypes, $args),
                    $keysToValues
                );
            } catch (ElementNotFoundException $e) {
                throw new IncompletePatternMatchException(
                    'Incomplete pattern match expression. (missing ' . implode(', ', $parameterTypes) . ')'
                );
            }


            /**
             * Upcoming Feature, Array DSL for matching via `x::xs` etc.
             */
//            // if key is a string, manually match
//            if (is_string($key)) {
//
//                throw new \Exception('Array DSL not available.');
//            }

            list($hasExtractable, $unwrappedArgs) = self::unwrapArgs($args);

            $value = $matchingPattern(...$args);
            $isCallable = is_callable($value);

            if ($hasExtractable && ! $isCallable) {
                throw new InvalidPatternMatchException(
                    'Invalid pattern match expression. (one of ' . implode(', ', $parameterTypes)
                    . ' requires a callback to unwrap)'
                );
            }

            /**
             * Extractable requires a callback to feed args into.
             */
            if ($hasExtractable && $isCallable) {
                return $matchingPattern(...$args)(...$unwrappedArgs);
            }

            /**
             * No extractable so we can just return the value directly.
             */
            return $value;
        };
    }
854356
public function pregMap( string$pattern, callable$callback ):array
	{
		preg_match_all($pattern,ltrim($this->content,"\t"),$matches);
		return array_map($callback,...$matches);
	}
346586
private function getTokensStream()
    {
        $matches = [];
        \preg_match_all(static::PATTERN_VAR, $this->pattern, $matches);
        foreach ($matches[0] ?? [] as $match) {
            $arr = $this->paramStrToArr($match);

            if (\count($arr) > 3) {
                throw new InvalidArgumentException("Invalid url pattern {$this->pattern}");
            }

            $name = $arr[0];
            $pattern = $arr[1] ?? $this->patterns->getDefaultPattern();
            $default = $arr[2] ?? null;

            yield [
                $match,
                $name,
                $pattern,
                $default
            ];
        }
    }