mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-01 08:50:50 +00:00
various improvements
This commit is contained in:
parent
96b0a7e88d
commit
192c4464ec
2
.github/workflows/phpstan.yaml
vendored
2
.github/workflows/phpstan.yaml
vendored
|
@ -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
|
||||
|
|
5
.github/workflows/validate_services.yaml
vendored
5
.github/workflows/validate_services.yaml
vendored
|
@ -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
|
||||
|
|
|
@ -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",
|
||||
|
@ -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",
|
||||
|
@ -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",
|
||||
|
@ -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": {
|
||||
|
|
|
@ -6,6 +6,7 @@ namespace Rector\AttributeAwarePhpDoc\Ast\Type;
|
|||
|
||||
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;
|
||||
|
@ -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 = '')
|
||||
{
|
||||
|
|
|
@ -34,7 +34,7 @@ final class FileInfoParser
|
|||
{
|
||||
$oldStmts = $this->parser->parseFile($fileInfo->getRealPath());
|
||||
|
||||
return $this->nodeScopeAndMetadataDecorator->decorateNodesFromFile($oldStmts, $fileInfo->getRealPath());
|
||||
return $this->nodeScopeAndMetadataDecorator->decorateNodesFromFile($oldStmts, $fileInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -44,6 +44,6 @@ final class FileInfoParser
|
|||
{
|
||||
$oldStmts = $this->parser->parseFile($fileInfo->getRealPath());
|
||||
|
||||
return $this->nodeScopeAndMetadataDecorator->decorateNodesFromFile($oldStmts, $fileInfo->getRealPath(), true);
|
||||
return $this->nodeScopeAndMetadataDecorator->decorateNodesFromFile($oldStmts, $fileInfo, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -111,10 +111,7 @@ abstract class AbstractFileSystemRector implements FileSystemRectorInterface
|
|||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,6 +18,7 @@ use Rector\NodeTypeResolver\NodeVisitor\ParentAndNextNodeVisitor;
|
|||
use Rector\NodeTypeResolver\NodeVisitor\PhpDocInfoNodeVisitor;
|
||||
use Rector\NodeTypeResolver\NodeVisitor\StatementNodeVisitor;
|
||||
use Rector\NodeTypeResolver\PHPStan\Scope\NodeScopeResolver;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class NodeScopeAndMetadataDecorator
|
||||
{
|
||||
|
@ -106,18 +107,19 @@ final class NodeScopeAndMetadataDecorator
|
|||
* @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();
|
||||
|
|
|
@ -19,6 +19,7 @@ use Rector\Core\Exception\ShouldNotHappenException;
|
|||
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
|
||||
|
@ -69,11 +70,11 @@ final class NodeScopeResolver
|
|||
* @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 {
|
||||
|
|
|
@ -14,6 +14,7 @@ use PHPStan\DependencyInjection\Type\OperatorTypeSpecifyingExtensionRegistryProv
|
|||
use PHPStan\Reflection\ReflectionProvider;
|
||||
use PHPStan\Rules\Properties\PropertyReflectionFinder;
|
||||
use Rector\Core\PhpParser\Printer\BetterStandardPrinter;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class ScopeFactory
|
||||
{
|
||||
|
@ -63,7 +64,7 @@ final class ScopeFactory
|
|||
$this->operatorTypeSpecifyingExtensionRegistryProvider = $operatorTypeSpecifyingExtensionRegistryProvider;
|
||||
}
|
||||
|
||||
public function createFromFile(string $filePath): Scope
|
||||
public function createFromFile(SmartFileInfo $fileInfo): Scope
|
||||
{
|
||||
return new MutatingScope(
|
||||
$this->phpStanScopeFactory,
|
||||
|
@ -73,7 +74,7 @@ final class ScopeFactory
|
|||
$this->betterStandardPrinter,
|
||||
$this->typeSpecifier,
|
||||
new PropertyReflectionFinder(),
|
||||
ScopeContext::create($filePath)
|
||||
ScopeContext::create($fileInfo->getRealPath())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,6 +74,6 @@ abstract class AbstractNodeTypeResolverTest extends AbstractKernelTestCase
|
|||
|
||||
$nodes = $this->parser->parseFile($smartFileInfo->getRealPath());
|
||||
|
||||
return $this->nodeScopeAndMetadataDecorator->decorateNodesFromFile($nodes, $smartFileInfo->getRealPath());
|
||||
return $this->nodeScopeAndMetadataDecorator->decorateNodesFromFile($nodes, $smartFileInfo);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,17 +41,17 @@ final class PropertyTypeResolverTest extends AbstractNodeTypeResolverTest
|
|||
|
||||
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
|
||||
|
|
|
@ -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
|
||||
{
|
|
@ -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#'
|
||||
|
|
|
@ -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' }
|
||||
|
||||
|
|
|
@ -164,8 +164,6 @@ PHP
|
|||
*/
|
||||
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();
|
||||
|
|
|
@ -10,4 +10,3 @@ function throwWithFactoryStaticMethodNotAnnotated()
|
|||
}
|
||||
|
||||
?>
|
||||
|
||||
|
|
|
@ -18,4 +18,3 @@ class SomeClassWithStaticCalls
|
|||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
services:
|
||||
_defaults:
|
||||
autowire: true
|
||||
public: true
|
||||
autowire: true
|
||||
autoconfigure: true
|
||||
|
||||
Rector\Doctrine\:
|
||||
resource: '../src'
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Rector\Php71\Tests\Rector\FuncCall\RemoveExtraParametersRector\Fixture;
|
||||
|
||||
use Rector\Php71\Tests\Rector\FuncCall\RemoveExtraParametersRector\Source\SomeExternalClass;
|
||||
|
||||
final class MethodExtraArgument
|
||||
{
|
||||
public function run()
|
||||
|
@ -9,11 +11,11 @@ final class MethodExtraArgument
|
|||
$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)
|
||||
|
@ -21,25 +23,14 @@ final class MethodExtraArgument
|
|||
}
|
||||
}
|
||||
|
||||
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()
|
||||
|
@ -47,11 +38,11 @@ final class MethodExtraArgument
|
|||
$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)
|
||||
|
@ -59,17 +50,4 @@ final class MethodExtraArgument
|
|||
}
|
||||
}
|
||||
|
||||
class ExternalClass
|
||||
{
|
||||
public function hide($value)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static function seek($value)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Rector\Privatization\Tests\Rector\ClassMethod\PrivatizeLocalOnlyMethodRector\Fixture;
|
||||
|
||||
use Rector\Privatization\Tests\Rector\ClassMethod\PrivatizeLocalOnlyMethodRector\Source\ExternalClass;
|
||||
|
||||
class SkipExternalCall
|
||||
{
|
||||
/**
|
||||
|
@ -22,10 +24,3 @@ class SkipExternalCall
|
|||
$this->externalClass->run();
|
||||
}
|
||||
}
|
||||
|
||||
class ExternalClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace Rector\Privatization\Tests\Rector\ClassMethod\PrivatizeLocalOnlyMethodRector\Source;
|
||||
|
||||
final class ExternalClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Rector\SOLID\Tests\Rector\ClassMethod\UseInterfaceOverImplementationInConstructorRector\Source;
|
||||
|
||||
class Apple implements Fruit
|
||||
class Coconut implements Fruit
|
||||
{
|
||||
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Symfony\Tests\FrameworkBundle\AbstractToConstructorInjectionRectorSource;
|
||||
namespace Rector\Symfony\Tests\Rector\FrameworkBundle\AbstractToConstructorInjectionRectorSource;
|
||||
|
||||
final class SomeNonKernelClass
|
||||
{
|
||||
|
|
|
@ -36,15 +36,10 @@ final class ReportRoutesExtension implements ReportingExtensionInterface
|
|||
$tableLines = [];
|
||||
|
||||
foreach ($this->routeCollector->getRouteValueObjects() as $routeValueObject) {
|
||||
$paramsAsString = $routeValueObject->getParams() !== [] ? '$' . implode(
|
||||
', $',
|
||||
$routeValueObject->getParams()
|
||||
) : '';
|
||||
|
||||
$tableLines[] = [
|
||||
$routeValueObject->getControllerClass(),
|
||||
$routeValueObject->getMethodName(),
|
||||
$paramsAsString,
|
||||
$routeValueObject->getParamsAsString(),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -45,19 +45,20 @@ final class RouteValueObject
|
|||
return $this->methodName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed[]
|
||||
*/
|
||||
public function getParams(): array
|
||||
{
|
||||
return $this->params;
|
||||
}
|
||||
|
||||
public function getSymfonyRoutePhpDocTagNode(): SymfonyRouteTagValueNode
|
||||
{
|
||||
return new SymfonyRouteTagValueNode($this->getPath());
|
||||
}
|
||||
|
||||
public function getParamsAsString(): string
|
||||
{
|
||||
if ($this->params === []) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return '$' . implode(', $', $this->params);
|
||||
}
|
||||
|
||||
private function getPath(): string
|
||||
{
|
||||
$controllerPath = $this->resolveControllerPath();
|
||||
|
|
|
@ -163,10 +163,7 @@ final class FileProcessor
|
|||
// needed for \Rector\NodeTypeResolver\PHPStan\Scope\NodeScopeResolver
|
||||
$this->tokensByFilePath[$smartFileInfo->getRealPath()] = [$oldStmts, $oldStmts, $oldTokens];
|
||||
|
||||
$newStmts = $this->nodeScopeAndMetadataDecorator->decorateNodesFromFile(
|
||||
$oldStmts,
|
||||
$smartFileInfo->getRealPath()
|
||||
);
|
||||
$newStmts = $this->nodeScopeAndMetadataDecorator->decorateNodesFromFile($oldStmts, $smartFileInfo);
|
||||
|
||||
return [$newStmts, $oldStmts, $oldTokens];
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace Rector\Core\Application;
|
||||
|
||||
use OndraM\CiDetector\CiDetector;
|
||||
use PHPStan\AnalysedCodeException;
|
||||
use PHPStan\Analyser\NodeScopeResolver;
|
||||
use Rector\ChangesReporting\Application\ErrorAndDiffCollector;
|
||||
|
@ -86,11 +85,6 @@ final class RectorApplication
|
|||
*/
|
||||
private $finishingExtensionRunner;
|
||||
|
||||
/**
|
||||
* @var CiDetector
|
||||
*/
|
||||
private $ciDetector;
|
||||
|
||||
public function __construct(
|
||||
SymfonyStyle $symfonyStyle,
|
||||
FileSystemFileProcessor $fileSystemFileProcessor,
|
||||
|
@ -101,8 +95,7 @@ final class RectorApplication
|
|||
RemovedAndAddedFilesCollector $removedAndAddedFilesCollector,
|
||||
RemovedAndAddedFilesProcessor $removedAndAddedFilesProcessor,
|
||||
NodeScopeResolver $nodeScopeResolver,
|
||||
FinishingExtensionRunner $finishingExtensionRunner,
|
||||
CiDetector $ciDetector
|
||||
FinishingExtensionRunner $finishingExtensionRunner
|
||||
) {
|
||||
$this->symfonyStyle = $symfonyStyle;
|
||||
$this->fileSystemFileProcessor = $fileSystemFileProcessor;
|
||||
|
@ -114,7 +107,6 @@ final class RectorApplication
|
|||
$this->enabledRectorsProvider = $enabledRectorsProvider;
|
||||
$this->nodeScopeResolver = $nodeScopeResolver;
|
||||
$this->finishingExtensionRunner = $finishingExtensionRunner;
|
||||
$this->ciDetector = $ciDetector;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -180,15 +172,11 @@ final class RectorApplication
|
|||
*/
|
||||
private function configureStepCount(SymfonyStyle $symfonyStyle): void
|
||||
{
|
||||
if (! $this->ciDetector->isCiDetected()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$privatesAccessor = new PrivatesAccessor();
|
||||
|
||||
/** @var ProgressBar $progressBar */
|
||||
$progressBar = $privatesAccessor->getPrivateProperty($symfonyStyle, 'progressBar');
|
||||
if ($progressBar->getMaxSteps() < 10) {
|
||||
if ($progressBar->getMaxSteps() < 40) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -246,9 +234,8 @@ final class RectorApplication
|
|||
|
||||
$oldContent = $fileInfo->getContents();
|
||||
|
||||
$newContent = $this->configuration->isDryRun() ? $this->fileProcessor->printToString(
|
||||
$fileInfo
|
||||
) : $this->fileProcessor->printToFile($fileInfo);
|
||||
$newContent = $this->configuration->isDryRun() ? $this->fileProcessor->printToString($fileInfo)
|
||||
: $this->fileProcessor->printToFile($fileInfo);
|
||||
|
||||
$this->errorAndDiffCollector->addFileDiff($fileInfo, $newContent, $oldContent);
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ namespace Rector\Core\Configuration;
|
|||
|
||||
use Jean85\PrettyVersions;
|
||||
use Nette\Utils\Strings;
|
||||
use OndraM\CiDetector\CiDetector;
|
||||
use Rector\ChangesReporting\Output\CheckstyleOutputFormatter;
|
||||
use Rector\ChangesReporting\Output\JsonOutputFormatter;
|
||||
use Rector\Core\Exception\Rector\RectorNotFoundOrNotValidRectorClassException;
|
||||
|
@ -60,6 +61,16 @@ final class Configuration
|
|||
*/
|
||||
private $source = [];
|
||||
|
||||
/**
|
||||
* @var CiDetector
|
||||
*/
|
||||
private $ciDetector;
|
||||
|
||||
public function __construct(CiDetector $ciDetector)
|
||||
{
|
||||
$this->ciDetector = $ciDetector;
|
||||
}
|
||||
|
||||
/**
|
||||
* Needs to run in the start of the life cycle, since the rest of workflow uses it.
|
||||
*/
|
||||
|
@ -119,6 +130,10 @@ final class Configuration
|
|||
|
||||
public function showProgressBar(): bool
|
||||
{
|
||||
if ($this->ciDetector->isCiDetected()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->showProgressBar;
|
||||
}
|
||||
|
||||
|
|
|
@ -71,7 +71,11 @@ final class BetterStandardPrinter extends Standard
|
|||
|
||||
// remove dead <?php structures
|
||||
$clearContent = Strings::replace($content, '#\<\?php(\s)\?\>\n?#');
|
||||
return Strings::replace($clearContent, '#\<\?php(\s+)\?\>#');
|
||||
|
||||
$clearContent = Strings::replace($clearContent, '#\<\?php(\s+)\?\>#');
|
||||
|
||||
// keep EOL
|
||||
return rtrim($clearContent) . PHP_EOL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
class PHPUnit_TestCase
|
||||
class PHPUnit_Abc
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,6 @@ class PHPUnit_TestCase
|
|||
|
||||
namespace PHPUnit;
|
||||
|
||||
class TestCase
|
||||
class Abc
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user