diff --git a/src/Factory/MatcherFactory.php b/src/Factory/MatcherFactory.php index 3bcd34f..19039b8 100644 --- a/src/Factory/MatcherFactory.php +++ b/src/Factory/MatcherFactory.php @@ -49,14 +49,12 @@ private function buildMatchers(Parser $parser, Backtrace $backtrace) : Matcher\C private function buildArrayMatcher(Matcher\ChainMatcher $scalarMatchers, Parser $parser, Backtrace $backtrace) : Matcher\ArrayMatcher { - $orMatcher = new Matcher\OrMatcher($backtrace, $scalarMatchers); - - return new Matcher\ArrayMatcher( + $arrayMatcher = new Matcher\ArrayMatcher( new Matcher\ChainMatcher( 'array', $backtrace, [ - $orMatcher, + new Matcher\OrMatcher($backtrace, $orMatchers = clone $scalarMatchers), $scalarMatchers, new Matcher\TextMatcher($backtrace, $parser), ] @@ -64,6 +62,9 @@ private function buildArrayMatcher(Matcher\ChainMatcher $scalarMatchers, Parser $backtrace, $parser ); + $orMatchers->registerMatcher($arrayMatcher); + + return $arrayMatcher; } private function buildScalarMatchers(Parser $parser, Backtrace $backtrace) : Matcher\ChainMatcher diff --git a/src/Matcher/ChainMatcher.php b/src/Matcher/ChainMatcher.php index 714ffb1..be21c4d 100644 --- a/src/Matcher/ChainMatcher.php +++ b/src/Matcher/ChainMatcher.php @@ -36,6 +36,11 @@ public function __construct(string $name, Backtrace $backtrace, array $matchers $this->name = $name; } + public function registerMatcher(ValueMatcher $matcher): void + { + $this->matchers[] = $matcher; + } + public function match($value, $pattern) : bool { $this->backtrace->matcherEntrance($this->matcherName(), $value, $pattern);