Skip to content

Commit

Permalink
PHPStan updated and static fixes (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Jun 10, 2021
1 parent 7bd6b3a commit 1a3afef
Show file tree
Hide file tree
Showing 37 changed files with 512 additions and 612 deletions.
14 changes: 7 additions & 7 deletions build/target-repository/docs/rector_rules_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,18 @@ Replaces defined map of arguments in defined methods and their calls.
- class: [`Rector\Arguments\Rector\ClassMethod\ArgumentDefaultValueReplacerRector`](../rules/Arguments/Rector/ClassMethod/ArgumentDefaultValueReplacerRector.php)

```php
use Rector\Arguments\Rector\ClassMethod\ArgumentDefaultValueReplacerRector;
use Rector\Arguments\ValueObject\ArgumentDefaultValueReplacer;
use Rector\Arguments\Rector\ClassMethod\ReplaceArgumentDefaultValueRector;
use Rector\Arguments\ValueObject\ReplaceArgumentDefaultValue;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;

return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();

$services->set(ArgumentDefaultValueReplacerRector::class)
$services->set(ReplaceArgumentDefaultValueRector::class)
->call('configure', [[
ArgumentDefaultValueReplacerRector::REPLACED_ARGUMENTS => ValueObjectInliner::inline([
new ArgumentDefaultValueReplacer('SomeExampleClass', 'someMethod', 0, 'SomeClass::OLD_CONSTANT', false),
ReplaceArgumentDefaultValueRector::REPLACED_ARGUMENTS => ValueObjectInliner::inline([
new ReplaceArgumentDefaultValue('SomeExampleClass', 'someMethod', 0, 'SomeClass::OLD_CONSTANT', false),
]),
]]);
};
Expand All @@ -218,7 +218,7 @@ Streamline the operator arguments of version_compare function

```php
use Rector\Arguments\Rector\FuncCall\FunctionArgumentDefaultValueReplacerRector;
use Rector\Arguments\ValueObject\FuncCallArgumentDefaultValueReplacer;
use Rector\Arguments\ValueObject\ReplaceFuncCallArgumentDefaultValue;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;

Expand All @@ -228,7 +228,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(FunctionArgumentDefaultValueReplacerRector::class)
->call('configure', [[
FunctionArgumentDefaultValueReplacerRector::REPLACED_ARGUMENTS => ValueObjectInliner::inline([
new FuncCallArgumentDefaultValueReplacer('version_compare', 2, 'gte', 'ge'),
new ReplaceFuncCallArgumentDefaultValue('version_compare', 2, 'gte', 'ge'),
]),
]]);
};
Expand Down
36 changes: 18 additions & 18 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"nette/utils": "^3.2",
"nikic/php-parser": "4.10.5",
"phpstan/phpdoc-parser": "^0.5.4",
"phpstan/phpstan": ">=0.12.86 <=0.12.88",
"phpstan/phpstan": ">=0.12.86 <=0.12.89",
"phpstan/phpstan-phpunit": "^0.12.19",
"rector/extension-installer": "^0.10.2",
"rector/rector-cakephp": "^0.11.2",
Expand All @@ -38,16 +38,16 @@
"symfony/http-kernel": "^5.3",
"symfony/process": "^5.3",
"symfony/yaml": "^5.3",
"symplify/astral": "^9.3.15",
"symplify/autowire-array-parameter": "^9.3.15",
"symplify/composer-json-manipulator": "^9.3.15",
"symplify/console-color-diff": "^9.3.15",
"symplify/package-builder": "^9.3.15",
"symplify/rule-doc-generator-contracts": "^9.3.15",
"symplify/simple-php-doc-parser": "^9.3.15",
"symplify/skipper": "^9.3.15",
"symplify/smart-file-system": "^9.3.10",
"symplify/symfony-php-config": "^9.3.10",
"symplify/astral": "^9.3.22",
"symplify/autowire-array-parameter": "^9.3.22",
"symplify/composer-json-manipulator": "^9.3.22",
"symplify/console-color-diff": "^9.3.22",
"symplify/package-builder": "^9.3.22",
"symplify/rule-doc-generator-contracts": "^9.3.22",
"symplify/simple-php-doc-parser": "^9.3.22",
"symplify/skipper": "^9.3.22",
"symplify/smart-file-system": "^9.3.22",
"symplify/symfony-php-config": "^9.3.22",
"tracy/tracy": "^2.8",
"webmozart/assert": "^1.10"
},
Expand All @@ -57,13 +57,13 @@
"phpunit/phpunit": "^9.5",
"rector/rector-generator": "^0.1.7",
"rector/phpstan-rules": "^0.3",
"symplify/coding-standard": "^9.3.15",
"symplify/easy-ci": "^9.3.15",
"symplify/easy-coding-standard": "^9.3.15",
"symplify/easy-testing": "^9.3.15",
"symplify/phpstan-extensions": "^9.3.15",
"symplify/phpstan-rules": "^9.3.15",
"symplify/rule-doc-generator": "^9.3.15"
"symplify/coding-standard": "^9.3.22",
"symplify/easy-ci": "^9.3.22",
"symplify/easy-coding-standard": "^9.3.22",
"symplify/easy-testing": "^9.3.22",
"symplify/phpstan-extensions": "^9.3.22",
"symplify/phpstan-rules": "^9.3.22",
"symplify/rule-doc-generator": "^9.3.22"
},
"replace": {
"rector/rector": "self.version"
Expand Down
20 changes: 10 additions & 10 deletions config/set/php80.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Rector\Arguments\Rector\ClassMethod\ArgumentAdderRector;
use Rector\Arguments\Rector\FuncCall\FunctionArgumentDefaultValueReplacerRector;
use Rector\Arguments\ValueObject\ArgumentAdder;
use Rector\Arguments\ValueObject\FuncCallArgumentDefaultValueReplacer;
use Rector\Arguments\ValueObject\ReplaceFuncCallArgumentDefaultValue;
use Rector\DeadCode\Rector\StaticCall\RemoveParentCallWithoutParentRector;
use Rector\Php80\Rector\Catch_\RemoveUnusedVariableInCatchRector;
use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;
Expand Down Expand Up @@ -97,15 +97,15 @@
$services->set(Rector\Arguments\Rector\FuncCall\FunctionArgumentDefaultValueReplacerRector::class)
->call('configure', [[
FunctionArgumentDefaultValueReplacerRector::REPLACED_ARGUMENTS => ValueObjectInliner::inline([
new FuncCallArgumentDefaultValueReplacer('version_compare', 2, 'gte', 'ge'),
new FuncCallArgumentDefaultValueReplacer('version_compare', 2, 'lte', 'le'),
new FuncCallArgumentDefaultValueReplacer('version_compare', 2, '', '!='),
new FuncCallArgumentDefaultValueReplacer('version_compare', 2, '!', '!='),
new FuncCallArgumentDefaultValueReplacer('version_compare', 2, 'g', 'gt'),
new FuncCallArgumentDefaultValueReplacer('version_compare', 2, 'l', 'lt'),
new FuncCallArgumentDefaultValueReplacer('version_compare', 2, 'gte', 'ge'),
new FuncCallArgumentDefaultValueReplacer('version_compare', 2, 'lte', 'le'),
new FuncCallArgumentDefaultValueReplacer('version_compare', 2, 'n', 'ne'),
new ReplaceFuncCallArgumentDefaultValue('version_compare', 2, 'gte', 'ge'),
new ReplaceFuncCallArgumentDefaultValue('version_compare', 2, 'lte', 'le'),
new ReplaceFuncCallArgumentDefaultValue('version_compare', 2, '', '!='),
new ReplaceFuncCallArgumentDefaultValue('version_compare', 2, '!', '!='),
new ReplaceFuncCallArgumentDefaultValue('version_compare', 2, 'g', 'gt'),
new ReplaceFuncCallArgumentDefaultValue('version_compare', 2, 'l', 'lt'),
new ReplaceFuncCallArgumentDefaultValue('version_compare', 2, 'gte', 'ge'),
new ReplaceFuncCallArgumentDefaultValue('version_compare', 2, 'lte', 'le'),
new ReplaceFuncCallArgumentDefaultValue('version_compare', 2, 'n', 'ne'),
]),
]]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Rector\PhpAttribute\Printer\PhpAttributeGroupFactory;
use Rector\Testing\PHPUnit\AbstractTestCase;

class PhpAttributeGroupFactoryTest extends AbstractTestCase
final class PhpAttributeGroupFactoryTest extends AbstractTestCase
{
private PhpAttributeGroupFactory $phpAttributeGroupFactory;

Expand All @@ -24,20 +24,23 @@ public function testCreateFromClassWithItems(): void
{
$attributeGroup = $this->phpAttributeGroupFactory->createFromClassWithItems(
'Symfony\Component\Routing\Annotation\Route',
['path' => '/path', 'name' => 'action']
[
'path' => '/path',
'name' => 'action',
]
);

self::assertInstanceOf(AttributeGroup::class, $attributeGroup);
$this->assertInstanceOf(AttributeGroup::class, $attributeGroup);
}

public function testCreateArgsFromItems(): void
{
$method = new \ReflectionMethod($this->phpAttributeGroupFactory, 'createArgsFromItems');
$method->setAccessible(true);
$args = $method->invokeArgs($this->phpAttributeGroupFactory, [['path' => '/path', 'name' => 'action']]);
$args = $this->phpAttributeGroupFactory->createArgsFromItems([
'path' => '/path',
'name' => 'action',
]);

self::assertIsArray($args);
self::assertCount(2, $args);
self::assertContainsOnlyInstancesOf(Arg::class, $args);
$this->assertCount(2, $args);
$this->assertContainsOnlyInstancesOf(Arg::class, $args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Rector\Core\Contract\Console\OutputStyleInterface;
use Rector\ListReporting\Contract\Output\ShowOutputFormatterInterface;

final class ConsoleOutputFormatter implements ShowOutputFormatterInterface
final class ConsoleShowOutputFormatter implements ShowOutputFormatterInterface
{
/**
* @var string
Expand Down
2 changes: 1 addition & 1 deletion packages/PhpAttribute/Printer/PhpAttributeGroupFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function create(
* @param mixed[] $items
* @return Arg[]
*/
private function createArgsFromItems(array $items, ?string $silentKey = null): array
public function createArgsFromItems(array $items, ?string $silentKey = null): array
{
$args = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use PhpParser\Node\Stmt\Return_;
use Rector\NodeTypeResolver\Node\AttributeKey;

final class ReadExprAnalyzer
final class JustReadExprAnalyzer
{
public function isReadContext(Expr $expr): bool
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
final class PropertyFetchReadNodeAnalyzer implements ReadNodeAnalyzerInterface
{
public function __construct(
private ReadExprAnalyzer $readExprAnalyzer,
private JustReadExprAnalyzer $justReadExprAnalyzer,
private NodeUsageFinder $nodeUsageFinder
) {
}
Expand All @@ -29,7 +29,7 @@ public function isRead(Node $node): bool
{
$propertyFetchUsages = $this->nodeUsageFinder->findPropertyFetchUsages($node);
foreach ($propertyFetchUsages as $propertyFetchUsage) {
if ($this->readExprAnalyzer->isReadContext($propertyFetchUsage)) {
if ($this->justReadExprAnalyzer->isReadContext($propertyFetchUsage)) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class VariableReadNodeAnalyzer implements ReadNodeAnalyzerInterface
public function __construct(
private ParentScopeFinder $parentScopeFinder,
private NodeUsageFinder $nodeUsageFinder,
private ReadExprAnalyzer $readExprAnalyzer
private JustReadExprAnalyzer $justReadExprAnalyzer
) {
}

Expand All @@ -36,7 +36,7 @@ public function isRead(Node $node): bool

$variableUsages = $this->nodeUsageFinder->findVariableUsages((array) $parentScope->stmts, $node);
foreach ($variableUsages as $variableUsage) {
if ($this->readExprAnalyzer->isReadContext($variableUsage)) {
if ($this->justReadExprAnalyzer->isReadContext($variableUsage)) {
return true;
}
}
Expand Down
24 changes: 0 additions & 24 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ parameters:
paths:
- rules/Renaming/Rector/FileWithoutNamespace/PseudoNamespaceToNamespaceRector.php
- rules/CodeQuality/Rector/Concat/JoinStringConcatRector.php
- rules/Php80/Rector/Switch_/ChangeSwitchToMatchRector.php
- packages/NodeNestingScope/NodeFinder/ScopeAwareNodeFinder.php

-
Expand Down Expand Up @@ -309,11 +308,6 @@ parameters:
- '#Parameter \#1 \$stmts of method Rector\\EarlyReturn\\Rector\\Return_\\PreparedValueToEarlyReturnRector\:\:collectIfs\(\) expects array<PhpParser\\Node\\Stmt\\If_\>, array<PhpParser\\Node\\Stmt\> given#'
- '#Access to an undefined property PhpParser\\Node\\FunctionLike\|PhpParser\\Node\\Stmt\\If_\:\:\$stmts#'

-
message: '#Function "get_declared_classes\(\)" cannot be used/left in the code#'
paths:
- rules/Restoration/ClassMap/ExistingClassesProvider.php

-
message: '#Parameter \#1 \$types of method Rector\\Defluent\\NodeAnalyzer\\FluentCallStaticTypeResolver\:\:filterOutAlreadyPresentParentClasses\(\) expects array<class\-string\>, array<int, string\> given#'
paths:
Expand All @@ -332,8 +326,6 @@ parameters:
paths:
- src/Console/Command/ProcessCommand.php

- '#Parameter \#2 \$returnedStrictTypeNode of method Rector\\TypeDeclaration\\Rector\\ClassMethod\\ReturnTypeFromStrictTypedCallRector\:\:refactorSingleReturnType\(\) expects PhpParser\\Node\\Name\|PhpParser\\Node\\NullableType\|PhpParser\\Node\\UnionType, PhpParser\\Node\\Name\|PhpParser\\Node\\NullableType\|PHPStan\\Type\\UnionType given#'

- '#(.*?) class\-string, string given#'

# part of refactor() API, node must be returned, or does bring any value
Expand All @@ -342,11 +334,6 @@ parameters:
paths:
- '*Rector.php'

-
message: '#Cannot cast array<string\>\|string\|null to string#'
paths:
- utils/compiler/src/Command/DowngradePathsCommand.php

# PHP 7_4 literal syntax
- '#Property PhpParser\\Node\\Scalar\\DNumber\:\:\$value \(float\|int\) does not accept string#'

Expand Down Expand Up @@ -414,21 +401,13 @@ parameters:

- '#Method Rector\\Core\\PhpParser\\Node\\BetterNodeFinder\:\:findParentTypes\(\) should return T of PhpParser\\Node\|null but returns class\-string<T of PhpParser\\Node\>\|T of PhpParser\\Node#'

-
message: '#Assign in loop is not allowed#'
paths:
- rules/DowngradePhp72/NodeAnalyzer/ParamContravariantDetector.php

# doc typo in php-parser
- '#Parameter \#2 \$args of class PhpParser\\Node\\Expr\\FuncCall constructor expects array<PhpParser\\Node\\Arg\>, array<int, PhpParser\\Node\\Arg\|null\> given#'

- '#Class with base "(.*?)" name is already used in "Symplify\\(.*?)", "Rector\\(.*?)"\. Use unique name to make classes easy to recognize#'

# php-parser bug
- '#Parameter \#1 \$type of method PhpParser\\Builder\\FunctionLike\:\:setReturnType\(\) expects PhpParser\\Node\\Name\|PhpParser\\Node\\NullableType\|string, PhpParser\\Node\\Name\|PhpParser\\Node\\NullableType\|PhpParser\\Node\\UnionType given#'

- '#Method Rector\\Core\\Tests\\DependencyInjection\\ConfigurableRectorImportConfigCallsMergeTest\:\:provideData\(\) return type has no value type specified in iterable type Iterator#'
- '#Class with base "PhpVersion" name is already used in "PHPStan\\Php\\PhpVersion", "Rector\\Core\\ValueObject\\PhpVersion"\. Use unique name to make classes easy to recognize#'

-
message: '#Use separate function calls with readable variable names#'
Expand All @@ -446,8 +425,6 @@ parameters:
paths:
- rules/EarlyReturn/Rector/If_/ChangeAndIfToEarlyReturnRector.php

- '#Class with base "PhpVersionFactory" name is already used in "PHPStan\\Php\\PhpVersionFactory", "Rector\\Core\\Util\\PhpVersionFactory"\. Use unique name to make classes easy to recognize#'

-
message: '#Function "function_exists\(\)" cannot be used/left in the code#'
paths:
Expand All @@ -466,7 +443,6 @@ parameters:
- '#Method Rector\\BetterPhpDocParser\\PhpDocParser\\BetterPhpDocParser\:\:parseChildAndStoreItsPositions\(\) should return PHPStan\\PhpDocParser\\Ast\\PhpDoc\\PhpDocTagNode\|PHPStan\\PhpDocParser\\Ast\\PhpDoc\\PhpDocTextNode but returns PHPStan\\PhpDocParser\\Ast\\PhpDoc\\PhpDocChildNode#'


- '#Method Rector\\Core\\Application\\VersionResolver\:\:resolvePackageData\(\) return type has no value type specified in iterable type array#'
- '#Cognitive complexity for "Rector\\Core\\Rector\\AbstractRector\:\:enterNode\(\)" is \d+, keep it under 9#'

-
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Rector\Tests\Arguments\Rector\ClassMethod\ArgumentDefaultValueReplacerRector\Fixture;
namespace Rector\Tests\Arguments\Rector\ClassMethod\ReplaceArgumentDefaultValueRector\Fixture;

use Symfony\Component\DependencyInjection\ContainerBuilder;

Expand All @@ -15,7 +15,7 @@ function argumentDefalutValue()
-----
<?php

namespace Rector\Tests\Arguments\Rector\ClassMethod\ArgumentDefaultValueReplacerRector\Fixture;
namespace Rector\Tests\Arguments\Rector\ClassMethod\ReplaceArgumentDefaultValueRector\Fixture;

use Symfony\Component\DependencyInjection\ContainerBuilder;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Rector\Tests\Arguments\Rector\ClassMethod\ArgumentDefaultValueReplacerRector\Fixture;
namespace Rector\Tests\Arguments\Rector\ClassMethod\ReplaceArgumentDefaultValueRector\Fixture;

use Symfony\Component\Yaml\Yaml;

Expand All @@ -16,7 +16,7 @@ function argumentDefaultValue2()
-----
<?php

namespace Rector\Tests\Arguments\Rector\ClassMethod\ArgumentDefaultValueReplacerRector\Fixture;
namespace Rector\Tests\Arguments\Rector\ClassMethod\ReplaceArgumentDefaultValueRector\Fixture;

use Symfony\Component\Yaml\Yaml;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Rector\Tests\Arguments\Rector\ClassMethod\ArgumentDefaultValueReplacerRector\Fixture;
namespace Rector\Tests\Arguments\Rector\ClassMethod\ReplaceArgumentDefaultValueRector\Fixture;

use Symfony\Component\Yaml\Yaml;

Expand All @@ -15,7 +15,7 @@ function argumentDefaultValue3()
-----
<?php

namespace Rector\Tests\Arguments\Rector\ClassMethod\ArgumentDefaultValueReplacerRector\Fixture;
namespace Rector\Tests\Arguments\Rector\ClassMethod\ReplaceArgumentDefaultValueRector\Fixture;

use Symfony\Component\Yaml\Yaml;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

declare(strict_types=1);

namespace Rector\Tests\Arguments\Rector\ClassMethod\ArgumentDefaultValueReplacerRector;
namespace Rector\Tests\Arguments\Rector\ClassMethod\ReplaceArgumentDefaultValueRector;

use Iterator;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;

final class ArgumentDefaultValueReplacerRectorTest extends AbstractRectorTestCase
final class ReplaceArgumentDefaultValueRectorTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
Expand Down

0 comments on commit 1a3afef

Please sign in to comment.