Skip to content

Commit 5c3f3cb

Browse files
mtomalamichal
andauthored
include ArrayMatcher in OrMatcher to fix issues with @null@||@array@ pattern (#214)
Co-authored-by: michal <[email protected]>
1 parent b8ddc75 commit 5c3f3cb

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/Factory/MatcherFactory.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ protected function buildMatchers(Parser $parser, Backtrace $backtrace) : Matcher
2323
{
2424
$scalarMatchers = $this->buildScalarMatchers($parser, $backtrace);
2525
$arrayMatcher = $this->buildArrayMatcher($scalarMatchers, $parser, $backtrace);
26+
$orMatcher = $this->buildOrMatcher([$scalarMatchers, $arrayMatcher], $backtrace);
2627

2728
// Matchers are registered in order of matching
2829
// 1) all scalars
@@ -39,7 +40,7 @@ protected function buildMatchers(Parser $parser, Backtrace $backtrace) : Matcher
3940
new Matcher\JsonMatcher($arrayMatcher, $backtrace),
4041
new Matcher\XmlMatcher($arrayMatcher, $backtrace),
4142
$arrayMatcher,
42-
new Matcher\OrMatcher($backtrace, $scalarMatchers),
43+
$orMatcher,
4344
new Matcher\TextMatcher($scalarMatchers, $backtrace, $parser),
4445
]
4546
);
@@ -88,7 +89,19 @@ protected function buildScalarMatchers(Parser $parser, Backtrace $backtrace) : M
8889
);
8990
}
9091

91-
protected function buildParser(Backtrace $backtrace) : Parser
92+
private function buildOrMatcher(array $orMatchers, Backtrace $backtrace) : Matcher\OrMatcher
93+
{
94+
return new Matcher\OrMatcher(
95+
$backtrace,
96+
new Matcher\ChainMatcher(
97+
'or',
98+
$backtrace,
99+
$orMatchers
100+
)
101+
);
102+
}
103+
104+
private function buildParser(Backtrace $backtrace) : Parser
92105
{
93106
return new Parser(new Lexer(), new Parser\ExpanderInitializer($backtrace));
94107
}

tests/OrMatcherTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,16 @@ public static function orExamples()
3434
['ipsum lorem', '@[email protected]("lorem")||@[email protected]("lorem")', true],
3535
['[email protected]', '@[email protected]()||@null@', true],
3636
[null, '@[email protected]()||@null@', true],
37-
[null, '@[email protected]()||@null@', true],
3837
['2014-08-19', '@[email protected]()||@integer@', true],
3938
[null, '@integer@||@string@', false],
4039
[1, '@[email protected](10)||@[email protected]("10")', false],
40+
[[], '@array@||@null@', true],
41+
[[1, 2, 3], '@[email protected](3)||@null@', true],
42+
[null, '@array@||@null@', true],
43+
[null, '@[email protected](3)||@null@', true],
44+
['ipsum', '@array@||@string@', true],
45+
['ipsum', '@array@||@null@', false],
46+
[1, '@array@||@null@', false],
4147
];
4248
}
4349
}

0 commit comments

Comments
 (0)