mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-01 17:00:51 +00:00
Updated Rector to commit dd970ac29023b0e6e27f54d79d98cf7415a638c5
dd970ac290
Drop AttributeKey::SCOPE in FullyQualifyStmtsAnalyzer (#3805)
This commit is contained in:
parent
2b9f121320
commit
f49ec8a9f1
|
@ -10,6 +10,7 @@ use PhpParser\Node\Name\FullyQualified;
|
|||
use PhpParser\Node\Stmt;
|
||||
use PhpParser\Node\Stmt\GroupUse;
|
||||
use PhpParser\Node\Stmt\UseUse;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Reflection\Constant\RuntimeConstantReflection;
|
||||
use PHPStan\Reflection\ReflectionProvider;
|
||||
use Rector\Core\Configuration\Option;
|
||||
|
@ -50,14 +51,14 @@ final class FullyQualifyStmtsAnalyzer
|
|||
/**
|
||||
* @param Stmt[] $stmts
|
||||
*/
|
||||
public function process(array $stmts) : void
|
||||
public function process(array $stmts, Scope $scope) : void
|
||||
{
|
||||
// no need to
|
||||
if ($this->parameterProvider->provideBoolParameter(Option::AUTO_IMPORT_NAMES)) {
|
||||
return;
|
||||
}
|
||||
// FQNize all class names
|
||||
$this->simpleCallableNodeTraverser->traverseNodesWithCallable($stmts, function (Node $node) : ?FullyQualified {
|
||||
$this->simpleCallableNodeTraverser->traverseNodesWithCallable($stmts, function (Node $node) use($scope) : ?FullyQualified {
|
||||
if (!$node instanceof Name) {
|
||||
return null;
|
||||
}
|
||||
|
@ -65,7 +66,7 @@ final class FullyQualifyStmtsAnalyzer
|
|||
if (\in_array($name, [ObjectReference::STATIC, ObjectReference::PARENT, ObjectReference::SELF], \true)) {
|
||||
return null;
|
||||
}
|
||||
if ($this->isNativeConstant($node)) {
|
||||
if ($this->isNativeConstant($node, $scope)) {
|
||||
return null;
|
||||
}
|
||||
$parentNode = $node->getAttribute(AttributeKey::PARENT_NODE);
|
||||
|
@ -79,13 +80,12 @@ final class FullyQualifyStmtsAnalyzer
|
|||
return new FullyQualified($name);
|
||||
});
|
||||
}
|
||||
private function isNativeConstant(Name $name) : bool
|
||||
private function isNativeConstant(Name $name, Scope $scope) : bool
|
||||
{
|
||||
$parentNode = $name->getAttribute(AttributeKey::PARENT_NODE);
|
||||
if (!$parentNode instanceof ConstFetch) {
|
||||
return \false;
|
||||
}
|
||||
$scope = $name->getAttribute(AttributeKey::SCOPE);
|
||||
if (!$this->reflectionProvider->hasConstant($name, $scope)) {
|
||||
return \false;
|
||||
}
|
||||
|
|
|
@ -8,9 +8,11 @@ use PhpParser\Node\Name;
|
|||
use PhpParser\Node\Stmt;
|
||||
use PhpParser\Node\Stmt\Declare_;
|
||||
use PhpParser\Node\Stmt\Namespace_;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use Rector\Core\NodeAnalyzer\InlineHTMLAnalyzer;
|
||||
use Rector\Core\PhpParser\Node\CustomNode\FileWithoutNamespace;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\Rector\AbstractScopeAwareRector;
|
||||
use Rector\PSR4\Contract\PSR4AutoloadNamespaceMatcherInterface;
|
||||
use Rector\PSR4\NodeManipulator\FullyQualifyStmtsAnalyzer;
|
||||
use Rector\PSR4\Rector\Namespace_\MultipleClassFileToPsr4ClassesRector;
|
||||
|
@ -19,7 +21,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
|||
/**
|
||||
* @see \Rector\Tests\PSR4\Rector\FileWithoutNamespace\NormalizeNamespaceByPSR4ComposerAutoloadRector\NormalizeNamespaceByPSR4ComposerAutoloadRectorTest
|
||||
*/
|
||||
final class NormalizeNamespaceByPSR4ComposerAutoloadRector extends AbstractRector
|
||||
final class NormalizeNamespaceByPSR4ComposerAutoloadRector extends AbstractScopeAwareRector
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
|
@ -83,7 +85,7 @@ CODE_SAMPLE
|
|||
* @param FileWithoutNamespace|Namespace_ $node
|
||||
* @return Node|null|Stmt[]
|
||||
*/
|
||||
public function refactor(Node $node)
|
||||
public function refactorWithScope(Node $node, Scope $scope)
|
||||
{
|
||||
if ($this->inlineHTMLAnalyzer->hasInlineHTML($node)) {
|
||||
return null;
|
||||
|
@ -101,10 +103,10 @@ CODE_SAMPLE
|
|||
}
|
||||
// to put declare_strict types on correct place
|
||||
if ($node instanceof FileWithoutNamespace) {
|
||||
return $this->refactorFileWithoutNamespace($node, $expectedNamespace);
|
||||
return $this->refactorFileWithoutNamespace($node, $expectedNamespace, $scope);
|
||||
}
|
||||
$node->name = new Name($expectedNamespace);
|
||||
$this->fullyQualifyStmtsAnalyzer->process($node->stmts);
|
||||
$this->fullyQualifyStmtsAnalyzer->process($node->stmts, $scope);
|
||||
return $node;
|
||||
}
|
||||
private function hasNamespaceInPreviousNamespace(Namespace_ $namespace) : bool
|
||||
|
@ -116,11 +118,10 @@ CODE_SAMPLE
|
|||
/**
|
||||
* @return Namespace_|Stmt[]
|
||||
*/
|
||||
private function refactorFileWithoutNamespace(FileWithoutNamespace $fileWithoutNamespace, string $expectedNamespace)
|
||||
private function refactorFileWithoutNamespace(FileWithoutNamespace $fileWithoutNamespace, string $expectedNamespace, Scope $scope)
|
||||
{
|
||||
$nodes = $fileWithoutNamespace->stmts;
|
||||
$declare = null;
|
||||
$nodesWithStrictTypesThenNamespace = [];
|
||||
foreach ($nodes as $key => $fileWithoutNamespace) {
|
||||
if ($key > 0) {
|
||||
break;
|
||||
|
@ -131,8 +132,7 @@ CODE_SAMPLE
|
|||
}
|
||||
}
|
||||
$namespace = new Namespace_(new Name($expectedNamespace), $nodes);
|
||||
$nodesWithStrictTypesThenNamespace[] = $namespace;
|
||||
$this->fullyQualifyStmtsAnalyzer->process($nodes);
|
||||
$this->fullyQualifyStmtsAnalyzer->process($nodes, $scope);
|
||||
if ($declare instanceof Declare_) {
|
||||
return [$declare, $namespace];
|
||||
}
|
||||
|
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '0e4a46d75ac336dfdfc268bf8c2019121593a7b2';
|
||||
public const PACKAGE_VERSION = 'dd970ac29023b0e6e27f54d79d98cf7415a638c5';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-05-11 19:22:49';
|
||||
public const RELEASE_DATE = '2023-05-11 19:33:06';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
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 ComposerAutoloaderInit1541611493e8c1217ebb7b54ee102dba::getLoader();
|
||||
return ComposerAutoloaderInitbf976720b7dcdf0b522d9622e6b2dff9::getLoader();
|
||||
|
|
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 ComposerAutoloaderInit1541611493e8c1217ebb7b54ee102dba
|
||||
class ComposerAutoloaderInitbf976720b7dcdf0b522d9622e6b2dff9
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,17 +22,17 @@ class ComposerAutoloaderInit1541611493e8c1217ebb7b54ee102dba
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit1541611493e8c1217ebb7b54ee102dba', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInitbf976720b7dcdf0b522d9622e6b2dff9', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit1541611493e8c1217ebb7b54ee102dba', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInitbf976720b7dcdf0b522d9622e6b2dff9', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit1541611493e8c1217ebb7b54ee102dba::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInitbf976720b7dcdf0b522d9622e6b2dff9::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit1541611493e8c1217ebb7b54ee102dba::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInitbf976720b7dcdf0b522d9622e6b2dff9::$files;
|
||||
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
|
8
vendor/composer/autoload_static.php
vendored
8
vendor/composer/autoload_static.php
vendored
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit1541611493e8c1217ebb7b54ee102dba
|
||||
class ComposerStaticInitbf976720b7dcdf0b522d9622e6b2dff9
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
|
@ -3109,9 +3109,9 @@ class ComposerStaticInit1541611493e8c1217ebb7b54ee102dba
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit1541611493e8c1217ebb7b54ee102dba::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit1541611493e8c1217ebb7b54ee102dba::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit1541611493e8c1217ebb7b54ee102dba::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInitbf976720b7dcdf0b522d9622e6b2dff9::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInitbf976720b7dcdf0b522d9622e6b2dff9::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInitbf976720b7dcdf0b522d9622e6b2dff9::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user