Skip to content

Commit c2303ed

Browse files
GeLoLabsEric GELOEN
and
Eric GELOEN
authored
Fix matching for '@array@||@null@' (#493)
Co-authored-by: Eric GELOEN <eric.geloen@rapid-flyer.com>
1 parent 6145a0e commit c2303ed

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

src/Factory/MatcherFactory.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,22 @@ private function buildMatchers(Parser $parser, Backtrace $backtrace) : Matcher\C
4949

5050
private function buildArrayMatcher(Matcher\ChainMatcher $scalarMatchers, Parser $parser, Backtrace $backtrace) : Matcher\ArrayMatcher
5151
{
52-
$orMatcher = new Matcher\OrMatcher($backtrace, $scalarMatchers);
53-
54-
return new Matcher\ArrayMatcher(
52+
$arrayMatcher = new Matcher\ArrayMatcher(
5553
new Matcher\ChainMatcher(
5654
'array',
5755
$backtrace,
5856
[
59-
$orMatcher,
57+
new Matcher\OrMatcher($backtrace, $orMatchers = clone $scalarMatchers),
6058
$scalarMatchers,
6159
new Matcher\TextMatcher($backtrace, $parser),
6260
]
6361
),
6462
$backtrace,
6563
$parser
6664
);
65+
$orMatchers->registerMatcher($arrayMatcher);
66+
67+
return $arrayMatcher;
6768
}
6869

6970
private function buildScalarMatchers(Parser $parser, Backtrace $backtrace) : Matcher\ChainMatcher

src/Matcher/ChainMatcher.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ public function __construct(string $name, Backtrace $backtrace, array $matchers
3636
$this->name = $name;
3737
}
3838

39+
public function registerMatcher(ValueMatcher $matcher) : void
40+
{
41+
$this->matchers[] = $matcher;
42+
}
43+
3944
public function match($value, $pattern) : bool
4045
{
4146
$this->backtrace->matcherEntrance($this->matcherName(), $value, $pattern);

tests/Matcher/OrMatcherTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ public static function positiveMatchData()
6565
'test' => '@integer@||@null@',
6666
],
6767
],
68+
[
69+
[
70+
'test' => [],
71+
],
72+
[
73+
'test' => '@array@||@null@',
74+
],
75+
],
6876
[
6977
[
7078
'first_level' => ['second_level', ['third_level']],

0 commit comments

Comments
 (0)