File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed
Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change 99use PHPStan \Analyser \Scope ;
1010use PHPStan \Rules \Rule ;
1111use PHPStan \Rules \RuleErrorBuilder ;
12+ use PHPStan \ShouldNotHappenException ;
1213use PHPStan \Type \Regex \RegexExpressionHelper ;
1314use function in_array ;
1415use function sprintf ;
@@ -126,8 +127,11 @@ private function validatePattern(string $pattern): ?string
126127 try {
127128 Strings::match ('' , $ pattern );
128129 } catch (RegexpException $ e ) {
129- $ lastColonPos = strrpos ($ e ->getMessage (), ': ' );
130- if (str_contains ($ e ->getMessage (), 'UTF-8 error ' ) && $ lastColonPos !== false ) {
130+ if (str_contains ($ e ->getMessage (), 'UTF-8 error ' )) {
131+ $ lastColonPos = strrpos ($ e ->getMessage (), ': ' );
132+ if ($ lastColonPos === false ) {
133+ throw new ShouldNotHappenException ();
134+ }
131135 // strip invalid utf-8 pattern contents to keep the error message NEON parsable.
132136 return substr ($ e ->getMessage (), 0 , $ lastColonPos );
133137 }
You can’t perform that action at this time.
0 commit comments