Skip to content

Commit 757f207

Browse files
committed
Add-php-configurator
1 parent 0a6e968 commit 757f207

21 files changed

+565
-114
lines changed

build/phpstan.neon

Lines changed: 0 additions & 112 deletions
This file was deleted.

build/phpstan.php

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use PHPStan\DependencyInjection\ProjectConfig\CacheConfig;
6+
use PHPStan\DependencyInjection\ProjectConfig\ExceptionsCheckConfig;
7+
use PHPStan\DependencyInjection\ProjectConfig\ExceptionsConfig;
8+
use PHPStan\DependencyInjection\ProjectConfig\ExcludePathsConfig;
9+
use PHPStan\DependencyInjection\ProjectConfig\IgnoreErrorsConfig;
10+
use PHPStan\DependencyInjection\ProjectConfig\ParametersConfig;
11+
use PHPStan\DependencyInjection\ProjectConfig\ProjectConfig;
12+
13+
return new ProjectConfig(
14+
includes: [
15+
'../vendor/phpstan/phpstan-deprecation-rules/rules.neon',
16+
'../vendor/phpstan/phpstan-nette/rules.neon',
17+
'../vendor/phpstan/phpstan-phpunit/extension.neon',
18+
'../vendor/phpstan/phpstan-phpunit/rules.neon',
19+
'../vendor/phpstan/phpstan-strict-rules/rules.neon',
20+
'../conf/bleedingEdge.neon',
21+
'../phpstan-baseline.neon',
22+
'../phpstan-baseline.php',
23+
'ignore-by-php-version.neon.php',
24+
'ignore-by-architecture.neon.php',
25+
],
26+
parameters: new ParametersConfig(
27+
level: 8,
28+
paths: [
29+
__DIR__ . '/PHPStan',
30+
__DIR__ . '/../src',
31+
__DIR__ . '/../tests',
32+
],
33+
bootstrapFiles: [__DIR__ . '/../tests/phpstan-bootstrap.php'],
34+
cache: new CacheConfig(nodesByStringCountMax: 128),
35+
checkUninitializedProperties: true,
36+
checkMissingCallableSignature: true,
37+
excludePaths: new ExcludePathsConfig(
38+
analyseAndScan: [
39+
__DIR__ . '/../tests/*/data/*',
40+
__DIR__ . '/../tests/tmp/*',
41+
__DIR__ . '/../tests/PHPStan/Analyser/nsrt/*',
42+
__DIR__ . '/../tests/PHPStan/Analyser/traits/*',
43+
__DIR__ . '/../tests/notAutoloaded/*',
44+
__DIR__ . '/../tests/PHPStan/Reflection/UnionTypesTest.php',
45+
__DIR__ . '/../tests/PHPStan/Reflection/MixedTypeTest.php',
46+
__DIR__ . '/../tests/e2e/magic-setter/*',
47+
__DIR__ . '/../tests/PHPStan/Rules/Properties/UninitializedPropertyRuleTest.php',
48+
__DIR__ . '/../tests/PHPStan/Command/IgnoredRegexValidatorTest.php',
49+
__DIR__ . '/../src/Command/IgnoredRegexValidator.php',
50+
],
51+
),
52+
exceptions: new ExceptionsConfig(
53+
uncheckedExceptionClasses: [
54+
'PHPStan\ShouldNotHappenException',
55+
'Symfony\Component\Console\Exception\InvalidArgumentException',
56+
'PHPStan\BetterReflection\SourceLocator\Exception\InvalidFileLocation',
57+
'PHPStan\BetterReflection\SourceLocator\Exception\InvalidArgumentException',
58+
'Symfony\Component\Finder\Exception\DirectoryNotFoundException',
59+
'InvalidArgumentException',
60+
'PHPStan\DependencyInjection\ParameterNotFoundException',
61+
'PHPStan\DependencyInjection\DuplicateIncludedFilesException',
62+
'PHPStan\Analyser\UndefinedVariableException',
63+
'RuntimeException',
64+
'Nette\Neon\Exception',
65+
'Nette\Utils\JsonException',
66+
'PHPStan\File\CouldNotReadFileException',
67+
'PHPStan\File\CouldNotWriteFileException',
68+
'PHPStan\Parser\ParserErrorsException',
69+
'ReflectionException',
70+
'Nette\Utils\AssertionException',
71+
'PHPStan\File\PathNotFoundException',
72+
'PHPStan\Broker\ClassNotFoundException',
73+
'PHPStan\Broker\FunctionNotFoundException',
74+
'PHPStan\Broker\ConstantNotFoundException',
75+
'PHPStan\Reflection\MissingMethodFromReflectionException',
76+
'PHPStan\Reflection\MissingPropertyFromReflectionException',
77+
'PHPStan\Reflection\MissingConstantFromReflectionException',
78+
'PHPStan\Type\CircularTypeAliasDefinitionException',
79+
'PHPStan\Broker\ClassAutoloadingException',
80+
'LogicException',
81+
'Error',
82+
],
83+
check: new ExceptionsCheckConfig(missingCheckedExceptionInThrows: true, tooWideThrowType: true),
84+
),
85+
ignoreErrors: [
86+
'#^Dynamic call to static method PHPUnit\\\Framework\\\\\S+\(\)\.$#',
87+
'#should be contravariant with parameter \$node \(PhpParser\\\Node\) of method PHPStan\\\Rules\\\Rule<PhpParser\\\Node>::processNode\(\)$#',
88+
'#Variable property access on PhpParser\\\Node#',
89+
'#Test::data[a-zA-Z0-9_]+\(\) return type has no value type specified in iterable type#',
90+
new IgnoreErrorsConfig(
91+
message: '#Fetching class constant class of deprecated class DeprecatedAnnotations\\\DeprecatedFoo.#',
92+
path: __DIR__ . '/../tests/PHPStan/Reflection/Annotations/DeprecatedAnnotationsTest.php',
93+
),
94+
new IgnoreErrorsConfig(
95+
message: '#Fetching class constant class of deprecated class DeprecatedAnnotations\\\DeprecatedWithMultipleTags.#',
96+
path: __DIR__ . '/../tests/PHPStan/Reflection/Annotations/DeprecatedAnnotationsTest.php',
97+
),
98+
new IgnoreErrorsConfig(
99+
message: '#^Variable property access on T of PHPStan\\\Rules\\\RuleError\.$#',
100+
path: __DIR__ . '/../src/Rules/RuleErrorBuilder.php',
101+
),
102+
new IgnoreErrorsConfig(
103+
message: '#^Parameter \#1 (?:\$argument|\$objectOrClass) of class ReflectionClass constructor expects class\-string\<PHPStan\\\ExtensionInstaller\\\GeneratedConfig\>\|PHPStan\\\ExtensionInstaller\\\GeneratedConfig, string given\.$#',
104+
count: 1,
105+
path: __DIR__ . '/../src/Command/CommandHelper.php',
106+
),
107+
new IgnoreErrorsConfig(
108+
message: '#^Parameter \#1 (?:\$argument|\$objectOrClass) of class ReflectionClass constructor expects class\-string\<PHPStan\\\ExtensionInstaller\\\GeneratedConfig\>\|PHPStan\\\ExtensionInstaller\\\GeneratedConfig, string given\.$#',
109+
count: 1,
110+
path: __DIR__ . '/../src/Diagnose/PHPStanDiagnoseExtension.php',
111+
),
112+
'#^Short ternary operator is not allowed#',
113+
],
114+
reportStaticMethodSignatures: true,
115+
tmpDir: '%rootDir%/tmp',
116+
stubFiles: [
117+
__DIR__ . '/stubs/ReactChildProcess.stub',
118+
__DIR__ . '/stubs/ReactStreams.stub',
119+
__DIR__ . '/stubs/NetteDIContainer.stub',
120+
__DIR__ . '/stubs/PhpParserName.stub',
121+
],
122+
),
123+
_extra: [
124+
'services' => [
125+
[
126+
'class' => 'PHPStan\Build\ServiceLocatorDynamicReturnTypeExtension',
127+
'tags' => ['phpstan.broker.dynamicMethodReturnTypeExtension'],
128+
],
129+
[
130+
'class' => 'PHPStan\Build\ContainerDynamicReturnTypeExtension',
131+
'tags' => ['phpstan.broker.dynamicMethodReturnTypeExtension'],
132+
],
133+
]
134+
]
135+
);

phpstan.neon.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
includes: [ build/phpstan.neon ]
1+
includes: [ build/phpstan.php ]

src/DependencyInjection/ContainerFactory.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace PHPStan\DependencyInjection;
44

55
use Nette\Bootstrap\Extensions\PhpExtension;
6-
use Nette\DI\Config\Adapters\PhpAdapter;
76
use Nette\DI\Definitions\Statement;
87
use Nette\DI\Extensions\ExtensionsExtension;
98
use Nette\DI\Helpers;

src/DependencyInjection/LoaderFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public function createLoader(): Loader
2323
$loader = new NeonLoader($this->fileHelper, $this->generateBaselineFile);
2424
$loader->addAdapter('dist', NeonAdapter::class);
2525
$loader->addAdapter('neon', NeonAdapter::class);
26+
$loader->addAdapter('php', PhpAdapter::class);
2627
$loader->setParameters([
2728
'rootDir' => $this->rootDir,
2829
'currentWorkingDirectory' => $this->currentWorkingDirectory,
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\DependencyInjection;
4+
5+
use Nette\DI\Config\Adapter;
6+
use PHPStan\DependencyInjection\ProjectConfig\ProjectConfig;
7+
use RuntimeException;
8+
use function get_debug_type;
9+
use function is_array;
10+
11+
final class PhpAdapter implements Adapter
12+
{
13+
14+
/**
15+
* @return array<array-key, mixed>
16+
*/
17+
public function load(string $file): array
18+
{
19+
$configuration = require $file;
20+
if (is_array($configuration)) {
21+
return $configuration;
22+
} elseif ($configuration instanceof ProjectConfig) {
23+
return $configuration->toArray();
24+
}
25+
26+
throw new RuntimeException('Unexpected configuration type: ' . get_debug_type($configuration));
27+
}
28+
29+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\DependencyInjection\ProjectConfig;
4+
5+
interface Arrayable
6+
{
7+
8+
/** @return array<array-key, mixed> */
9+
public function toArray(): array;
10+
11+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\DependencyInjection\ProjectConfig;
4+
5+
use function array_key_exists;
6+
use function array_map;
7+
use function get_object_vars;
8+
use function is_array;
9+
10+
trait ArrayableTrait
11+
{
12+
13+
public function toArray(): array
14+
{
15+
$vars = get_object_vars($this);
16+
if (array_key_exists('_extra', $vars) && is_array($vars['_extra'])) {
17+
$vars += $vars['_extra'];
18+
unset($vars['_extra']);
19+
}
20+
21+
$config = [];
22+
foreach ($vars as $key => $value) {
23+
if ($value === Undefined::Undefined) {
24+
continue;
25+
}
26+
if ($value instanceof Arrayable) {
27+
$config[$key] = $value->toArray();
28+
} elseif (is_array($value)) {
29+
$config[$key] = array_map(
30+
static fn (mixed $item): mixed => $item instanceof Arrayable ? $item->toArray() : $item,
31+
$value,
32+
);
33+
} else {
34+
$config[$key] = $value;
35+
}
36+
}
37+
return $config;
38+
}
39+
40+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\DependencyInjection\ProjectConfig;
4+
5+
final class CacheConfig implements Arrayable
6+
{
7+
8+
use ArrayableTrait;
9+
10+
public function __construct(
11+
private readonly int|Undefined $nodesByStringCountMax = Undefined::Undefined,
12+
)
13+
{
14+
}
15+
16+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\DependencyInjection\ProjectConfig;
4+
5+
final class ExceptionsCheckConfig implements Arrayable
6+
{
7+
8+
use ArrayableTrait;
9+
10+
public function __construct(
11+
private readonly bool|Undefined $missingCheckedExceptionInThrows = Undefined::Undefined,
12+
private readonly bool|Undefined $tooWideThrowType = Undefined::Undefined,
13+
)
14+
{
15+
}
16+
17+
}

0 commit comments

Comments
 (0)