Skip to content

Commit 2e8ed68

Browse files
mtomalamichal
andauthored
include ArrayMatcher in OrMatcher to fix issues with @null@||@array@ (#213)
* include ArrayMatcher in OrMatcher to fix issues with `@null@||@array@` pattern * more test cases Co-authored-by: michal <[email protected]>
1 parent efd3b2f commit 2e8ed68

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/Factory/MatcherFactory.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ private function buildMatchers(Parser $parser, Backtrace $backtrace) : Matcher\C
3737
}
3838

3939
$matchers[] = $arrayMatcher;
40-
$matchers[] = new Matcher\OrMatcher($backtrace, $scalarMatchers);
40+
$matchers[] = $this->buildOrMatcher($backtrace, $matchers);
4141
$matchers[] = new Matcher\TextMatcher($scalarMatchers, $backtrace, $parser);
4242

4343
return new Matcher\ChainMatcher(
@@ -88,6 +88,18 @@ private function buildScalarMatchers(Parser $parser, Backtrace $backtrace) : Mat
8888
);
8989
}
9090

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

tests/OrMatcherTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,16 @@ public static function orExamples()
2121
['ipsum lorem', '@[email protected]("lorem")||@[email protected]("lorem")', true],
2222
['[email protected]', '@[email protected]()||@null@', true],
2323
[null, '@[email protected]()||@null@', true],
24-
[null, '@[email protected]()||@null@', true],
2524
['2014-08-19', '@[email protected]()||@integer@', true],
2625
[null, '@integer@||@string@', false],
2726
[1, '@[email protected](10)||@[email protected]("10")', false],
27+
[[], '@array@||@null@', true],
28+
[[1, 2, 3], '@[email protected](3)||@null@', true],
29+
[null, '@array@||@null@', true],
30+
[null, '@[email protected](3)||@null@', true],
31+
['ipsum', '@array@||@string@', true],
32+
['ipsum', '@array@||@null@', false],
33+
[1, '@array@||@null@', false],
2834
];
2935
}
3036

0 commit comments

Comments
 (0)