File tree Expand file tree Collapse file tree 2 files changed +29
-7
lines changed
tests/PHPStan/Analyser/nsrt Expand file tree Collapse file tree 2 files changed +29
-7
lines changed Original file line number Diff line number Diff line change 2323use function count ;
2424use function in_array ;
2525use function is_int ;
26+ use function preg_replace ;
2627use function rtrim ;
2728use function sscanf ;
2829use function str_contains ;
@@ -64,20 +65,24 @@ public function parseGroups(string $regex): ?array
6465 return null ;
6566 }
6667
67- $ rawRegex = $ this ->regexExpressionHelper ->removeDelimitersAndModifiers ($ regex );
68- try {
69- $ ast = self ::$ parser ->parse ($ rawRegex );
70- } catch (Exception ) {
71- return null ;
72- }
73-
7468 $ modifiers = $ this ->regexExpressionHelper ->getPatternModifiers ($ regex ) ?? '' ;
7569 foreach (self ::NOT_SUPPORTED_MODIFIERS as $ notSupportedModifier ) {
7670 if (str_contains ($ modifiers , $ notSupportedModifier )) {
7771 return null ;
7872 }
7973 }
8074
75+ if (str_contains ($ modifiers , 'x ' )) {
76+ $ regex = preg_replace ('/#.*/ ' , '' , $ regex );
77+ }
78+
79+ $ rawRegex = $ this ->regexExpressionHelper ->removeDelimitersAndModifiers ($ regex );
80+ try {
81+ $ ast = self ::$ parser ->parse ($ rawRegex );
82+ } catch (Exception ) {
83+ return null ;
84+ }
85+
8186 $ captureOnlyNamed = false ;
8287 if ($ this ->phpVersion ->supportsPregCaptureOnlyNamedGroups ()) {
8388 $ captureOnlyNamed = str_contains ($ modifiers , 'n ' );
Original file line number Diff line number Diff line change 1+ <?php // lint >= 7.4
2+
3+ namespace Bug12242 ;
4+
5+ use function PHPStan \Testing \assertType ;
6+
7+ function foo (string $ str ): void
8+ {
9+ $ regexp = '/
10+ # (
11+ ([\d,]*)
12+ # )
13+ /x ' ;
14+ if (preg_match ($ regexp , $ str , $ match )) {
15+ assertType ('array{string, string} ' , $ match );
16+ }
17+ }
You can’t perform that action at this time.
0 commit comments