mirror of
https://github.com/rectorphp/rector.git
synced 2025-04-13 03:52:15 +02:00
Updated Rector to commit ceab6d71bb3436c1c613651a12af55954ab3f7bf
ceab6d71bb
Add currentStmt property on AbstractRector to allow pull Scope from it on deep Expr (#4437)
This commit is contained in:
parent
b9ed01d3be
commit
bff94f9200
@ -50,7 +50,6 @@ use Rector\Core\Contract\Rector\PhpRectorInterface;
|
||||
use Rector\Core\Contract\Rector\RectorInterface;
|
||||
use Rector\Core\NonPhpFile\NonPhpFileProcessor;
|
||||
use Rector\Core\PhpParser\NodeTraverser\RectorNodeTraverser;
|
||||
use Rector\Core\Validation\Collector\EmptyConfigurableRectorCollector;
|
||||
use Rector\Core\ValueObjectFactory\Application\FileFactory;
|
||||
use Rector\NodeNameResolver\Contract\NodeNameResolverInterface;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
@ -135,7 +134,6 @@ return static function (RectorConfig $rectorConfig) : void {
|
||||
$services->load('Rector\\Core\\', __DIR__ . '/../src')->exclude([__DIR__ . '/../src/Rector', __DIR__ . '/../src/Console/Style/RectorConsoleOutputStyle.php', __DIR__ . '/../src/Exception', __DIR__ . '/../src/DependencyInjection/CompilerPass', __DIR__ . '/../src/DependencyInjection/Loader', __DIR__ . '/../src/Kernel', __DIR__ . '/../src/ValueObject', __DIR__ . '/../src/Bootstrap', __DIR__ . '/../src/Enum', __DIR__ . '/../src/functions', __DIR__ . '/../src/PhpParser/Node/CustomNode', __DIR__ . '/../src/PhpParser/ValueObject', __DIR__ . '/../src/PHPStan/NodeVisitor', __DIR__ . '/../src/constants.php']);
|
||||
$services->set(ConsoleApplication::class)->arg('$commands', tagged_iterator(Command::class));
|
||||
$services->alias(Application::class, ConsoleApplication::class);
|
||||
$services->set(EmptyConfigurableRectorCollector::class)->arg('$containerBuilder', service('service_container'));
|
||||
$services->set(SimpleCallableNodeTraverser::class);
|
||||
$services->set(BuilderFactory::class);
|
||||
$services->set(CloningVisitor::class);
|
||||
|
@ -12,7 +12,7 @@ use PhpParser\Node\Scalar\String_;
|
||||
use PhpParser\Node\Stmt\ClassConst;
|
||||
use PhpParser\NodeTraverser;
|
||||
use PHPStan\Reflection\ReflectionProvider;
|
||||
use Rector\Core\Contract\Rector\AllowEmptyConfigurableRectorInterface;
|
||||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
|
||||
@ -24,7 +24,7 @@ use RectorPrefix202307\Webmozart\Assert\Assert;
|
||||
*
|
||||
* @see \Rector\Tests\Php55\Rector\String_\StringClassNameToClassConstantRector\StringClassNameToClassConstantRectorTest
|
||||
*/
|
||||
final class StringClassNameToClassConstantRector extends AbstractRector implements AllowEmptyConfigurableRectorInterface, MinPhpVersionInterface
|
||||
final class StringClassNameToClassConstantRector extends AbstractRector implements MinPhpVersionInterface, ConfigurableRectorInterface
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
|
@ -7,7 +7,7 @@ use RectorPrefix202307\Nette\Utils\Strings;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Scalar\DNumber;
|
||||
use PhpParser\Node\Scalar\LNumber;
|
||||
use Rector\Core\Contract\Rector\AllowEmptyConfigurableRectorInterface;
|
||||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\Util\StringUtils;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
@ -19,13 +19,14 @@ use RectorPrefix202307\Webmozart\Assert\Assert;
|
||||
/**
|
||||
* @changelog https://wiki.php.net/rfc/numeric_literal_separator
|
||||
* @changelog https://github.com/nikic/PHP-Parser/pull/615
|
||||
*
|
||||
* @see \Rector\Tests\Php74\Rector\LNumber\AddLiteralSeparatorToNumberRector\AddLiteralSeparatorToNumberRectorTest
|
||||
* @changelog https://twitter.com/seldaek/status/1329064983120982022
|
||||
*
|
||||
* Taking the most generic use case to the account: https://wiki.php.net/rfc/numeric_literal_separator#should_it_be_the_role_of_an_ide_to_group_digits
|
||||
* The final check should be done manually
|
||||
*/
|
||||
final class AddLiteralSeparatorToNumberRector extends AbstractRector implements AllowEmptyConfigurableRectorInterface, MinPhpVersionInterface
|
||||
final class AddLiteralSeparatorToNumberRector extends AbstractRector implements MinPhpVersionInterface, ConfigurableRectorInterface
|
||||
{
|
||||
/**
|
||||
* @api
|
||||
|
@ -19,7 +19,7 @@ use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\TypeCombinator;
|
||||
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger;
|
||||
use Rector\BetterPhpDocParser\ValueObject\PhpDocAttributeKey;
|
||||
use Rector\Core\Contract\Rector\AllowEmptyConfigurableRectorInterface;
|
||||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\NodeAnalyzer\ParamAnalyzer;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\ValueObject\MethodName;
|
||||
@ -39,7 +39,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
*
|
||||
* @see \Rector\Tests\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector\ClassPropertyAssignToConstructorPromotionRectorTest
|
||||
*/
|
||||
final class ClassPropertyAssignToConstructorPromotionRector extends AbstractRector implements MinPhpVersionInterface, AllowEmptyConfigurableRectorInterface
|
||||
final class ClassPropertyAssignToConstructorPromotionRector extends AbstractRector implements MinPhpVersionInterface, ConfigurableRectorInterface
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
|
@ -3,7 +3,7 @@
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Strict\Rector;
|
||||
|
||||
use Rector\Core\Contract\Rector\AllowEmptyConfigurableRectorInterface;
|
||||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\Rector\AbstractScopeAwareRector;
|
||||
use RectorPrefix202307\Webmozart\Assert\Assert;
|
||||
/**
|
||||
@ -11,7 +11,7 @@ use RectorPrefix202307\Webmozart\Assert\Assert;
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
abstract class AbstractFalsyScalarRuleFixerRector extends AbstractScopeAwareRector implements AllowEmptyConfigurableRectorInterface
|
||||
abstract class AbstractFalsyScalarRuleFixerRector extends AbstractScopeAwareRector implements ConfigurableRectorInterface
|
||||
{
|
||||
/**
|
||||
* @api
|
||||
|
@ -11,6 +11,7 @@ use PhpParser\Node\Expr\BooleanNot;
|
||||
use PhpParser\Node\Expr\Empty_;
|
||||
use PhpParser\Node\Expr\Isset_;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Strict\NodeFactory\ExactCompareFactory;
|
||||
use Rector\Strict\Rector\AbstractFalsyScalarRuleFixerRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
||||
@ -18,7 +19,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @see \Rector\Tests\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector\DisallowedEmptyRuleFixerRectorTest
|
||||
*/
|
||||
final class DisallowedEmptyRuleFixerRector extends AbstractFalsyScalarRuleFixerRector
|
||||
final class DisallowedEmptyRuleFixerRector extends AbstractFalsyScalarRuleFixerRector implements ConfigurableRectorInterface
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
|
@ -6,7 +6,7 @@ namespace Rector\Transform\Rector\ClassMethod;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\Interface_;
|
||||
use Rector\Core\Contract\Rector\AllowEmptyConfigurableRectorInterface;
|
||||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\Reflection\ReflectionResolver;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
@ -21,7 +21,7 @@ use RectorPrefix202307\Webmozart\Assert\Assert;
|
||||
/**
|
||||
* @see \Rector\Tests\Transform\Rector\ClassMethod\ReturnTypeWillChangeRector\ReturnTypeWillChangeRectorTest
|
||||
*/
|
||||
final class ReturnTypeWillChangeRector extends AbstractRector implements AllowEmptyConfigurableRectorInterface, MinPhpVersionInterface
|
||||
final class ReturnTypeWillChangeRector extends AbstractRector implements MinPhpVersionInterface, ConfigurableRectorInterface
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
|
@ -7,7 +7,7 @@ use PhpParser\Node;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PHPStan\Reflection\ReflectionProvider;
|
||||
use Rector\Core\Contract\Rector\AllowEmptyConfigurableRectorInterface;
|
||||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\ValueObject\MethodName;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
@ -24,7 +24,7 @@ use RectorPrefix202307\Webmozart\Assert\Assert;
|
||||
*
|
||||
* @see \Rector\Tests\Transform\Rector\Class_\AddAllowDynamicPropertiesAttributeRector\AddAllowDynamicPropertiesAttributeRectorTest
|
||||
*/
|
||||
final class AddAllowDynamicPropertiesAttributeRector extends AbstractRector implements AllowEmptyConfigurableRectorInterface, MinPhpVersionInterface
|
||||
final class AddAllowDynamicPropertiesAttributeRector extends AbstractRector implements MinPhpVersionInterface, ConfigurableRectorInterface
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
|
@ -12,7 +12,7 @@ use PHPStan\Reflection\ClassReflection;
|
||||
use PHPStan\Type\NeverType;
|
||||
use PHPStan\Type\VoidType;
|
||||
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger;
|
||||
use Rector\Core\Contract\Rector\AllowEmptyConfigurableRectorInterface;
|
||||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\Reflection\ReflectionResolver;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
@ -25,7 +25,7 @@ use RectorPrefix202307\Webmozart\Assert\Assert;
|
||||
/**
|
||||
* @see \Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddVoidReturnTypeWhereNoReturnRector\AddVoidReturnTypeWhereNoReturnRectorTest
|
||||
*/
|
||||
final class AddVoidReturnTypeWhereNoReturnRector extends AbstractRector implements MinPhpVersionInterface, AllowEmptyConfigurableRectorInterface
|
||||
final class AddVoidReturnTypeWhereNoReturnRector extends AbstractRector implements ConfigurableRectorInterface, MinPhpVersionInterface
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
|
@ -12,7 +12,7 @@ use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\Type;
|
||||
use PHPStan\Type\TypeCombinator;
|
||||
use PHPStan\Type\UnionType;
|
||||
use Rector\Core\Contract\Rector\AllowEmptyConfigurableRectorInterface;
|
||||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\Reflection\ReflectionResolver;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
@ -27,7 +27,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @see \Rector\Tests\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector\TypedPropertyFromAssignsRectorTest
|
||||
*/
|
||||
final class TypedPropertyFromAssignsRector extends AbstractRector implements AllowEmptyConfigurableRectorInterface, MinPhpVersionInterface
|
||||
final class TypedPropertyFromAssignsRector extends AbstractRector implements MinPhpVersionInterface, ConfigurableRectorInterface
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
|
@ -55,7 +55,7 @@ final class ChangedNodeScopeRefresher
|
||||
$this->scopeAnalyzer = $scopeAnalyzer;
|
||||
$this->currentFileProvider = $currentFileProvider;
|
||||
}
|
||||
public function refresh(Node $node, ?MutatingScope $mutatingScope, ?string $filePath = null) : void
|
||||
public function refresh(Node $node, ?MutatingScope $mutatingScope, ?string $filePath = null, ?Stmt $currentStmt = null) : void
|
||||
{
|
||||
// nothing to refresh
|
||||
if (!$this->scopeAnalyzer->isRefreshable($node)) {
|
||||
@ -66,7 +66,7 @@ final class ChangedNodeScopeRefresher
|
||||
$file = $this->currentFileProvider->getFile();
|
||||
$filePath = $file->getFilePath();
|
||||
}
|
||||
$mutatingScope = $this->scopeAnalyzer->resolveScope($node, $filePath, $mutatingScope);
|
||||
$mutatingScope = $mutatingScope instanceof MutatingScope ? $mutatingScope : $this->scopeAnalyzer->resolveScope($node, $filePath, $currentStmt);
|
||||
if (!$mutatingScope instanceof MutatingScope) {
|
||||
$errorMessage = \sprintf('Node "%s" with is missing scope required for scope refresh', \get_class($node));
|
||||
throw new ShouldNotHappenException($errorMessage);
|
||||
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '972d7607f1c4ab8b733b91d7aa5020ce1b143538';
|
||||
public const PACKAGE_VERSION = 'ceab6d71bb3436c1c613651a12af55954ab3f7bf';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-07-19 11:49:53';
|
||||
public const RELEASE_DATE = '2023-07-19 12:04:44';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
@ -15,7 +15,6 @@ use Rector\Core\Contract\Console\OutputStyleInterface;
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\Core\StaticReflection\DynamicSourceLocatorDecorator;
|
||||
use Rector\Core\Util\MemoryLimiter;
|
||||
use Rector\Core\Validation\EmptyConfigurableRectorChecker;
|
||||
use Rector\Core\ValueObject\Configuration;
|
||||
use Rector\Core\ValueObject\ProcessResult;
|
||||
use Rector\Core\ValueObjectFactory\ProcessResultFactory;
|
||||
@ -54,11 +53,6 @@ final class ProcessCommand extends \Rector\Core\Console\Command\AbstractProcessC
|
||||
* @var \Rector\Core\StaticReflection\DynamicSourceLocatorDecorator
|
||||
*/
|
||||
private $dynamicSourceLocatorDecorator;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\Validation\EmptyConfigurableRectorChecker
|
||||
*/
|
||||
private $emptyConfigurableRectorChecker;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\Console\Output\OutputFormatterCollector
|
||||
@ -74,7 +68,7 @@ final class ProcessCommand extends \Rector\Core\Console\Command\AbstractProcessC
|
||||
* @var \Rector\Core\Util\MemoryLimiter
|
||||
*/
|
||||
private $memoryLimiter;
|
||||
public function __construct(AdditionalAutoloader $additionalAutoloader, ChangedFilesDetector $changedFilesDetector, ConfigInitializer $configInitializer, ApplicationFileProcessor $applicationFileProcessor, ProcessResultFactory $processResultFactory, DynamicSourceLocatorDecorator $dynamicSourceLocatorDecorator, EmptyConfigurableRectorChecker $emptyConfigurableRectorChecker, OutputFormatterCollector $outputFormatterCollector, OutputStyleInterface $rectorOutputStyle, MemoryLimiter $memoryLimiter)
|
||||
public function __construct(AdditionalAutoloader $additionalAutoloader, ChangedFilesDetector $changedFilesDetector, ConfigInitializer $configInitializer, ApplicationFileProcessor $applicationFileProcessor, ProcessResultFactory $processResultFactory, DynamicSourceLocatorDecorator $dynamicSourceLocatorDecorator, OutputFormatterCollector $outputFormatterCollector, OutputStyleInterface $rectorOutputStyle, MemoryLimiter $memoryLimiter)
|
||||
{
|
||||
$this->additionalAutoloader = $additionalAutoloader;
|
||||
$this->changedFilesDetector = $changedFilesDetector;
|
||||
@ -82,7 +76,6 @@ final class ProcessCommand extends \Rector\Core\Console\Command\AbstractProcessC
|
||||
$this->applicationFileProcessor = $applicationFileProcessor;
|
||||
$this->processResultFactory = $processResultFactory;
|
||||
$this->dynamicSourceLocatorDecorator = $dynamicSourceLocatorDecorator;
|
||||
$this->emptyConfigurableRectorChecker = $emptyConfigurableRectorChecker;
|
||||
$this->outputFormatterCollector = $outputFormatterCollector;
|
||||
$this->rectorOutputStyle = $rectorOutputStyle;
|
||||
$this->memoryLimiter = $memoryLimiter;
|
||||
@ -116,13 +109,11 @@ final class ProcessCommand extends \Rector\Core\Console\Command\AbstractProcessC
|
||||
$this->rectorOutputStyle->error('The given paths do not match any files');
|
||||
return ExitCode::FAILURE;
|
||||
}
|
||||
// 2. inform user about registering configurable rule without configuration
|
||||
$this->emptyConfigurableRectorChecker->check();
|
||||
// MAIN PHASE
|
||||
// 3. run Rector
|
||||
// 2. run Rector
|
||||
$systemErrorsAndFileDiffs = $this->applicationFileProcessor->run($configuration, $input);
|
||||
// REPORTING PHASE
|
||||
// 4. reporting phase
|
||||
// 3. reporting phase
|
||||
// report diffs and errors
|
||||
$outputFormat = $configuration->getOutputFormat();
|
||||
$outputFormatter = $this->outputFormatterCollector->getByName($outputFormat);
|
||||
|
@ -1,8 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Core\Contract\Rector;
|
||||
|
||||
interface AllowEmptyConfigurableRectorInterface extends \Rector\Core\Contract\Rector\ConfigurableRectorInterface
|
||||
{
|
||||
}
|
@ -11,7 +11,7 @@ use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Param;
|
||||
use PhpParser\Node\Stmt;
|
||||
use PHPStan\Analyser\MutatingScope;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\NodeTypeResolver\PHPStan\Scope\ScopeFactory;
|
||||
final class ScopeAnalyzer
|
||||
@ -38,18 +38,16 @@ final class ScopeAnalyzer
|
||||
}
|
||||
return \true;
|
||||
}
|
||||
public function resolveScope(Node $node, string $filePath, ?MutatingScope $mutatingScope = null) : ?MutatingScope
|
||||
public function resolveScope(Node $node, string $filePath, ?Stmt $currentStmt = null) : ?Scope
|
||||
{
|
||||
if ($mutatingScope instanceof MutatingScope) {
|
||||
return $mutatingScope;
|
||||
}
|
||||
// on File level
|
||||
if ($node instanceof Stmt && $node->getAttribute(AttributeKey::STATEMENT_DEPTH) === 0) {
|
||||
return $this->scopeFactory->createFromFile($filePath);
|
||||
}
|
||||
// too deep Expr, eg: $$param = $$bar = self::decodeValue($result->getItem()->getTextContent());
|
||||
if ($node instanceof Expr && $node->getAttribute(AttributeKey::EXPRESSION_DEPTH) >= 2) {
|
||||
return $this->scopeFactory->createFromFile($filePath);
|
||||
$scope = $currentStmt instanceof Stmt ? $currentStmt->getAttribute(AttributeKey::SCOPE) : $this->scopeFactory->createFromFile($filePath);
|
||||
return $scope instanceof Scope ? $scope : $this->scopeFactory->createFromFile($filePath);
|
||||
}
|
||||
/**
|
||||
* Node and parent Node doesn't has Scope, and Node Start token pos is < 0,
|
||||
|
@ -89,6 +89,10 @@ CODE_SAMPLE;
|
||||
* @var \Rector\Core\ValueObject\Application\File
|
||||
*/
|
||||
protected $file;
|
||||
/**
|
||||
* @var \Rector\Core\Rector\Stmt|null
|
||||
*/
|
||||
protected $currentStmt;
|
||||
/**
|
||||
* @var \Rector\Core\Application\ChangedNodeScopeRefresher
|
||||
*/
|
||||
@ -176,8 +180,7 @@ CODE_SAMPLE;
|
||||
}
|
||||
public final function enterNode(Node $node)
|
||||
{
|
||||
$nodeClass = \get_class($node);
|
||||
if (!$this->isMatchingNodeType($nodeClass)) {
|
||||
if (!$this->isMatchingNodeType($node)) {
|
||||
return null;
|
||||
}
|
||||
if ($this->shouldSkipCurrentNode($node)) {
|
||||
@ -331,18 +334,20 @@ CODE_SAMPLE;
|
||||
{
|
||||
$nodes = $node instanceof Node ? [$node] : $node;
|
||||
foreach ($nodes as $node) {
|
||||
$this->changedNodeScopeRefresher->refresh($node, $mutatingScope, $filePath);
|
||||
$this->changedNodeScopeRefresher->refresh($node, $mutatingScope, $filePath, $this->currentStmt);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param class-string<Node> $nodeClass
|
||||
*/
|
||||
private function isMatchingNodeType(string $nodeClass) : bool
|
||||
private function isMatchingNodeType(Node $node) : bool
|
||||
{
|
||||
$nodeClass = \get_class($node);
|
||||
foreach ($this->getNodeTypes() as $nodeType) {
|
||||
if (\is_a($nodeClass, $nodeType, \true)) {
|
||||
return \true;
|
||||
if (!\is_a($nodeClass, $nodeType, \true)) {
|
||||
if ($node instanceof \Rector\Core\Rector\Stmt) {
|
||||
$this->currentStmt = $node;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
return \true;
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ abstract class AbstractScopeAwareRector extends \Rector\Core\Rector\AbstractRect
|
||||
/** @var MutatingScope|null $currentScope */
|
||||
$currentScope = $node->getAttribute(AttributeKey::SCOPE);
|
||||
if (!$currentScope instanceof MutatingScope) {
|
||||
$currentScope = $this->scopeAnalyzer->resolveScope($node, $this->file->getFilePath());
|
||||
$currentScope = $this->scopeAnalyzer->resolveScope($node, $this->file->getFilePath(), $this->currentStmt);
|
||||
}
|
||||
if (!$currentScope instanceof Scope) {
|
||||
$errorMessage = \sprintf('Scope not available on "%s" node, but is required by a refactorWithScope() method of "%s" rule. Fix scope refresh on changed nodes first', \get_class($node), static::class);
|
||||
|
@ -1,62 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Core\Validation\Collector;
|
||||
|
||||
use Rector\Core\Contract\Rector\AllowEmptyConfigurableRectorInterface;
|
||||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\NonPhpFile\Rector\RenameClassNonPhpRector;
|
||||
use RectorPrefix202307\Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use RectorPrefix202307\Symfony\Component\DependencyInjection\Definition;
|
||||
/**
|
||||
* @see \Rector\Core\Tests\Validation\Collector\EmptyConfigurableRectorCollector\EmptyConfigurableRectorCollectorTest
|
||||
*/
|
||||
final class EmptyConfigurableRectorCollector
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Symfony\Component\DependencyInjection\ContainerBuilder
|
||||
*/
|
||||
private $containerBuilder;
|
||||
public function __construct(ContainerBuilder $containerBuilder)
|
||||
{
|
||||
$this->containerBuilder = $containerBuilder;
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<ConfigurableRectorInterface>>
|
||||
*/
|
||||
public function resolveEmptyConfigurableRectorClasses() : array
|
||||
{
|
||||
$emptyConfigurableRectorClasses = [];
|
||||
foreach ($this->containerBuilder->getServiceIds() as $serviceId) {
|
||||
if (!\is_a($serviceId, ConfigurableRectorInterface::class, \true)) {
|
||||
continue;
|
||||
}
|
||||
if (\is_a($serviceId, AllowEmptyConfigurableRectorInterface::class, \true)) {
|
||||
continue;
|
||||
}
|
||||
// it seems always loaded
|
||||
if (\is_a($serviceId, RenameClassNonPhpRector::class, \true)) {
|
||||
continue;
|
||||
}
|
||||
$serviceDefinition = $this->containerBuilder->getDefinition($serviceId);
|
||||
if ($this->hasConfigureMethodCall($serviceDefinition)) {
|
||||
continue;
|
||||
}
|
||||
$emptyConfigurableRectorClasses[] = $serviceId;
|
||||
}
|
||||
return $emptyConfigurableRectorClasses;
|
||||
}
|
||||
private function hasConfigureMethodCall(Definition $definition) : bool
|
||||
{
|
||||
foreach ($definition->getMethodCalls() as $methodCall) {
|
||||
if ($methodCall[0] === 'configure') {
|
||||
if (!isset($methodCall[1][0])) {
|
||||
return \false;
|
||||
}
|
||||
return $methodCall[1][0] !== [];
|
||||
}
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Core\Validation;
|
||||
|
||||
use Rector\Core\Contract\Console\OutputStyleInterface;
|
||||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\Validation\Collector\EmptyConfigurableRectorCollector;
|
||||
final class EmptyConfigurableRectorChecker
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\Validation\Collector\EmptyConfigurableRectorCollector
|
||||
*/
|
||||
private $emptyConfigurableRectorCollector;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\Contract\Console\OutputStyleInterface
|
||||
*/
|
||||
private $rectorOutputStyle;
|
||||
public function __construct(EmptyConfigurableRectorCollector $emptyConfigurableRectorCollector, OutputStyleInterface $rectorOutputStyle)
|
||||
{
|
||||
$this->emptyConfigurableRectorCollector = $emptyConfigurableRectorCollector;
|
||||
$this->rectorOutputStyle = $rectorOutputStyle;
|
||||
}
|
||||
public function check() : void
|
||||
{
|
||||
$emptyConfigurableRectorClasses = $this->emptyConfigurableRectorCollector->resolveEmptyConfigurableRectorClasses();
|
||||
if ($emptyConfigurableRectorClasses === []) {
|
||||
return;
|
||||
}
|
||||
$this->reportWarningMessage($emptyConfigurableRectorClasses);
|
||||
$solutionMessage = \sprintf('Do you want to run them?%sConfigure them in `rector.php` with "...$rectorConfig->ruleWithConfiguration(...);"', \PHP_EOL);
|
||||
$this->rectorOutputStyle->note($solutionMessage);
|
||||
if (!$this->rectorOutputStyle->isVerbose()) {
|
||||
// ensure there is new line after progress bar and report : "[OK] Rector is done!" with add a space
|
||||
$this->rectorOutputStyle->writeln(' ');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param array<class-string<ConfigurableRectorInterface>> $emptyConfigurableRectorClasses
|
||||
*/
|
||||
private function reportWarningMessage(array $emptyConfigurableRectorClasses) : void
|
||||
{
|
||||
$warningMessage = \sprintf('Your project contains %d configurable rector rules that are skipped as need to be configured to run.', \count($emptyConfigurableRectorClasses));
|
||||
$this->rectorOutputStyle->warning($warningMessage);
|
||||
foreach ($emptyConfigurableRectorClasses as $emptyConfigurableRectorClass) {
|
||||
$this->rectorOutputStyle->writeln(' * ' . $emptyConfigurableRectorClass);
|
||||
}
|
||||
// to take time to absorb it
|
||||
\sleep(5);
|
||||
}
|
||||
}
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
|
||||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderIniteca17cb0d0de8025a8c123919c87bb6e::getLoader();
|
||||
return ComposerAutoloaderInit65d2b9c1c4a01d7e2aa44f2b41b74e33::getLoader();
|
||||
|
3
vendor/composer/autoload_classmap.php
vendored
3
vendor/composer/autoload_classmap.php
vendored
@ -1531,7 +1531,6 @@ return array(
|
||||
'Rector\\Core\\Contract\\PHPStan\\Reflection\\TypeToCallReflectionResolver\\TypeToCallReflectionResolverInterface' => $baseDir . '/src/Contract/PHPStan/Reflection/TypeToCallReflectionResolver/TypeToCallReflectionResolverInterface.php',
|
||||
'Rector\\Core\\Contract\\PhpParser\\Node\\StmtsAwareInterface' => $baseDir . '/src/Contract/PhpParser/Node/StmtsAwareInterface.php',
|
||||
'Rector\\Core\\Contract\\Processor\\FileProcessorInterface' => $baseDir . '/src/Contract/Processor/FileProcessorInterface.php',
|
||||
'Rector\\Core\\Contract\\Rector\\AllowEmptyConfigurableRectorInterface' => $baseDir . '/src/Contract/Rector/AllowEmptyConfigurableRectorInterface.php',
|
||||
'Rector\\Core\\Contract\\Rector\\ConfigurableRectorInterface' => $baseDir . '/src/Contract/Rector/ConfigurableRectorInterface.php',
|
||||
'Rector\\Core\\Contract\\Rector\\NonPhpRectorInterface' => $baseDir . '/src/Contract/Rector/NonPhpRectorInterface.php',
|
||||
'Rector\\Core\\Contract\\Rector\\PhpRectorInterface' => $baseDir . '/src/Contract/Rector/PhpRectorInterface.php',
|
||||
@ -1643,8 +1642,6 @@ return array(
|
||||
'Rector\\Core\\Util\\PhpVersionFactory' => $baseDir . '/src/Util/PhpVersionFactory.php',
|
||||
'Rector\\Core\\Util\\Reflection\\PrivatesAccessor' => $baseDir . '/src/Util/Reflection/PrivatesAccessor.php',
|
||||
'Rector\\Core\\Util\\StringUtils' => $baseDir . '/src/Util/StringUtils.php',
|
||||
'Rector\\Core\\Validation\\Collector\\EmptyConfigurableRectorCollector' => $baseDir . '/src/Validation/Collector/EmptyConfigurableRectorCollector.php',
|
||||
'Rector\\Core\\Validation\\EmptyConfigurableRectorChecker' => $baseDir . '/src/Validation/EmptyConfigurableRectorChecker.php',
|
||||
'Rector\\Core\\Validation\\RectorAssert' => $baseDir . '/src/Validation/RectorAssert.php',
|
||||
'Rector\\Core\\ValueObjectFactory\\Application\\FileFactory' => $baseDir . '/src/ValueObjectFactory/Application/FileFactory.php',
|
||||
'Rector\\Core\\ValueObjectFactory\\ProcessResultFactory' => $baseDir . '/src/ValueObjectFactory/ProcessResultFactory.php',
|
||||
|
10
vendor/composer/autoload_real.php
vendored
10
vendor/composer/autoload_real.php
vendored
@ -2,7 +2,7 @@
|
||||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderIniteca17cb0d0de8025a8c123919c87bb6e
|
||||
class ComposerAutoloaderInit65d2b9c1c4a01d7e2aa44f2b41b74e33
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@ -22,17 +22,17 @@ class ComposerAutoloaderIniteca17cb0d0de8025a8c123919c87bb6e
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderIniteca17cb0d0de8025a8c123919c87bb6e', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit65d2b9c1c4a01d7e2aa44f2b41b74e33', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderIniteca17cb0d0de8025a8c123919c87bb6e', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit65d2b9c1c4a01d7e2aa44f2b41b74e33', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticIniteca17cb0d0de8025a8c123919c87bb6e::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit65d2b9c1c4a01d7e2aa44f2b41b74e33::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticIniteca17cb0d0de8025a8c123919c87bb6e::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit65d2b9c1c4a01d7e2aa44f2b41b74e33::$files;
|
||||
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
11
vendor/composer/autoload_static.php
vendored
11
vendor/composer/autoload_static.php
vendored
@ -4,7 +4,7 @@
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticIniteca17cb0d0de8025a8c123919c87bb6e
|
||||
class ComposerStaticInit65d2b9c1c4a01d7e2aa44f2b41b74e33
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
@ -1785,7 +1785,6 @@ class ComposerStaticIniteca17cb0d0de8025a8c123919c87bb6e
|
||||
'Rector\\Core\\Contract\\PHPStan\\Reflection\\TypeToCallReflectionResolver\\TypeToCallReflectionResolverInterface' => __DIR__ . '/../..' . '/src/Contract/PHPStan/Reflection/TypeToCallReflectionResolver/TypeToCallReflectionResolverInterface.php',
|
||||
'Rector\\Core\\Contract\\PhpParser\\Node\\StmtsAwareInterface' => __DIR__ . '/../..' . '/src/Contract/PhpParser/Node/StmtsAwareInterface.php',
|
||||
'Rector\\Core\\Contract\\Processor\\FileProcessorInterface' => __DIR__ . '/../..' . '/src/Contract/Processor/FileProcessorInterface.php',
|
||||
'Rector\\Core\\Contract\\Rector\\AllowEmptyConfigurableRectorInterface' => __DIR__ . '/../..' . '/src/Contract/Rector/AllowEmptyConfigurableRectorInterface.php',
|
||||
'Rector\\Core\\Contract\\Rector\\ConfigurableRectorInterface' => __DIR__ . '/../..' . '/src/Contract/Rector/ConfigurableRectorInterface.php',
|
||||
'Rector\\Core\\Contract\\Rector\\NonPhpRectorInterface' => __DIR__ . '/../..' . '/src/Contract/Rector/NonPhpRectorInterface.php',
|
||||
'Rector\\Core\\Contract\\Rector\\PhpRectorInterface' => __DIR__ . '/../..' . '/src/Contract/Rector/PhpRectorInterface.php',
|
||||
@ -1897,8 +1896,6 @@ class ComposerStaticIniteca17cb0d0de8025a8c123919c87bb6e
|
||||
'Rector\\Core\\Util\\PhpVersionFactory' => __DIR__ . '/../..' . '/src/Util/PhpVersionFactory.php',
|
||||
'Rector\\Core\\Util\\Reflection\\PrivatesAccessor' => __DIR__ . '/../..' . '/src/Util/Reflection/PrivatesAccessor.php',
|
||||
'Rector\\Core\\Util\\StringUtils' => __DIR__ . '/../..' . '/src/Util/StringUtils.php',
|
||||
'Rector\\Core\\Validation\\Collector\\EmptyConfigurableRectorCollector' => __DIR__ . '/../..' . '/src/Validation/Collector/EmptyConfigurableRectorCollector.php',
|
||||
'Rector\\Core\\Validation\\EmptyConfigurableRectorChecker' => __DIR__ . '/../..' . '/src/Validation/EmptyConfigurableRectorChecker.php',
|
||||
'Rector\\Core\\Validation\\RectorAssert' => __DIR__ . '/../..' . '/src/Validation/RectorAssert.php',
|
||||
'Rector\\Core\\ValueObjectFactory\\Application\\FileFactory' => __DIR__ . '/../..' . '/src/ValueObjectFactory/Application/FileFactory.php',
|
||||
'Rector\\Core\\ValueObjectFactory\\ProcessResultFactory' => __DIR__ . '/../..' . '/src/ValueObjectFactory/ProcessResultFactory.php',
|
||||
@ -3026,9 +3023,9 @@ class ComposerStaticIniteca17cb0d0de8025a8c123919c87bb6e
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticIniteca17cb0d0de8025a8c123919c87bb6e::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticIniteca17cb0d0de8025a8c123919c87bb6e::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticIniteca17cb0d0de8025a8c123919c87bb6e::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit65d2b9c1c4a01d7e2aa44f2b41b74e33::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit65d2b9c1c4a01d7e2aa44f2b41b74e33::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit65d2b9c1c4a01d7e2aa44f2b41b74e33::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
8
vendor/composer/installed.json
vendored
8
vendor/composer/installed.json
vendored
@ -1985,12 +1985,12 @@
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/rectorphp\/rector-downgrade-php.git",
|
||||
"reference": "e10ce1addb5f523aa30749cd8dcf77796d46fd09"
|
||||
"reference": "f901f272bb9d83c8ab0c751a9b474c84a27fac05"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-downgrade-php\/zipball\/e10ce1addb5f523aa30749cd8dcf77796d46fd09",
|
||||
"reference": "e10ce1addb5f523aa30749cd8dcf77796d46fd09",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-downgrade-php\/zipball\/f901f272bb9d83c8ab0c751a9b474c84a27fac05",
|
||||
"reference": "f901f272bb9d83c8ab0c751a9b474c84a27fac05",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -2014,7 +2014,7 @@
|
||||
"tomasvotruba\/type-coverage": "^0.2",
|
||||
"tomasvotruba\/unused-public": "^0.1"
|
||||
},
|
||||
"time": "2023-07-19T10:46:18+00:00",
|
||||
"time": "2023-07-19T10:57:42+00:00",
|
||||
"default-branch": true,
|
||||
"type": "rector-extension",
|
||||
"extra": {
|
||||
|
2
vendor/composer/installed.php
vendored
2
vendor/composer/installed.php
vendored
File diff suppressed because one or more lines are too long
@ -9,7 +9,7 @@ namespace Rector\RectorInstaller;
|
||||
*/
|
||||
final class GeneratedConfig
|
||||
{
|
||||
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 2d14418'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main e10ce1a'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 3918e6f'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main a0af12a'));
|
||||
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 2d14418'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main f901f27'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 3918e6f'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main a0af12a'));
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ use PhpParser\Node\Param;
|
||||
use PhpParser\Node\Stmt\ClassLike;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PHPStan\Reflection\ClassReflection;
|
||||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\Reflection\ReflectionResolver;
|
||||
use Rector\DowngradePhp72\NodeAnalyzer\BuiltInMethodAnalyzer;
|
||||
@ -24,7 +25,7 @@ use RectorPrefix202307\Webmozart\Assert\Assert;
|
||||
*
|
||||
* @see \Rector\Tests\DowngradePhp72\Rector\ClassMethod\DowngradeParameterTypeWideningRector\DowngradeParameterTypeWideningRectorTest
|
||||
*/
|
||||
final class DowngradeParameterTypeWideningRector extends AbstractRector
|
||||
final class DowngradeParameterTypeWideningRector extends AbstractRector implements ConfigurableRectorInterface
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
|
Loading…
x
Reference in New Issue
Block a user