src/Matcher/MatcherVerifier.php
public function explain(array $matchers, array $arguments): MatcherResult
    {
        $isMatch = true;
        $matcherMatches = [];
        $argumentMatches = [];
        $argumentCount = count($arguments);
        $index = 0;

        foreach ($matchers as $matcher) {
            if ($matcher instanceof WildcardMatcher) {
                $matcherIsMatch = true;
                $innerMatcher = $matcher->matcher();
                $minimumArguments = $matcher->minimumArguments();
                $maximumArguments = $matcher->maximumArguments();

                for ($count = 0; $count < $minimumArguments; ++$count) {
                    if ($index >= $argumentCount) {
                        $matcherIsMatch = false;
                        $argumentMatches[] = false;

                        break;
                    }

                    if ($innerMatcher->matches($arguments[$index])) {
                        $argumentMatches[] = true;
                    } else {
                        $matcherIsMatch = false;
                        $argumentMatches[] = false;
                    }

                    ++$index;
                }

                if ($maximumArguments < 0) {
                    while (
                        $index < $argumentCount &&
                        $innerMatcher->matches($arguments[$index])
                    ) {
                        $argumentMatches[] = true;
                        ++$index;
                    }
                } else {
                    for (; $count < $maximumArguments; ++$count) {
                        if (
                            $index >= $argumentCount ||
                            !$innerMatcher->matches($arguments[$index])
                        ) {
                            break;
                        }

                        $argumentMatches[] = true;
                        ++$index;
                    }
                }

                $isMatch = $isMatch && $matcherIsMatch;
                $matcherMatches[] = $matcherIsMatch;

                continue;
            }

            $matcherIsMatch =
                $index < $argumentCount &&
                $matcher->matches($arguments[$index]);

            $isMatch = $isMatch && $matcherIsMatch;
            $matcherMatches[] = $matcherIsMatch;
            $argumentMatches[] = $matcherIsMatch;
            ++$index;
        }

        for (; $index < $argumentCount; ++$index) {
            $argumentMatches[] = false;
            $isMatch = false;
        }

        return new MatcherResult($isMatch, $matcherMatches, $argumentMatches);
    }
public function explain(array $matchers, array $arguments): MatcherResult
    {
        $isMatch = true;
        $matcherMatches = [];
        $argumentMatches = [];
        $argumentCount = count($arguments);
        $index = 0;

        foreach ($matchers as $matcher) {
            if ($matcher instanceof WildcardMatcher) {
                $matcherIsMatch = true;
                $innerMatcher = $matcher->matcher();
                $minimumArguments = $matcher->minimumArguments();
                $maximumArguments = $matcher->maximumArguments();

                for ($count = 0; $count < $minimumArguments; ++$count) {
                    if ($index >= $argumentCount) {
                        $matcherIsMatch = false;
                        $argumentMatches[] = false;

                        break;
                    }

                    if ($innerMatcher->matches($arguments[$index])) {
                        $argumentMatches[] = true;
                    } else {
                        $matcherIsMatch = false;
                        $argumentMatches[] = false;
                    }

                    ++$index;
                }

                if ($maximumArguments < 0) {
                    while (
                        $index < $argumentCount &&
                        $innerMatcher->matches($arguments[$index])
                    ) {
                        $argumentMatches[] = true;
                        ++$index;
                    }
                } else {
                    for (; $count < $maximumArguments; ++$count) {
                        if (
                            $index >= $argumentCount ||
                            !$innerMatcher->matches($arguments[$index])
                        ) {
                            break;
                        }

                        $argumentMatches[] = true;
                        ++$index;
                    }
                }

                $isMatch = $isMatch && $matcherIsMatch;
                $matcherMatches[] = $matcherIsMatch;

                continue;
            }

            $matcherIsMatch =
                $index < $argumentCount &&
                $matcher->matches($arguments[$index]);

            $isMatch = $isMatch && $matcherIsMatch;
            $matcherMatches[] = $matcherIsMatch;
            $argumentMatches[] = $matcherIsMatch;
            ++$index;
        }

        for (; $index < $argumentCount; ++$index) {
            $argumentMatches[] = false;
            $isMatch = false;
        }

        return new MatcherResult($isMatch, $matcherMatches, $argumentMatches);
    }
public function explain ( array $ matchers , array $ arguments ) : MatcherResult { $ isMatch = true ; $ matcherMatches = [ ] ; $ argumentMatches = [ ] ; $ argumentCount = count ( $ arguments ) ; $ index = 0 ; foreach ( $ matchers as $ matcher ) { if ( $ matcher instanceof WildcardMatcher ) { $ matcherIsMatch = true ; $ innerMatcher = $ matcher -> matcher ( ) ; $ minimumArguments = $ matcher -> minimumArguments ( ) ; $ maximumArguments = $ matcher -> maximumArguments ( ) ; for ( $ count = 0 ; $ count < $ minimumArguments ; ++ $ count ) { if ( $ index >= $ argumentCount ) { $ matcherIsMatch = false ; $ argumentMatches [ ] = false ; break ; } if ( $ innerMatcher -> matches ( $ arguments [ $ index ] ) ) { $ argumentMatches [ ] = true ; } else { $ matcherIsMatch = false ; $ argumentMatches [ ] = false ; } ++ $ index ; } if ( $ maximumArguments < 0 ) { while ( $ index < $ argumentCount && $ innerMatcher -> matches ( $ arguments [ $ index ] ) ) { $ argumentMatches [ ] = true ; ++ $ index ; } } else { for ( ; $ count < $ maximumArguments ; ++ $ count ) { if ( $ index >= $ argumentCount || ! $ innerMatcher -> matches ( $ arguments [ $ index ] ) ) { break ; } $ argumentMatches [ ] = true ; ++ $ index ; } } $ isMatch = $ isMatch && $ matcherIsMatch ; $ matcherMatches [ ] = $ matcherIsMatch ; continue ; } $ matcherIsMatch = $ index < $ argumentCount && $ matcher -> matches ( $ arguments [ $ index ] ) ; $ isMatch = $ isMatch && $ matcherIsMatch ; $ matcherMatches [ ] = $ matcherIsMatch ; $ argumentMatches [ ] = $ matcherIsMatch ; ++ $ index ; } for ( ; $ index < $ argumentCount ; ++ $ index ) { $ argumentMatches [ ] = false ; $ isMatch = false ; } return new MatcherResult ( $ isMatch , $ matcherMatches , $ argumentMatches ) ; }
Explain which of the supplied arguments match which of the supplied
matchers.

@param array<Matchable> $matchers  The matchers.
@param array            $arguments The arguments.

@return MatcherResult The result of matching.
Explain which of the supplied arguments match which of the supplied matchers .