Skip to content

Commit 7d09c45

Browse files
Merge branch '6.4' into 7.0
* 6.4: More short closures + isset instead of null checks + etc.
2 parents 45682bd + 6c8b12f commit 7d09c45

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

Node/BinaryNode.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function compile(Compiler $compiler): void
5555
}
5656

5757
$compiler
58-
->raw('(static function ($regexp, $str) { set_error_handler(function ($t, $m) use ($regexp, $str) { throw new \Symfony\Component\ExpressionLanguage\SyntaxError(sprintf(\'Regexp "%s" passed to "matches" is not valid\', $regexp).substr($m, 12)); }); try { return preg_match($regexp, (string) $str); } finally { restore_error_handler(); } })(')
58+
->raw('(static function ($regexp, $str) { set_error_handler(static fn ($t, $m) => throw new \Symfony\Component\ExpressionLanguage\SyntaxError(sprintf(\'Regexp "%s" passed to "matches" is not valid\', $regexp).substr($m, 12))); try { return preg_match($regexp, (string) $str); } finally { restore_error_handler(); } })(')
5959
->compile($this->nodes['right'])
6060
->raw(', ')
6161
->compile($this->nodes['left'])
@@ -182,9 +182,7 @@ public function toArray(): array
182182

183183
private function evaluateMatches(string $regexp, ?string $str): int
184184
{
185-
set_error_handler(function ($t, $m) use ($regexp) {
186-
throw new SyntaxError(sprintf('Regexp "%s" passed to "matches" is not valid', $regexp).substr($m, 12));
187-
});
185+
set_error_handler(static fn ($t, $m) => throw new SyntaxError(sprintf('Regexp "%s" passed to "matches" is not valid', $regexp).substr($m, 12)));
188186
try {
189187
return preg_match($regexp, (string) $str);
190188
} finally {

Tests/Node/BinaryNodeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public static function getCompileData(): array
120120

121121
['range(1, 3)', new BinaryNode('..', new ConstantNode(1), new ConstantNode(3))],
122122

123-
['(static function ($regexp, $str) { set_error_handler(function ($t, $m) use ($regexp, $str) { throw new \Symfony\Component\ExpressionLanguage\SyntaxError(sprintf(\'Regexp "%s" passed to "matches" is not valid\', $regexp).substr($m, 12)); }); try { return preg_match($regexp, (string) $str); } finally { restore_error_handler(); } })("/^[a-z]+\$/", "abc")', new BinaryNode('matches', new ConstantNode('abc'), new ConstantNode('/^[a-z]+$/'))],
123+
['(static function ($regexp, $str) { set_error_handler(static fn ($t, $m) => throw new \Symfony\Component\ExpressionLanguage\SyntaxError(sprintf(\'Regexp "%s" passed to "matches" is not valid\', $regexp).substr($m, 12))); try { return preg_match($regexp, (string) $str); } finally { restore_error_handler(); } })("/^[a-z]+\$/", "abc")', new BinaryNode('matches', new ConstantNode('abc'), new ConstantNode('/^[a-z]+$/'))],
124124

125125
['str_starts_with("abc", "a")', new BinaryNode('starts with', new ConstantNode('abc'), new ConstantNode('a'))],
126126
['str_ends_with("abc", "a")', new BinaryNode('ends with', new ConstantNode('abc'), new ConstantNode('a'))],

0 commit comments

Comments
 (0)