Skip to content

Commit 5b93b4c

Browse files
authored
[CodeQuality] Fix escape character on SimplifyRegexPatternRector (#7390)
1 parent 33771c6 commit 5b93b4c

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Rector\Tests\CodeQuality\Rector\FuncCall\SimplifyRegexPatternRector\Fixture;
4+
5+
class SlashDelimiter
6+
{
7+
public function run(string $param)
8+
{
9+
return preg_match('/^[0-9]+$/', $param);
10+
}
11+
}
12+
13+
?>
14+
-----
15+
<?php
16+
17+
namespace Rector\Tests\CodeQuality\Rector\FuncCall\SimplifyRegexPatternRector\Fixture;
18+
19+
class SlashDelimiter
20+
{
21+
public function run(string $param)
22+
{
23+
return preg_match('/^\d+$/', $param);
24+
}
25+
}
26+
27+
?>

rules/CodeQuality/Rector/FuncCall/SimplifyRegexPatternRector.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ final class SimplifyRegexPatternRector extends AbstractRector
2121
* @var array<string, string>
2222
*/
2323
private const COMPLEX_PATTERN_TO_SIMPLE = [
24-
'[0-9]' => '\d',
25-
'[a-zA-Z0-9_]' => '\w',
26-
'[A-Za-z0-9_]' => '\w',
27-
'[0-9a-zA-Z_]' => '\w',
28-
'[0-9A-Za-z_]' => '\w',
29-
'[\r\n\t\f\v ]' => '\s',
24+
'[0-9]' => '\\d',
25+
'[a-zA-Z0-9_]' => '\\w',
26+
'[A-Za-z0-9_]' => '\\w',
27+
'[0-9a-zA-Z_]' => '\\w',
28+
'[0-9A-Za-z_]' => '\\w',
29+
'[\r\n\t\f\v ]' => '\\s',
3030
];
3131

3232
public function __construct(

0 commit comments

Comments
 (0)