Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 3 additions & 29 deletions conf/parametersSchema.neon
Original file line number Diff line number Diff line change
Expand Up @@ -111,42 +111,16 @@ parametersSchema:
ignoreErrors: listOf(
anyOf(
string(),
structure([
?messages: listOf(string())
?identifier: string()
?identifiers: listOf(string())
?path: string()
?reportUnmatched: bool()
]),
structure([
?message: string()
?messages: listOf(string())
?identifier: string()
?identifiers: listOf(string())
?path: string()
?paths: listOf(string())
?count: int()
?reportUnmatched: bool()
]),
structure([
?message: string()
count: int()
path: string()
?identifier: string()
?identifiers: listOf(string())
?reportUnmatched: bool()
]),
structure([
?message: string()
paths: listOf(string())
?identifier: string()
?identifiers: listOf(string())
?reportUnmatched: bool()
]),
structure([
?messages: listOf(string())
paths: listOf(string())
?identifier: string()
?identifiers: listOf(string())
?reportUnmatched: bool()
])
)
)
internalErrorsCountLimit: int()
Expand Down
36 changes: 30 additions & 6 deletions src/DependencyInjection/ContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,22 @@
use PHPStan\ShouldNotHappenException;
use PHPStan\Type\ObjectType;
use function array_diff_key;
use function array_intersect;
use function array_key_exists;
use function array_keys;
use function array_map;
use function array_merge;
use function array_unique;
use function count;
use function dirname;
use function extension_loaded;
use function getenv;
use function implode;
use function ini_get;
use function is_array;
use function is_file;
use function is_readable;
use function is_string;
use function spl_object_id;
use function sprintf;
use function str_ends_with;
Expand Down Expand Up @@ -318,15 +322,35 @@ private function validateParameters(array $parameters, array $parametersSchema):
$processor->process($schema, $parameters);

if (
!array_key_exists('phpVersion', $parameters)
|| !is_array($parameters['phpVersion'])) {
return;
array_key_exists('phpVersion', $parameters)
&& is_array($parameters['phpVersion'])
) {
$phpVersion = $parameters['phpVersion'];

if ($phpVersion['max'] < $phpVersion['min']) {
throw new InvalidPhpVersionException('Invalid PHP version range: phpVersion.max should be greater or equal to phpVersion.min.');
}
}

$phpVersion = $parameters['phpVersion'];
foreach ($parameters['ignoreErrors'] ?? [] as $ignoreError) {
if (is_string($ignoreError)) {
continue;
}

$atLeastOneOf = ['message', 'messages', 'identifier', 'identifiers', 'path', 'paths'];
if (array_intersect($atLeastOneOf, array_keys($ignoreError)) === []) {
throw new InvalidIgnoredErrorException('An ignoreErrors entry must contain at least one of the following fields: ' . implode(', ', $atLeastOneOf) . '.');
}

if ($phpVersion['max'] < $phpVersion['min']) {
throw new InvalidPhpVersionException('Invalid PHP version range: phpVersion.max should be greater or equal to phpVersion.min.');
foreach (['message', 'identifier', 'path'] as $field) {
if (array_key_exists($field, $ignoreError) && array_key_exists($field . 's', $ignoreError)) {
throw new InvalidIgnoredErrorException(sprintf('An ignoreErrors entry cannot contain both %s and %s fields.', $field, $field . 's'));
}
}

if (array_key_exists('count', $ignoreError) && !array_key_exists('path', $ignoreError)) {
throw new InvalidIgnoredErrorException('An ignoreErrors entry with count field must also contain path field.');
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/DependencyInjection/InvalidIgnoredErrorException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php declare(strict_types = 1);

namespace PHPStan\DependencyInjection;

use Nette\DI\InvalidConfigurationException;

final class InvalidIgnoredErrorException extends InvalidConfigurationException
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php declare(strict_types = 1);

namespace PHPStan\DependencyInjection;

use PHPStan\Testing\PHPStanTestCase;
use PHPUnit\Framework\Attributes\DataProvider;

class InvalidIgnoredErrorExceptionTest extends PHPStanTestCase
{

private static string $configFile;

public static function dateValidateIgnoreErrors(): iterable

Check failure on line 13 in tests/PHPStan/DependencyInjection/InvalidIgnoredErrorExceptionTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, ubuntu-latest)

Method PHPStan\DependencyInjection\InvalidIgnoredErrorExceptionTest::dateValidateIgnoreErrors() return type has no value type specified in iterable type iterable.

Check failure on line 13 in tests/PHPStan/DependencyInjection/InvalidIgnoredErrorExceptionTest.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.4)

Method PHPStan\DependencyInjection\InvalidIgnoredErrorExceptionTest::dateValidateIgnoreErrors() return type has no value type specified in iterable type iterable.

Check failure on line 13 in tests/PHPStan/DependencyInjection/InvalidIgnoredErrorExceptionTest.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.2)

Method PHPStan\DependencyInjection\InvalidIgnoredErrorExceptionTest::dateValidateIgnoreErrors() return type has no value type specified in iterable type iterable.

Check failure on line 13 in tests/PHPStan/DependencyInjection/InvalidIgnoredErrorExceptionTest.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.5)

Method PHPStan\DependencyInjection\InvalidIgnoredErrorExceptionTest::dateValidateIgnoreErrors() return type has no value type specified in iterable type iterable.

Check failure on line 13 in tests/PHPStan/DependencyInjection/InvalidIgnoredErrorExceptionTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, ubuntu-latest)

Method PHPStan\DependencyInjection\InvalidIgnoredErrorExceptionTest::dateValidateIgnoreErrors() return type has no value type specified in iterable type iterable.

Check failure on line 13 in tests/PHPStan/DependencyInjection/InvalidIgnoredErrorExceptionTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.4, ubuntu-latest)

Method PHPStan\DependencyInjection\InvalidIgnoredErrorExceptionTest::dateValidateIgnoreErrors() return type has no value type specified in iterable type iterable.

Check failure on line 13 in tests/PHPStan/DependencyInjection/InvalidIgnoredErrorExceptionTest.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.3)

Method PHPStan\DependencyInjection\InvalidIgnoredErrorExceptionTest::dateValidateIgnoreErrors() return type has no value type specified in iterable type iterable.

Check failure on line 13 in tests/PHPStan/DependencyInjection/InvalidIgnoredErrorExceptionTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.5, ubuntu-latest)

Method PHPStan\DependencyInjection\InvalidIgnoredErrorExceptionTest::dateValidateIgnoreErrors() return type has no value type specified in iterable type iterable.

Check failure on line 13 in tests/PHPStan/DependencyInjection/InvalidIgnoredErrorExceptionTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, ubuntu-latest)

Method PHPStan\DependencyInjection\InvalidIgnoredErrorExceptionTest::dateValidateIgnoreErrors() return type has no value type specified in iterable type iterable.

Check failure on line 13 in tests/PHPStan/DependencyInjection/InvalidIgnoredErrorExceptionTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, ubuntu-latest)

Method PHPStan\DependencyInjection\InvalidIgnoredErrorExceptionTest::dateValidateIgnoreErrors() return type has no value type specified in iterable type iterable.

Check failure on line 13 in tests/PHPStan/DependencyInjection/InvalidIgnoredErrorExceptionTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, windows-latest)

Method PHPStan\DependencyInjection\InvalidIgnoredErrorExceptionTest::dateValidateIgnoreErrors() return type has no value type specified in iterable type iterable.

Check failure on line 13 in tests/PHPStan/DependencyInjection/InvalidIgnoredErrorExceptionTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.4, windows-latest)

Method PHPStan\DependencyInjection\InvalidIgnoredErrorExceptionTest::dateValidateIgnoreErrors() return type has no value type specified in iterable type iterable.

Check failure on line 13 in tests/PHPStan/DependencyInjection/InvalidIgnoredErrorExceptionTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, windows-latest)

Method PHPStan\DependencyInjection\InvalidIgnoredErrorExceptionTest::dateValidateIgnoreErrors() return type has no value type specified in iterable type iterable.

Check failure on line 13 in tests/PHPStan/DependencyInjection/InvalidIgnoredErrorExceptionTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.5, windows-latest)

Method PHPStan\DependencyInjection\InvalidIgnoredErrorExceptionTest::dateValidateIgnoreErrors() return type has no value type specified in iterable type iterable.

Check failure on line 13 in tests/PHPStan/DependencyInjection/InvalidIgnoredErrorExceptionTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, windows-latest)

Method PHPStan\DependencyInjection\InvalidIgnoredErrorExceptionTest::dateValidateIgnoreErrors() return type has no value type specified in iterable type iterable.

Check failure on line 13 in tests/PHPStan/DependencyInjection/InvalidIgnoredErrorExceptionTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, windows-latest)

Method PHPStan\DependencyInjection\InvalidIgnoredErrorExceptionTest::dateValidateIgnoreErrors() return type has no value type specified in iterable type iterable.

Check failure on line 13 in tests/PHPStan/DependencyInjection/InvalidIgnoredErrorExceptionTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4, ubuntu-latest)

Method PHPStan\DependencyInjection\InvalidIgnoredErrorExceptionTest::dateValidateIgnoreErrors() return type has no value type specified in iterable type iterable.

Check failure on line 13 in tests/PHPStan/DependencyInjection/InvalidIgnoredErrorExceptionTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4, windows-latest)

Method PHPStan\DependencyInjection\InvalidIgnoredErrorExceptionTest::dateValidateIgnoreErrors() return type has no value type specified in iterable type iterable.
{
yield [
__DIR__ . '/invalidIgnoreErrors/one.neon',
'An ignoreErrors entry cannot contain both message and messages fields.',
];
yield [
__DIR__ . '/invalidIgnoreErrors/two.neon',
'An ignoreErrors entry cannot contain both path and paths fields.',
];
}

#[DataProvider('dateValidateIgnoreErrors')]
public function testValidateIgnoreErrors(string $file, string $expectedMessage): void
{
self::$configFile = $file;
$this->expectExceptionMessage($expectedMessage);
self::getContainer();
}

public static function getAdditionalConfigFiles(): array
{
return [
__DIR__ . '/../../../conf/bleedingEdge.neon',
self::$configFile,
];
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
ignoreErrors:
-
message: '#One#'
messages: ['#Two#']
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
ignoreErrors:
-
path: ../IgnoreErrorsTest.php
paths: [../IgnoreErrorsTest.php]
Loading