Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into phpstan2
Browse files Browse the repository at this point in the history
# Conflicts:
#	dev-tools/phpstan/baseline.php
  • Loading branch information
keradus committed Nov 18, 2024
2 parents ed4353f + 52dc062 commit 41fdc44
Show file tree
Hide file tree
Showing 27 changed files with 227 additions and 67 deletions.
7 changes: 7 additions & 0 deletions .php-cs-fixer.php-highest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
$config->setRules(array_merge($config->getRules(), [
'@PHP83Migration' => true,
'@PHP82Migration:risky' => true,
'phpdoc_to_property_type' => [ // experimental
'map_types' => [
'TFixerInputConfig' => 'array',
'TFixerComputedConfig' => 'array',
'TFixer' => '\PhpCsFixer\AbstractFixer',
],
],
'fully_qualified_strict_types' => ['import_symbols' => true],
'php_unit_attributes' => false, // as is not yet supported by PhpCsFixerInternal/configurable_fixer_template
]));
Expand Down
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,18 @@
"symfony/stopwatch": "^5.4 || ^6.0 || ^7.0"
},
"require-dev": {
"facile-it/paraunit": "^1.3 || ^2.3",
"infection/infection": "^0.29.5",
"justinrainbow/json-schema": "^5.2",
"facile-it/paraunit": "^1.3.1 || ^2.4",
"infection/infection": "^0.29.8",
"justinrainbow/json-schema": "^5.3 || ^6.0",
"keradus/cli-executor": "^2.1",
"mikey179/vfsstream": "^1.6.11",
"mikey179/vfsstream": "^1.6.12",
"php-coveralls/php-coveralls": "^2.7",
"php-cs-fixer/accessible-object": "^1.1",
"php-cs-fixer/phpunit-constraint-isidenticalstring": "^1.5",
"php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "^1.5",
"phpunit/phpunit": "^9.6.19 || ^10.5.21 || ^11.2",
"symfony/var-dumper": "^5.4 || ^6.0 || ^7.0",
"symfony/yaml": "^5.4 || ^6.0 || ^7.0"
"phpunit/phpunit": "^9.6.21 || ^10.5.38 || ^11.4.3",
"symfony/var-dumper": "^5.4.47 || ^6.4.15 || ^7.1.8",
"symfony/yaml": "^5.4.45 || ^6.4.13 || ^7.1.6"
},
"suggest": {
"ext-dom": "For handling output formats in XML",
Expand Down
13 changes: 8 additions & 5 deletions dev-tools/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

96 changes: 72 additions & 24 deletions dev-tools/phpstan/baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@
'count' => 1,
'path' => __DIR__ . '/../../src/Console/Command/CheckCommand.php',
];
$ignoreErrors[] = [
'message' => '#^Property PhpCsFixer\\\\Console\\\\Command\\\\CheckCommand\\:\\:\\$defaultDescription has no type specified\\.$#',
'identifier' => 'missingType.property',
'count' => 1,
'path' => __DIR__ . '/../../src/Console/Command/CheckCommand.php',
];
$ignoreErrors[] = [
'message' => '#^Property PhpCsFixer\\\\Console\\\\Command\\\\CheckCommand\\:\\:\\$defaultName has no type specified\\.$#',
'identifier' => 'missingType.property',
'count' => 1,
'path' => __DIR__ . '/../../src/Console/Command/CheckCommand.php',
];
$ignoreErrors[] = [
'message' => '#^Offset 1 might not exist on array\\.$#',
'identifier' => 'offsetAccess.notFound',
Expand Down Expand Up @@ -109,6 +121,18 @@
'count' => 1,
'path' => __DIR__ . '/../../src/Console/Command/DescribeCommand.php',
];
$ignoreErrors[] = [
'message' => '#^Property PhpCsFixer\\\\Console\\\\Command\\\\DescribeCommand\\:\\:\\$defaultName has no type specified\\.$#',
'identifier' => 'missingType.property',
'count' => 1,
'path' => __DIR__ . '/../../src/Console/Command/DescribeCommand.php',
];
$ignoreErrors[] = [
'message' => '#^Property PhpCsFixer\\\\Console\\\\Command\\\\DocumentationCommand\\:\\:\\$defaultName has no type specified\\.$#',
'identifier' => 'missingType.property',
'count' => 1,
'path' => __DIR__ . '/../../src/Console/Command/DocumentationCommand.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#3 \\$cwd of class PhpCsFixer\\\\Console\\\\ConfigurationResolver constructor expects string, string\\|false given\\.$#',
'identifier' => 'argument.type',
Expand All @@ -121,6 +145,24 @@
'count' => 1,
'path' => __DIR__ . '/../../src/Console/Command/FixCommand.php',
];
$ignoreErrors[] = [
'message' => '#^Property PhpCsFixer\\\\Console\\\\Command\\\\FixCommand\\:\\:\\$defaultDescription has no type specified\\.$#',
'identifier' => 'missingType.property',
'count' => 1,
'path' => __DIR__ . '/../../src/Console/Command/FixCommand.php',
];
$ignoreErrors[] = [
'message' => '#^Property PhpCsFixer\\\\Console\\\\Command\\\\FixCommand\\:\\:\\$defaultName has no type specified\\.$#',
'identifier' => 'missingType.property',
'count' => 1,
'path' => __DIR__ . '/../../src/Console/Command/FixCommand.php',
];
$ignoreErrors[] = [
'message' => '#^Property PhpCsFixer\\\\Console\\\\Command\\\\HelpCommand\\:\\:\\$defaultName has no type specified\\.$#',
'identifier' => 'missingType.property',
'count' => 1,
'path' => __DIR__ . '/../../src/Console/Command/HelpCommand.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#2 \\$basePath of static method Symfony\\\\Component\\\\Filesystem\\\\Path\\:\\:makeRelative\\(\\) expects string, string\\|false given\\.$#',
'identifier' => 'argument.type',
Expand All @@ -133,6 +175,18 @@
'count' => 1,
'path' => __DIR__ . '/../../src/Console/Command/ListFilesCommand.php',
];
$ignoreErrors[] = [
'message' => '#^Property PhpCsFixer\\\\Console\\\\Command\\\\ListFilesCommand\\:\\:\\$defaultName has no type specified\\.$#',
'identifier' => 'missingType.property',
'count' => 1,
'path' => __DIR__ . '/../../src/Console/Command/ListFilesCommand.php',
];
$ignoreErrors[] = [
'message' => '#^Property PhpCsFixer\\\\Console\\\\Command\\\\ListSetsCommand\\:\\:\\$defaultName has no type specified\\.$#',
'identifier' => 'missingType.property',
'count' => 1,
'path' => __DIR__ . '/../../src/Console/Command/ListSetsCommand.php',
];
$ignoreErrors[] = [
'message' => '#^Offset \'argv\' might not exist on array\\<mixed\\>\\.$#',
'identifier' => 'offsetAccess.notFound',
Expand All @@ -145,12 +199,30 @@
'count' => 1,
'path' => __DIR__ . '/../../src/Console/Command/SelfUpdateCommand.php',
];
$ignoreErrors[] = [
'message' => '#^Property PhpCsFixer\\\\Console\\\\Command\\\\SelfUpdateCommand\\:\\:\\$defaultName has no type specified\\.$#',
'identifier' => 'missingType.property',
'count' => 1,
'path' => __DIR__ . '/../../src/Console/Command/SelfUpdateCommand.php',
];
$ignoreErrors[] = [
'message' => '#^Offset \'files\' might not exist on array\\.$#',
'identifier' => 'offsetAccess.notFound',
'count' => 1,
'path' => __DIR__ . '/../../src/Console/Command/WorkerCommand.php',
];
$ignoreErrors[] = [
'message' => '#^Property PhpCsFixer\\\\Console\\\\Command\\\\WorkerCommand\\:\\:\\$defaultDescription has no type specified\\.$#',
'identifier' => 'missingType.property',
'count' => 1,
'path' => __DIR__ . '/../../src/Console/Command/WorkerCommand.php',
];
$ignoreErrors[] = [
'message' => '#^Property PhpCsFixer\\\\Console\\\\Command\\\\WorkerCommand\\:\\:\\$defaultName has no type specified\\.$#',
'identifier' => 'missingType.property',
'count' => 1,
'path' => __DIR__ . '/../../src/Console/Command/WorkerCommand.php',
];
$ignoreErrors[] = [
'message' => '#^Offset \'allow\\-risky\' might not exist on array\\<string, mixed\\>\\.$#',
'identifier' => 'offsetAccess.notFound',
Expand Down Expand Up @@ -2203,30 +2275,6 @@
'count' => 1,
'path' => __DIR__ . '/../../src/RuleSet/RuleSet.php',
];
$ignoreErrors[] = [
'message' => '#^Call to an undefined method object\\:\\:getName\\(\\)\\.$#',
'identifier' => 'method.notFound',
'count' => 1,
'path' => __DIR__ . '/../../src/RuleSet/RuleSets.php',
];
$ignoreErrors[] = [
'message' => '#^Method PhpCsFixer\\\\RuleSet\\\\RuleSets\\:\\:getSetDefinitions\\(\\) should return array\\<string, PhpCsFixer\\\\RuleSet\\\\RuleSetDescriptionInterface\\> but returns array\\<int\\|string, object\\>\\.$#',
'identifier' => 'return.type',
'count' => 1,
'path' => __DIR__ . '/../../src/RuleSet/RuleSets.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#2 \\$callback of function uksort expects callable\\(int\\|string, int\\|string\\)\\: int, Closure\\(string, string\\)\\: int\\<\\-1, 1\\> given\\.$#',
'identifier' => 'argument.type',
'count' => 1,
'path' => __DIR__ . '/../../src/RuleSet/RuleSets.php',
];
$ignoreErrors[] = [
'message' => '#^Static property PhpCsFixer\\\\RuleSet\\\\RuleSets\\:\\:\\$setDefinitions \\(array\\<string, PhpCsFixer\\\\RuleSet\\\\RuleSetDescriptionInterface\\>\\) does not accept array\\<int\\|string, object\\>\\.$#',
'identifier' => 'assign.propertyType',
'count' => 1,
'path' => __DIR__ . '/../../src/RuleSet/RuleSets.php',
];
$ignoreErrors[] = [
'message' => '#^Offset \'action\' might not exist on array\\.$#',
'identifier' => 'offsetAccess.notFound',
Expand Down
9 changes: 9 additions & 0 deletions doc/rules/function_notation/phpdoc_to_param_type.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ actions are required if inherited signatures are not properly documented.
Configuration
-------------

``map_types``
~~~~~~~~~~~~~

Map of custom types, eg template types from PHPStan.

Allowed types: ``array<string, string>``

Default value: ``[]``

``scalar_types``
~~~~~~~~~~~~~~~~

Expand Down
9 changes: 9 additions & 0 deletions doc/rules/function_notation/phpdoc_to_property_type.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ be required for newly typed properties that are read before initialization.
Configuration
-------------

``map_types``
~~~~~~~~~~~~~

Map of custom types, eg template types from PHPStan.

Allowed types: ``array<string, string>``

Default value: ``[]``

``scalar_types``
~~~~~~~~~~~~~~~~

Expand Down
9 changes: 9 additions & 0 deletions doc/rules/function_notation/phpdoc_to_return_type.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ Manual actions are required if inherited signatures are not properly documented.
Configuration
-------------

``map_types``
~~~~~~~~~~~~~

Map of custom types, eg template types from PHPStan.

Allowed types: ``array<string, string>``

Default value: ``[]``

``scalar_types``
~~~~~~~~~~~~~~~~

Expand Down
6 changes: 2 additions & 4 deletions src/AbstractDoctrineAnnotationFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@
* @internal
*
* @phpstan-type _AutogeneratedInputConfiguration array{
* scalar_types?: bool,
* union_types?: bool
* ignored_tags?: list<string>
* }
* @phpstan-type _AutogeneratedComputedConfiguration array{
* scalar_types: bool,
* union_types: bool
* ignored_tags: list<string>
* }
*
* @implements ConfigurableFixerInterface<_AutogeneratedInputConfiguration, _AutogeneratedComputedConfiguration>
Expand Down
10 changes: 10 additions & 0 deletions src/AbstractPhpdocToTypeDeclarationFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@
*
* @phpstan-type _CommonTypeInfo array{commonType: string, isNullable: bool}
* @phpstan-type _AutogeneratedInputConfiguration array{
* map_types?: array<string, string>,
* scalar_types?: bool,
* union_types?: bool
* }
* @phpstan-type _AutogeneratedComputedConfiguration array{
* map_types: array<string, string>,
* scalar_types: bool,
* union_types: bool
* }
Expand Down Expand Up @@ -95,6 +97,10 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn
->setAllowedTypes(['bool'])
->setDefault(\PHP_VERSION_ID >= 8_00_00)
->getOption(),
(new FixerOptionBuilder('map_types', 'Map of custom types, eg template types from PHPStan.'))
->setAllowedTypes(['array<string, string>'])
->setDefault([])
->getOption(),
]);
}

Expand Down Expand Up @@ -213,6 +219,10 @@ protected function getCommonTypeInfo(TypeExpression $typesExpression, bool $isRe
return null;
}

if (\array_key_exists($commonType, $this->configuration['map_types'])) {
$commonType = $this->configuration['map_types'][$commonType];
}

if (isset($this->scalarTypes[$commonType])) {
if (false === $this->configuration['scalar_types']) {
return null;
Expand Down
2 changes: 0 additions & 2 deletions src/Console/Command/CheckCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@
#[AsCommand(name: 'check', description: 'Checks if configured files/directories comply with configured rules.')]
final class CheckCommand extends FixCommand
{
/** @var string */
protected static $defaultName = 'check';

/** @var string */
protected static $defaultDescription = 'Checks if configured files/directories comply with configured rules.';

public function __construct(ToolInfoInterface $toolInfo)
Expand Down
3 changes: 1 addition & 2 deletions src/Console/Command/DescribeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
#[AsCommand(name: 'describe')]
final class DescribeCommand extends Command
{
/** @var string */
protected static $defaultName = 'describe';

/**
Expand All @@ -67,7 +66,7 @@ final class DescribeCommand extends Command
private FixerFactory $fixerFactory;

/**
* @var array<string, FixerInterface>
* @var null|array<string, FixerInterface>
*/
private $fixers;

Expand Down
1 change: 0 additions & 1 deletion src/Console/Command/DocumentationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#[AsCommand(name: 'documentation')]
final class DocumentationCommand extends Command
{
/** @var string */
protected static $defaultName = 'documentation';

private Filesystem $filesystem;
Expand Down
2 changes: 0 additions & 2 deletions src/Console/Command/FixCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,8 @@
#[AsCommand(name: 'fix', description: 'Fixes a directory or a file.')]
/* final */ class FixCommand extends Command
{
/** @var string */
protected static $defaultName = 'fix';

/** @var string */
protected static $defaultDescription = 'Fixes a directory or a file.';

private EventDispatcherInterface $eventDispatcher;
Expand Down
1 change: 0 additions & 1 deletion src/Console/Command/HelpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#[AsCommand(name: 'help')]
final class HelpCommand extends BaseHelpCommand
{
/** @var string */
protected static $defaultName = 'help';

/**
Expand Down
1 change: 0 additions & 1 deletion src/Console/Command/ListFilesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#[AsCommand(name: 'list-files')]
final class ListFilesCommand extends Command
{
/** @var string */
protected static $defaultName = 'list-files';

private ConfigInterface $defaultConfig;
Expand Down
1 change: 0 additions & 1 deletion src/Console/Command/ListSetsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#[AsCommand(name: 'list-sets')]
final class ListSetsCommand extends Command
{
/** @var string */
protected static $defaultName = 'list-sets';

protected function configure(): void
Expand Down
1 change: 0 additions & 1 deletion src/Console/Command/SelfUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#[AsCommand(name: 'self-update')]
final class SelfUpdateCommand extends Command
{
/** @var string */
protected static $defaultName = 'self-update';

private NewVersionCheckerInterface $versionChecker;
Expand Down
Loading

0 comments on commit 41fdc44

Please sign in to comment.