Skip to content

Commit

Permalink
Fix matching for '@array@||@null@' (#493)
Browse files Browse the repository at this point in the history
Co-authored-by: Eric GELOEN <[email protected]>
  • Loading branch information
GeLoLabs and Eric GELOEN authored Oct 7, 2024
1 parent 6145a0e commit c2303ed
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/Factory/MatcherFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,22 @@ 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),
]
),
$backtrace,
$parser
);
$orMatchers->registerMatcher($arrayMatcher);

return $arrayMatcher;
}

private function buildScalarMatchers(Parser $parser, Backtrace $backtrace) : Matcher\ChainMatcher
Expand Down
5 changes: 5 additions & 0 deletions src/Matcher/ChainMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions tests/Matcher/OrMatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ public static function positiveMatchData()
'test' => '@integer@||@null@',
],
],
[
[
'test' => [],
],
[
'test' => '@array@||@null@',
],
],
[
[
'first_level' => ['second_level', ['third_level']],
Expand Down

0 comments on commit c2303ed

Please sign in to comment.