|
15 | 15 | use function file_get_contents; |
16 | 16 | use function is_array; |
17 | 17 | use function max; |
| 18 | +use function range; |
18 | 19 | use function sort; |
19 | 20 | use function sprintf; |
20 | 21 | use function substr_count; |
@@ -208,45 +209,45 @@ private function analyse(string $filename): void |
208 | 209 |
|
209 | 210 | private function findLinesIgnoredByLineBasedAnnotations(string $filename, string $source, bool $useAnnotationsForIgnoringCode): void |
210 | 211 | { |
211 | | - $ignore = false; |
212 | | - $stop = false; |
| 212 | + if (!$useAnnotationsForIgnoringCode) { |
| 213 | + return; |
| 214 | + } |
| 215 | + |
| 216 | + $start = false; |
213 | 217 |
|
214 | 218 | foreach (token_get_all($source) as $token) { |
215 | | - if (!is_array($token)) { |
| 219 | + if (!is_array($token) || |
| 220 | + !(T_COMMENT === $token[0] || T_DOC_COMMENT === $token[0]) |
| 221 | + ) { |
216 | 222 | continue; |
217 | 223 | } |
218 | 224 |
|
219 | | - switch ($token[0]) { |
220 | | - case T_COMMENT: |
221 | | - case T_DOC_COMMENT: |
222 | | - if (!$useAnnotationsForIgnoringCode) { |
223 | | - break; |
224 | | - } |
225 | | - |
226 | | - $comment = trim($token[1]); |
227 | | - |
228 | | - if ($comment === '// @codeCoverageIgnore' || |
229 | | - $comment === '//@codeCoverageIgnore') { |
230 | | - $ignore = true; |
231 | | - $stop = true; |
232 | | - } elseif ($comment === '// @codeCoverageIgnoreStart' || |
233 | | - $comment === '//@codeCoverageIgnoreStart') { |
234 | | - $ignore = true; |
235 | | - } elseif ($comment === '// @codeCoverageIgnoreEnd' || |
236 | | - $comment === '//@codeCoverageIgnoreEnd') { |
237 | | - $stop = true; |
238 | | - } |
239 | | - |
240 | | - break; |
241 | | - } |
| 225 | + $comment = trim($token[1]); |
242 | 226 |
|
243 | | - if ($ignore) { |
| 227 | + if ($comment === '// @codeCoverageIgnore' || |
| 228 | + $comment === '//@codeCoverageIgnore') { |
244 | 229 | $this->ignoredLines[$filename][] = $token[2]; |
245 | 230 |
|
246 | | - if ($stop) { |
247 | | - $ignore = false; |
248 | | - $stop = false; |
| 231 | + continue; |
| 232 | + } |
| 233 | + |
| 234 | + if ($comment === '// @codeCoverageIgnoreStart' || |
| 235 | + $comment === '//@codeCoverageIgnoreStart') { |
| 236 | + $start = $token[2]; |
| 237 | + |
| 238 | + continue; |
| 239 | + } |
| 240 | + |
| 241 | + if ($comment === '// @codeCoverageIgnoreEnd' || |
| 242 | + $comment === '//@codeCoverageIgnoreEnd') { |
| 243 | + if (false === $start) { |
| 244 | + $start = $token[2]; |
249 | 245 | } |
| 246 | + |
| 247 | + $this->ignoredLines[$filename] = array_merge( |
| 248 | + $this->ignoredLines[$filename], |
| 249 | + range($start, $token[2]) |
| 250 | + ); |
250 | 251 | } |
251 | 252 | } |
252 | 253 | } |
|
0 commit comments