@@ -116,22 +116,27 @@ public function process(
116116 }
117117 }
118118 } elseif (isset ($ ignore ['paths ' ])) {
119- foreach ($ ignore ['paths ' ] as $ j => $ ignorePath ) {
120- $ shouldBeIgnored = IgnoredError ::shouldIgnore ($ this ->fileHelper , $ error , ignoredErrorPattern: $ ignore ['message ' ] ?? null , ignoredErrorMessage: $ ignore ['rawMessage ' ] ?? null , identifier: $ ignore ['identifier ' ] ?? null , path: $ ignorePath );
121- if (!$ shouldBeIgnored ) {
122- continue ;
123- }
124-
125- if (isset ($ unmatchedIgnoredErrors [$ i ])) {
126- if (!is_array ($ unmatchedIgnoredErrors [$ i ])) {
127- throw new ShouldNotHappenException ();
119+ // Message and identifier do not depend on the path. Match them once
120+ // instead of repeating the potentially expensive regex for every path.
121+ $ matchesMessageAndIdentifier = IgnoredError ::shouldIgnore ($ this ->fileHelper , $ error , ignoredErrorPattern: $ ignore ['message ' ] ?? null , ignoredErrorMessage: $ ignore ['rawMessage ' ] ?? null , identifier: $ ignore ['identifier ' ] ?? null , path: null );
122+ if ($ matchesMessageAndIdentifier ) {
123+ foreach ($ ignore ['paths ' ] as $ j => $ ignorePath ) {
124+ $ shouldBeIgnored = IgnoredError ::shouldIgnore ($ this ->fileHelper , $ error , ignoredErrorPattern: null , ignoredErrorMessage: null , identifier: null , path: $ ignorePath );
125+ if (!$ shouldBeIgnored ) {
126+ continue ;
128127 }
129- unset($ unmatchedIgnoredErrors [$ i ]['paths ' ][$ j ]);
130- if (isset ($ unmatchedIgnoredErrors [$ i ]['paths ' ]) && count ($ unmatchedIgnoredErrors [$ i ]['paths ' ]) === 0 ) {
131- unset($ unmatchedIgnoredErrors [$ i ]);
128+
129+ if (isset ($ unmatchedIgnoredErrors [$ i ])) {
130+ if (!is_array ($ unmatchedIgnoredErrors [$ i ])) {
131+ throw new ShouldNotHappenException ();
132+ }
133+ unset($ unmatchedIgnoredErrors [$ i ]['paths ' ][$ j ]);
134+ if (isset ($ unmatchedIgnoredErrors [$ i ]['paths ' ]) && count ($ unmatchedIgnoredErrors [$ i ]['paths ' ]) === 0 ) {
135+ unset($ unmatchedIgnoredErrors [$ i ]);
136+ }
132137 }
138+ break ;
133139 }
134- break ;
135140 }
136141 } else {
137142 $ shouldBeIgnored = IgnoredError ::shouldIgnore ($ this ->fileHelper , $ error , ignoredErrorPattern: $ ignore ['message ' ] ?? null , ignoredErrorMessage: $ ignore ['rawMessage ' ] ?? null , identifier: $ ignore ['identifier ' ] ?? null , path: null );
0 commit comments