@@ -50,12 +50,15 @@ public function process(
50
50
bool $ onlyFiles ,
51
51
array $ analysedFiles ,
52
52
bool $ hasInternalErrors ,
53
+ bool $ generateBaseline ,
54
+ bool $ ignoreNewErrors ,
53
55
): IgnoredErrorHelperProcessedResult
54
56
{
55
- $ unmatchedIgnoredErrors = $ this ->ignoreErrors ;
57
+ // if we are generating the baseline, we dont want ignore Errors configuration to affect the errors we output
58
+ $ unmatchedIgnoredErrors = $ generateBaseline ? [] : $ this ->ignoreErrors ;
56
59
$ stringErrors = [];
57
60
58
- $ processIgnoreError = function (Error $ error , int $ i , $ ignore ) use (&$ unmatchedIgnoredErrors , &$ stringErrors ): bool {
61
+ $ processIgnoreError = function (Error $ error , int $ i , $ ignore ) use ($ generateBaseline , &$ unmatchedIgnoredErrors , &$ stringErrors ): bool {
59
62
$ shouldBeIgnored = false ;
60
63
if (is_string ($ ignore )) {
61
64
$ shouldBeIgnored = IgnoredError::shouldIgnore ($ this ->fileHelper , $ error , $ ignore , null , null );
@@ -65,7 +68,8 @@ public function process(
65
68
} else {
66
69
if (isset ($ ignore ['path ' ])) {
67
70
$ shouldBeIgnored = IgnoredError::shouldIgnore ($ this ->fileHelper , $ error , $ ignore ['message ' ] ?? null , $ ignore ['identifier ' ] ?? null , $ ignore ['path ' ]);
68
- if ($ shouldBeIgnored ) {
71
+ // only ignore errors when not generating the baseline, because it need to contain all errors
72
+ if ($ shouldBeIgnored && !$ generateBaseline ) {
69
73
if (isset ($ ignore ['count ' ])) {
70
74
$ realCount = $ unmatchedIgnoredErrors [$ i ]['realCount ' ] ?? 0 ;
71
75
$ realCount ++;
@@ -115,12 +119,12 @@ public function process(
115
119
'Error message "%s" cannot be ignored, use excludePaths instead. ' ,
116
120
$ error ->getMessage (),
117
121
);
118
- return true ;
122
+ return false ;
119
123
}
120
- return false ;
124
+ return true ;
121
125
}
122
126
123
- return true ;
127
+ return false ;
124
128
};
125
129
126
130
$ ignoredErrors = [];
@@ -130,12 +134,16 @@ public function process(
130
134
foreach ($ this ->ignoreErrorsByFile [$ filePath ] as $ ignoreError ) {
131
135
$ i = $ ignoreError ['index ' ];
132
136
$ ignore = $ ignoreError ['ignoreError ' ];
133
- $ result = $ processIgnoreError ($ error , $ i , $ ignore );
134
- if (!$ result ) {
137
+ $ isIgnoreMatch = $ processIgnoreError ($ error , $ i , $ ignore );
138
+ if (!$ isIgnoreMatch ) {
139
+ continue ;
140
+ }
141
+
142
+ if (!$ generateBaseline ) {
135
143
unset($ errors [$ errorIndex ]);
136
144
$ ignoredErrors [] = [$ error , $ ignore ];
137
- continue 2 ;
138
145
}
146
+ continue 2 ;
139
147
}
140
148
}
141
149
@@ -146,12 +154,16 @@ public function process(
146
154
foreach ($ this ->ignoreErrorsByFile [$ normalizedTraitFilePath ] as $ ignoreError ) {
147
155
$ i = $ ignoreError ['index ' ];
148
156
$ ignore = $ ignoreError ['ignoreError ' ];
149
- $ result = $ processIgnoreError ($ error , $ i , $ ignore );
150
- if (!$ result ) {
157
+ $ isIgnoreMatch = $ processIgnoreError ($ error , $ i , $ ignore );
158
+ if (!$ isIgnoreMatch ) {
159
+ continue ;
160
+ }
161
+
162
+ if (!$ generateBaseline ) {
151
163
unset($ errors [$ errorIndex ]);
152
164
$ ignoredErrors [] = [$ error , $ ignore ];
153
- continue 2 ;
154
165
}
166
+ continue 2 ;
155
167
}
156
168
}
157
169
}
@@ -160,13 +172,24 @@ public function process(
160
172
$ i = $ ignoreError ['index ' ];
161
173
$ ignore = $ ignoreError ['ignoreError ' ];
162
174
163
- $ result = $ processIgnoreError ($ error , $ i , $ ignore );
164
- if (!$ result ) {
175
+ $ isIgnoreMatch = $ processIgnoreError ($ error , $ i , $ ignore );
176
+ if (!$ isIgnoreMatch ) {
177
+ continue ;
178
+ }
179
+
180
+ if (!$ generateBaseline ) {
165
181
unset($ errors [$ errorIndex ]);
166
182
$ ignoredErrors [] = [$ error , $ ignore ];
167
- continue 2 ;
168
183
}
184
+ continue 2 ;
169
185
}
186
+
187
+ if (!$ ignoreNewErrors ) {
188
+ continue ;
189
+ }
190
+
191
+ // if the error was not ignored, it is a new error, don't return it when $ignoreNewErrors is set
192
+ unset($ errors [$ errorIndex ]);
170
193
}
171
194
172
195
$ errors = array_values ($ errors );
0 commit comments