Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/phpstan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v1
with:
php-version: 7.3
php-version: 7.4
coverage: none
tools: cs2pr
- run: composer install --no-progress
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/validate_services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ jobs:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v1
with:
php-version: 7.2
coverage: none # disable xdebug, pcov
php-version: 7.4
coverage: none

- run: composer install --no-progress
- run: bin/rector validate-services-in-sets --ansi
10 changes: 3 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"nikic/php-parser": "4.3.*",
"ondram/ci-detector": "^3.1",
"phpstan/phpdoc-parser": "^0.4",
"phpstan/phpstan": "^0.12.11",
"phpstan/phpstan": "0.12.18",
"phpstan/phpstan-phpunit": "^0.12",
"sebastian/diff": "^3.0|^4.0",
"symfony/console": "^4.4.6|^5.0.6",
Expand Down Expand Up @@ -202,10 +202,7 @@
"Rector\\ZendToSymfony\\Tests\\": "rules/zend-to-symfony/tests"
},
"classmap": [
"packages/node-type-resolver/tests/PerNodeTypeResolver/ParamTypeResolver/Source",
"packages/node-type-resolver/tests/PerNodeTypeResolver/PropertyTypeResolver/Source",
"rules/cakephp/tests/Rector/Name/ImplicitShortClassNameUseStatementRector/Source",
"rules/symfony/tests/Rector/FrameworkBundle/AbstractToConstructorInjectionRectorSource",
"rules/symfony/tests/Rector/FrameworkBundle/ContainerGetToConstructorInjectionRector/Source",
"rules/autodiscovery/tests/Rector/FileSystem/MoveInterfacesToContractNamespaceDirectoryRector/Expected",
"rules/autodiscovery/tests/Rector/FileSystem/MoveServicesBySuffixToDirectoryRector/Expected",
Expand All @@ -218,7 +215,6 @@
"tests/Issues/Issue1243/Source"
],
"files": [
"packages/better-php-doc-parser/tests/PhpDocInfo/PhpDocInfoPrinter/AbstractPhpDocInfoPrinterTest.php",
"rules/coding-style/tests/Rector/Throw_/AnnotateThrowablesRector/Source/i_throw_an_exception.func.php",
"rules/dead-code/tests/Rector/MethodCall/RemoveDefaultArgumentValueRector/Source/UserDefined.php",
"rules/type-declaration/tests/Rector/Property/CompleteVarDocTypePropertyRector/Source/EventDispatcher.php",
Expand All @@ -228,12 +224,12 @@
"rules/renaming/tests/Rector/Class_/RenameClassRector/Source/Twig_Extension_Sandbox.php",
"rules/renaming/tests/Rector/Class_/RenameClassRector/Source/TwigFilter.php",
"rules/renaming/tests/Rector/Class_/RenameClassRector/Source/Manual_Twig_Filter.php",
"rules/solid/tests/Rector/ClassMethod/UseInterfaceOverImplementationInConstructorRector/Source/Apple.php",
"tests/Rector/Namespace_/PseudoNamespaceToNamespaceRector/Source/ChangeMeAnotherNamespace.php",
"rules/coding-style/tests/Rector/Namespace_/ImportFullyQualifiedNamesRector/Source/Foo.php",
"rules/coding-style/tests/Rector/Namespace_/ImportFullyQualifiedNamesRector/Source/Function_/count.php",
"rules/coding-style/tests/Rector/Namespace_/ImportFullyQualifiedNamesRector/Source/AnotherClass.php",
"rules/coding-style/tests/Rector/Namespace_/ImportFullyQualifiedNamesRector/Source/YetAnotherClass.php"
"rules/coding-style/tests/Rector/Namespace_/ImportFullyQualifiedNamesRector/Source/YetAnotherClass.php",
"rules/solid/tests/Rector/ClassMethod/UseInterfaceOverImplementationInConstructorRector/Source/Coconut.php"
]
},
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Nette\Utils\Strings;
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprIntegerNode;
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprStringNode;
use PHPStan\PhpDocParser\Ast\Type\ArrayShapeItemNode;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
Expand All @@ -22,7 +23,7 @@ final class AttributeAwareArrayShapeItemNode extends ArrayShapeItemNode implemen
private $hasSpaceAfterDoubleColon = false;

/**
* @param ConstExprIntegerNode|IdentifierTypeNode|null $keyName
* @param ConstExprIntegerNode|ConstExprStringNode|IdentifierTypeNode|null $keyName
*/
public function __construct($keyName, bool $optional, TypeNode $typeNode, string $docComment = '')
{
Expand Down
4 changes: 2 additions & 2 deletions packages/file-system-rector/src/Parser/FileInfoParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function parseFileInfoToNodesAndDecorate(SmartFileInfo $fileInfo): array
{
$oldStmts = $this->parser->parseFile($fileInfo->getRealPath());

return $this->nodeScopeAndMetadataDecorator->decorateNodesFromFile($oldStmts, $fileInfo->getRealPath());
return $this->nodeScopeAndMetadataDecorator->decorateNodesFromFile($oldStmts, $fileInfo);
}

/**
Expand All @@ -44,6 +44,6 @@ public function parseFileInfoToNodesAndDecorateWithScope(SmartFileInfo $fileInfo
{
$oldStmts = $this->parser->parseFile($fileInfo->getRealPath());

return $this->nodeScopeAndMetadataDecorator->decorateNodesFromFile($oldStmts, $fileInfo->getRealPath(), true);
return $this->nodeScopeAndMetadataDecorator->decorateNodesFromFile($oldStmts, $fileInfo, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,7 @@ protected function parseFileInfoToNodes(SmartFileInfo $smartFileInfo): array
$oldStmts = $this->parser->parseFile($smartFileInfo->getRealPath());
// needed for format preserving
$this->oldStmts = $oldStmts;
return $this->nodeScopeAndMetadataDecorator->decorateNodesFromFile(
$oldStmts,
$smartFileInfo->getRealPath()
);
return $this->nodeScopeAndMetadataDecorator->decorateNodesFromFile($oldStmts, $smartFileInfo);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Rector\NodeTypeResolver\NodeVisitor\PhpDocInfoNodeVisitor;
use Rector\NodeTypeResolver\NodeVisitor\StatementNodeVisitor;
use Rector\NodeTypeResolver\PHPStan\Scope\NodeScopeResolver;
use Symplify\SmartFileSystem\SmartFileInfo;

final class NodeScopeAndMetadataDecorator
{
Expand Down Expand Up @@ -106,18 +107,19 @@ public function __construct(
* @param Node[] $nodes
* @return Node[]
*/
public function decorateNodesFromFile(array $nodes, string $filePath, bool $needsScope = false): array
public function decorateNodesFromFile(array $nodes, SmartFileInfo $fileInfo, bool $needsScope = false): array
{
$nodeTraverser = new NodeTraverser();
$nodeTraverser->addVisitor(new NameResolver(null, [
'preserveOriginalNames' => true,
'replaceNodes' => true, // required by PHPStan
// required by PHPStan
'replaceNodes' => true,
]));
$nodes = $nodeTraverser->traverse($nodes);

// node scoping is needed only for Scope
if ($needsScope || $this->configuration->areAnyPhpRectorsLoaded()) {
$nodes = $this->nodeScopeResolver->processNodes($nodes, $filePath);
$nodes = $this->nodeScopeResolver->processNodes($nodes, $fileInfo);
}

$nodeTraverser = new NodeTraverser();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\NodeTypeResolver\PHPStan\Collector\TraitNodeScopeCollector;
use Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor\RemoveDeepChainMethodCallNodeVisitor;
use Symplify\SmartFileSystem\SmartFileInfo;

/**
* @inspired by https://github.com/silverstripe/silverstripe-upgrader/blob/532182b23e854d02e0b27e68ebc394f436de0682/src/UpgradeRule/PHP/Visitor/PHPStanScopeVisitor.php
Expand Down Expand Up @@ -69,11 +70,11 @@ public function __construct(
* @param Node[] $nodes
* @return Node[]
*/
public function processNodes(array $nodes, string $filePath): array
public function processNodes(array $nodes, SmartFileInfo $smartFileInfo): array
{
$this->removeDeepChainMethodCallNodes($nodes);

$scope = $this->scopeFactory->createFromFile($filePath);
$scope = $this->scopeFactory->createFromFile($smartFileInfo);

// skip chain method calls, performance issue: https://github.com/phpstan/phpstan/issues/254
$nodeCallback = function (Node $node, MutatingScope $scope): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Properties\PropertyReflectionFinder;
use Rector\Core\PhpParser\Printer\BetterStandardPrinter;
use Symplify\SmartFileSystem\SmartFileInfo;

final class ScopeFactory
{
Expand Down Expand Up @@ -63,7 +64,7 @@ public function __construct(
$this->operatorTypeSpecifyingExtensionRegistryProvider = $operatorTypeSpecifyingExtensionRegistryProvider;
}

public function createFromFile(string $filePath): Scope
public function createFromFile(SmartFileInfo $fileInfo): Scope
{
return new MutatingScope(
$this->phpStanScopeFactory,
Expand All @@ -73,7 +74,7 @@ public function createFromFile(string $filePath): Scope
$this->betterStandardPrinter,
$this->typeSpecifier,
new PropertyReflectionFinder(),
ScopeContext::create($filePath)
ScopeContext::create($fileInfo->getRealPath())
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ private function getNodesForFile(string $file): array

$nodes = $this->parser->parseFile($smartFileInfo->getRealPath());

return $this->nodeScopeAndMetadataDecorator->decorateNodesFromFile($nodes, $smartFileInfo->getRealPath());
return $this->nodeScopeAndMetadataDecorator->decorateNodesFromFile($nodes, $smartFileInfo);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ public function test(string $file, int $nodePosition, Type $expectedType): void

public function provideData(): Iterator
{
yield [__DIR__ . '/Source/ClassWithProperties.php', 0, new ObjectType(Html::class)];
yield [__DIR__ . '/Source/MethodParamDocBlock.php', 0, new ObjectType(Html::class)];

yield [
__DIR__ . '/Source/ClassWithProperties.php',
__DIR__ . '/Source/MethodParamDocBlock.php',
1,
TypeFactoryStaticHelper::createUnionObjectType([ClassThatExtendsHtml::class, Html::class]),
];

// mimics failing test from DomainDrivenDesign set
$unionType = TypeFactoryStaticHelper::createUnionObjectType([SomeChild::class, new NullType()]);
yield [__DIR__ . '/Source/fixture.php', 0, $unionType];
yield [__DIR__ . '/Source/ActionClass.php', 0, $unionType];
}

private function getStringFromType(Type $type): string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php

namespace Rector\DomainDrivenDesign\Tests\Rector\ObjectToScalarDocBlockRector;

use Rector\NodeTypeResolver\Tests\PerNodeTypeResolver\PropertyTypeResolver\Source\SomeChild;
namespace Rector\NodeTypeResolver\Tests\PerNodeTypeResolver\PropertyTypeResolver\Source;

class ActionClass
{
Expand Down
2 changes: 2 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,5 @@ parameters:
- '#Method Rector\\DeadCode\\NodeFinder\\PreviousVariableAssignNodeFinder\:\:find\(\) should return PhpParser\\Node\\Expr\\Assign\|null but returns PhpParser\\Node\|null#'
- '#Parameter \#2 \$name of method Rector\\NodeNameResolver\\NodeNameResolver\:\:isName\(\) expects string, string\|null given#'
- '#Method Rector\\PHPOffice\\Rector\\MethodCall\\IncreaseColumnIndexRector\:\:findVariableAssignName\(\) should return PhpParser\\Node\\Expr\\Assign\|null but returns PhpParser\\Node\|null#'

- '#Parameter \#1 \$keyName of method Rector\\AttributeAwarePhpDoc\\Ast\\Type\\AttributeAwareArrayShapeItemNode\:\:createKeyWithSpacePattern\(\) expects PHPStan\\PhpDocParser\\Ast\\ConstExpr\\ConstExprIntegerNode\|PHPStan\\PhpDocParser\\Ast\\Type\\IdentifierTypeNode\|null, PHPStan\\PhpDocParser\\Ast\\ConstExpr\\ConstExprIntegerNode\|PHPStan\\PhpDocParser\\Ast\\ConstExpr\\ConstExprStringNode\|PHPStan\\PhpDocParser\\Ast\\Type\\IdentifierTypeNode\|null given#'
4 changes: 0 additions & 4 deletions rector.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
services:
Rector\DeadCode\Rector\ClassMethod\RemoveDeadRecursiveClassMethodRector: null
# Rector\Privatization\Rector\MethodCall\PrivatizeLocalGetterToPropertyRector: null

imports:
- { resource: "create-rector.yaml", ignore_errors: 'not_found' }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,6 @@ private function shouldSkip(string $lastName, string $aliasName): bool
*/
private function renameNameNode(array $usedNameNodes, string $lastName): void
{
/** @var Identifier|Name $usedName */
// @todo value objects
foreach ($usedNameNodes as $nameAndParent) {
$parentNode = $nameAndParent->getParentNode();
$usedName = $nameAndParent->getNameNode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ function throwWithFactoryStaticMethodNotAnnotated()
}

?>

Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ class SomeClassWithStaticCalls
{
}
}

3 changes: 2 additions & 1 deletion rules/doctrine/config/config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
services:
_defaults:
autowire: true
public: true
autowire: true
autoconfigure: true

Rector\Doctrine\:
resource: '../src'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,74 +2,52 @@

namespace Rector\Php71\Tests\Rector\FuncCall\RemoveExtraParametersRector\Fixture;

use Rector\Php71\Tests\Rector\FuncCall\RemoveExtraParametersRector\Source\SomeExternalClass;

final class MethodExtraArgument
{
public function run()
{
$this->perform(1);
$this->perform(1, 2);

(new ExternalClass())->hide(1);
(new ExternalClass())->hide(1, 2);
(new SomeExternalClass())->hide(1);
(new SomeExternalClass())->hide(1, 2);

ExternalClass::seek(1);
ExternalClass::seek(1, 2);
SomeExternalClass::seek(1);
SomeExternalClass::seek(1, 2);
}

private function perform($value)
{
}
}

class ExternalClass
{
public function hide($value)
{

}

public static function seek($value)
{

}
}

?>
-----
<?php

namespace Rector\Php71\Tests\Rector\FuncCall\RemoveExtraParametersRector\Fixture;

use Rector\Php71\Tests\Rector\FuncCall\RemoveExtraParametersRector\Source\SomeExternalClass;

final class MethodExtraArgument
{
public function run()
{
$this->perform(1);
$this->perform(1);

(new ExternalClass())->hide(1);
(new ExternalClass())->hide(1);
(new SomeExternalClass())->hide(1);
(new SomeExternalClass())->hide(1);

ExternalClass::seek(1);
ExternalClass::seek(1);
SomeExternalClass::seek(1);
SomeExternalClass::seek(1);
}

private function perform($value)
{
}
}

class ExternalClass
{
public function hide($value)
{

}

public static function seek($value)
{

}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Rector\Php71\Tests\Rector\FuncCall\RemoveExtraParametersRector\Source;

final class SomeExternalClass
{
public function hide($value)
{

}

public static function seek($value)
{

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Rector\Privatization\Tests\Rector\ClassMethod\PrivatizeLocalOnlyMethodRector\Fixture;

use Rector\Privatization\Tests\Rector\ClassMethod\PrivatizeLocalOnlyMethodRector\Source\ExternalClass;

class SkipExternalCall
{
/**
Expand All @@ -22,10 +24,3 @@ class SkipExternalCall
$this->externalClass->run();
}
}

class ExternalClass
{
public function run()
{
}
}
Loading