|
32 | 32 | use PHPStan\ShouldNotHappenException; |
33 | 33 | use PHPStan\Type\ObjectType; |
34 | 34 | use function array_diff_key; |
| 35 | +use function array_intersect; |
35 | 36 | use function array_key_exists; |
| 37 | +use function array_keys; |
36 | 38 | use function array_map; |
37 | 39 | use function array_merge; |
38 | 40 | use function array_unique; |
39 | 41 | use function count; |
40 | 42 | use function dirname; |
41 | 43 | use function extension_loaded; |
42 | 44 | use function getenv; |
| 45 | +use function implode; |
43 | 46 | use function ini_get; |
44 | 47 | use function is_array; |
45 | 48 | use function is_file; |
46 | 49 | use function is_readable; |
| 50 | +use function is_string; |
47 | 51 | use function spl_object_id; |
48 | 52 | use function sprintf; |
49 | 53 | use function str_ends_with; |
@@ -318,15 +322,35 @@ private function validateParameters(array $parameters, array $parametersSchema): |
318 | 322 | $processor->process($schema, $parameters); |
319 | 323 |
|
320 | 324 | if ( |
321 | | - !array_key_exists('phpVersion', $parameters) |
322 | | - || !is_array($parameters['phpVersion'])) { |
323 | | - return; |
| 325 | + array_key_exists('phpVersion', $parameters) |
| 326 | + && is_array($parameters['phpVersion']) |
| 327 | + ) { |
| 328 | + $phpVersion = $parameters['phpVersion']; |
| 329 | + |
| 330 | + if ($phpVersion['max'] < $phpVersion['min']) { |
| 331 | + throw new InvalidPhpVersionException('Invalid PHP version range: phpVersion.max should be greater or equal to phpVersion.min.'); |
| 332 | + } |
324 | 333 | } |
325 | 334 |
|
326 | | - $phpVersion = $parameters['phpVersion']; |
| 335 | + foreach ($parameters['ignoreErrors'] ?? [] as $ignoreError) { |
| 336 | + if (is_string($ignoreError)) { |
| 337 | + continue; |
| 338 | + } |
| 339 | + |
| 340 | + $atLeastOneOf = ['message', 'messages', 'identifier', 'identifiers', 'path', 'paths']; |
| 341 | + if (array_intersect($atLeastOneOf, array_keys($ignoreError)) === []) { |
| 342 | + throw new InvalidIgnoredErrorException('An ignoreErrors entry must contain at least one of the following fields: ' . implode(', ', $atLeastOneOf) . '.'); |
| 343 | + } |
327 | 344 |
|
328 | | - if ($phpVersion['max'] < $phpVersion['min']) { |
329 | | - throw new InvalidPhpVersionException('Invalid PHP version range: phpVersion.max should be greater or equal to phpVersion.min.'); |
| 345 | + foreach (['message', 'identifier', 'path'] as $field) { |
| 346 | + if (array_key_exists($field, $ignoreError) && array_key_exists($field . 's', $ignoreError)) { |
| 347 | + throw new InvalidIgnoredErrorException(sprintf('An ignoreErrors entry cannot contain both %s and %s fields.', $field, $field . 's')); |
| 348 | + } |
| 349 | + } |
| 350 | + |
| 351 | + if (array_key_exists('count', $ignoreError) && !array_key_exists('path', $ignoreError)) { |
| 352 | + throw new InvalidIgnoredErrorException('An ignoreErrors entry with count field must also contain path field.'); |
| 353 | + } |
330 | 354 | } |
331 | 355 | } |
332 | 356 |
|
|
0 commit comments