Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
112 changes: 0 additions & 112 deletions build/phpstan.neon

This file was deleted.

135 changes: 135 additions & 0 deletions build/phpstan.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<?php

declare(strict_types=1);

use PHPStan\DependencyInjection\ProjectConfig\CacheConfig;
use PHPStan\DependencyInjection\ProjectConfig\Exceptions\CheckConfig;
use PHPStan\DependencyInjection\ProjectConfig\ExceptionsConfig;
use PHPStan\DependencyInjection\ProjectConfig\ExcludePathsConfig;
use PHPStan\DependencyInjection\ProjectConfig\IgnoreErrorsConfig;
use PHPStan\DependencyInjection\ProjectConfig\ParametersConfig;
use PHPStan\DependencyInjection\ProjectConfig\ProjectConfig;

return new ProjectConfig(
includes: [
'../vendor/phpstan/phpstan-deprecation-rules/rules.neon',
'../vendor/phpstan/phpstan-nette/rules.neon',
'../vendor/phpstan/phpstan-phpunit/extension.neon',
'../vendor/phpstan/phpstan-phpunit/rules.neon',
'../vendor/phpstan/phpstan-strict-rules/rules.neon',
'../conf/bleedingEdge.neon',
'../phpstan-baseline.neon',
'../phpstan-baseline.php',
'ignore-by-php-version.neon.php',
'ignore-by-architecture.neon.php',
],
parameters: new ParametersConfig(
level: 8,
paths: [
__DIR__ . '/PHPStan',
__DIR__ . '/../src',
__DIR__ . '/../tests',
],
bootstrapFiles: [__DIR__ . '/../tests/phpstan-bootstrap.php'],
cache: new CacheConfig(nodesByStringCountMax: 128),
checkUninitializedProperties: true,
checkMissingCallableSignature: true,
excludePaths: new ExcludePathsConfig(
analyseAndScan: [
__DIR__ . '/../tests/*/data/*',
__DIR__ . '/../tests/tmp/*',
__DIR__ . '/../tests/PHPStan/Analyser/nsrt/*',
__DIR__ . '/../tests/PHPStan/Analyser/traits/*',
__DIR__ . '/../tests/notAutoloaded/*',
__DIR__ . '/../tests/PHPStan/Reflection/UnionTypesTest.php',
__DIR__ . '/../tests/PHPStan/Reflection/MixedTypeTest.php',
__DIR__ . '/../tests/e2e/magic-setter/*',
__DIR__ . '/../tests/PHPStan/Rules/Properties/UninitializedPropertyRuleTest.php',
__DIR__ . '/../tests/PHPStan/Command/IgnoredRegexValidatorTest.php',
__DIR__ . '/../src/Command/IgnoredRegexValidator.php',
],
),
exceptions: new ExceptionsConfig(
uncheckedExceptionClasses: [
'PHPStan\ShouldNotHappenException',
'Symfony\Component\Console\Exception\InvalidArgumentException',
'PHPStan\BetterReflection\SourceLocator\Exception\InvalidFileLocation',
'PHPStan\BetterReflection\SourceLocator\Exception\InvalidArgumentException',
'Symfony\Component\Finder\Exception\DirectoryNotFoundException',
'InvalidArgumentException',
'PHPStan\DependencyInjection\ParameterNotFoundException',
'PHPStan\DependencyInjection\DuplicateIncludedFilesException',
'PHPStan\Analyser\UndefinedVariableException',
'RuntimeException',
'Nette\Neon\Exception',
'Nette\Utils\JsonException',
'PHPStan\File\CouldNotReadFileException',
'PHPStan\File\CouldNotWriteFileException',
'PHPStan\Parser\ParserErrorsException',
'ReflectionException',
'Nette\Utils\AssertionException',
'PHPStan\File\PathNotFoundException',
'PHPStan\Broker\ClassNotFoundException',
'PHPStan\Broker\FunctionNotFoundException',
'PHPStan\Broker\ConstantNotFoundException',
'PHPStan\Reflection\MissingMethodFromReflectionException',
'PHPStan\Reflection\MissingPropertyFromReflectionException',
'PHPStan\Reflection\MissingConstantFromReflectionException',
'PHPStan\Type\CircularTypeAliasDefinitionException',
'PHPStan\Broker\ClassAutoloadingException',
'LogicException',
'Error',
],
check: new CheckConfig(missingCheckedExceptionInThrows: true, tooWideThrowType: true),
),
ignoreErrors: [
'#^Dynamic call to static method PHPUnit\\\Framework\\\\\S+\(\)\.$#',
'#should be contravariant with parameter \$node \(PhpParser\\\Node\) of method PHPStan\\\Rules\\\Rule<PhpParser\\\Node>::processNode\(\)$#',
'#Variable property access on PhpParser\\\Node#',
'#Test::data[a-zA-Z0-9_]+\(\) return type has no value type specified in iterable type#',
new IgnoreErrorsConfig(
message: '#Fetching class constant class of deprecated class DeprecatedAnnotations\\\DeprecatedFoo.#',
path: __DIR__ . '/../tests/PHPStan/Reflection/Annotations/DeprecatedAnnotationsTest.php',
),
new IgnoreErrorsConfig(
message: '#Fetching class constant class of deprecated class DeprecatedAnnotations\\\DeprecatedWithMultipleTags.#',
path: __DIR__ . '/../tests/PHPStan/Reflection/Annotations/DeprecatedAnnotationsTest.php',
),
new IgnoreErrorsConfig(
message: '#^Variable property access on T of PHPStan\\\Rules\\\RuleError\.$#',
path: __DIR__ . '/../src/Rules/RuleErrorBuilder.php',
),
new IgnoreErrorsConfig(
message: '#^Parameter \#1 (?:\$argument|\$objectOrClass) of class ReflectionClass constructor expects class\-string\<PHPStan\\\ExtensionInstaller\\\GeneratedConfig\>\|PHPStan\\\ExtensionInstaller\\\GeneratedConfig, string given\.$#',
count: 1,
path: __DIR__ . '/../src/Command/CommandHelper.php',
),
new IgnoreErrorsConfig(
message: '#^Parameter \#1 (?:\$argument|\$objectOrClass) of class ReflectionClass constructor expects class\-string\<PHPStan\\\ExtensionInstaller\\\GeneratedConfig\>\|PHPStan\\\ExtensionInstaller\\\GeneratedConfig, string given\.$#',
count: 1,
path: __DIR__ . '/../src/Diagnose/PHPStanDiagnoseExtension.php',
),
'#^Short ternary operator is not allowed#',
],
reportStaticMethodSignatures: true,
tmpDir: '%rootDir%/tmp',
stubFiles: [
__DIR__ . '/stubs/ReactChildProcess.stub',
__DIR__ . '/stubs/ReactStreams.stub',
__DIR__ . '/stubs/NetteDIContainer.stub',
__DIR__ . '/stubs/PhpParserName.stub',
],
),
_extra: [
'services' => [
[
'class' => 'PHPStan\Build\ServiceLocatorDynamicReturnTypeExtension',
'tags' => ['phpstan.broker.dynamicMethodReturnTypeExtension'],
],
[
'class' => 'PHPStan\Build\ContainerDynamicReturnTypeExtension',
'tags' => ['phpstan.broker.dynamicMethodReturnTypeExtension'],
],
]
]
);
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1 +1 @@
includes: [ build/phpstan.neon ]
includes: [ build/phpstan.php ]
1 change: 0 additions & 1 deletion src/DependencyInjection/ContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace PHPStan\DependencyInjection;

use Nette\Bootstrap\Extensions\PhpExtension;
use Nette\DI\Config\Adapters\PhpAdapter;
use Nette\DI\Definitions\Statement;
use Nette\DI\Extensions\ExtensionsExtension;
use Nette\DI\Helpers;
Expand Down
1 change: 1 addition & 0 deletions src/DependencyInjection/LoaderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function createLoader(): Loader
$loader = new NeonLoader($this->fileHelper, $this->generateBaselineFile);
$loader->addAdapter('dist', NeonAdapter::class);
$loader->addAdapter('neon', NeonAdapter::class);
$loader->addAdapter('php', PhpAdapter::class);
$loader->setParameters([
'rootDir' => $this->rootDir,
'currentWorkingDirectory' => $this->currentWorkingDirectory,
Expand Down
29 changes: 29 additions & 0 deletions src/DependencyInjection/PhpAdapter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php declare(strict_types = 1);

namespace PHPStan\DependencyInjection;

use Nette\DI\Config\Adapter;
use PHPStan\DependencyInjection\ProjectConfig\ProjectConfig;
use RuntimeException;
use function get_debug_type;
use function is_array;

final class PhpAdapter implements Adapter
{

/**
* @return array<array-key, mixed>
*/
public function load(string $file): array
{
$configuration = require $file;
if (is_array($configuration)) {
return $configuration;
} elseif ($configuration instanceof ProjectConfig) {
return $configuration->toArray();
}

throw new RuntimeException('Unexpected configuration type: ' . get_debug_type($configuration));
}

}
11 changes: 11 additions & 0 deletions src/DependencyInjection/ProjectConfig/Arrayable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php declare(strict_types = 1);

namespace PHPStan\DependencyInjection\ProjectConfig;

interface Arrayable
{

/** @return array<array-key, mixed> */
public function toArray(): array;

}
40 changes: 40 additions & 0 deletions src/DependencyInjection/ProjectConfig/ArrayableTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php declare(strict_types = 1);

namespace PHPStan\DependencyInjection\ProjectConfig;

use function array_key_exists;
use function array_map;
use function get_object_vars;
use function is_array;

trait ArrayableTrait
{

public function toArray(): array
{
$vars = get_object_vars($this);
if (array_key_exists('_extra', $vars) && is_array($vars['_extra'])) {
$vars += $vars['_extra'];
unset($vars['_extra']);
}

$config = [];
foreach ($vars as $key => $value) {
if ($value === Undefined::Undefined) {
continue;
}
if ($value instanceof Arrayable) {
$config[$key] = $value->toArray();
} elseif (is_array($value)) {
$config[$key] = array_map(
static fn (mixed $item): mixed => $item instanceof Arrayable ? $item->toArray() : $item,
$value,
);
} else {
$config[$key] = $value;
}
}
return $config;
}

}
16 changes: 16 additions & 0 deletions src/DependencyInjection/ProjectConfig/CacheConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php declare(strict_types = 1);

namespace PHPStan\DependencyInjection\ProjectConfig;

final class CacheConfig implements Arrayable
{

use ArrayableTrait;

public function __construct(
private readonly int|Undefined $nodesByStringCountMax = Undefined::Undefined,
)
{
}

}
21 changes: 21 additions & 0 deletions src/DependencyInjection/ProjectConfig/Exceptions/CheckConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php declare(strict_types = 1);

namespace PHPStan\DependencyInjection\ProjectConfig\Exceptions;

use PHPStan\DependencyInjection\ProjectConfig\Arrayable;
use PHPStan\DependencyInjection\ProjectConfig\ArrayableTrait;
use PHPStan\DependencyInjection\ProjectConfig\Undefined;

final class CheckConfig implements Arrayable
{

use ArrayableTrait;

public function __construct(
private readonly bool|Undefined $missingCheckedExceptionInThrows = Undefined::Undefined,
private readonly bool|Undefined $tooWideThrowType = Undefined::Undefined,
)
{
}

}
Loading
Loading