Updated Rector to commit c0a042c3b68eb657d7e525ae2c2648d0ec96fb19

c0a042c3b6 Drop AttributeKey::SCOPE in MagicPropertyFetchAnalyzer (#3868)
This commit is contained in:
Tomas Votruba 2023-05-16 10:36:59 +00:00
parent 1c94a7b40a
commit ddec6bfaa0
6 changed files with 27 additions and 31 deletions

View File

@ -9,11 +9,13 @@ use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\Variable;
use PHPStan\Analyser\Scope;
use PHPStan\Type\ObjectType;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\NodeAnalyzer\PropertyFetchAnalyzer;
use Rector\Core\NodeManipulator\MagicPropertyFetchAnalyzer;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\Rector\AbstractScopeAwareRector;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Transform\ValueObject\GetAndSetToMethodCall;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
@ -22,7 +24,7 @@ use RectorPrefix202305\Webmozart\Assert\Assert;
/**
* @see \Rector\Tests\Transform\Rector\Assign\GetAndSetToMethodCallRector\GetAndSetToMethodCallRectorTest
*/
final class GetAndSetToMethodCallRector extends AbstractRector implements ConfigurableRectorInterface
final class GetAndSetToMethodCallRector extends AbstractScopeAwareRector implements ConfigurableRectorInterface
{
/**
* @var GetAndSetToMethodCall[]
@ -65,15 +67,15 @@ CODE_SAMPLE
/**
* @param Assign|PropertyFetch $node
*/
public function refactor(Node $node) : ?Node
public function refactorWithScope(Node $node, Scope $scope) : ?Node
{
if ($node instanceof Assign) {
if ($node->var instanceof PropertyFetch) {
return $this->processMagicSet($node->expr, $node->var);
return $this->processMagicSet($node->expr, $node->var, $scope);
}
return null;
}
return $this->processPropertyFetch($node);
return $this->processPropertyFetch($node, $scope);
}
/**
* @param mixed[] $configuration
@ -83,22 +85,22 @@ CODE_SAMPLE
Assert::allIsAOf($configuration, GetAndSetToMethodCall::class);
$this->getAndSetToMethodCalls = $configuration;
}
private function processMagicSet(Expr $expr, PropertyFetch $propertyFetch) : ?Node
private function processMagicSet(Expr $expr, PropertyFetch $propertyFetch, Scope $scope) : ?Node
{
foreach ($this->getAndSetToMethodCalls as $getAndSetToMethodCall) {
$objectType = $getAndSetToMethodCall->getObjectType();
if ($this->shouldSkipPropertyFetch($propertyFetch, $objectType)) {
if ($this->shouldSkipPropertyFetch($propertyFetch, $objectType, $scope)) {
continue;
}
return $this->createMethodCallNodeFromAssignNode($propertyFetch, $expr, $getAndSetToMethodCall->getSetMethod());
}
return null;
}
private function processPropertyFetch(PropertyFetch $propertyFetch) : ?MethodCall
private function processPropertyFetch(PropertyFetch $propertyFetch, Scope $scope) : ?MethodCall
{
$parentNode = $propertyFetch->getAttribute(AttributeKey::PARENT_NODE);
foreach ($this->getAndSetToMethodCalls as $getAndSetToMethodCall) {
if ($this->shouldSkipPropertyFetch($propertyFetch, $getAndSetToMethodCall->getObjectType())) {
if ($this->shouldSkipPropertyFetch($propertyFetch, $getAndSetToMethodCall->getObjectType(), $scope)) {
continue;
}
// setter, skip
@ -111,12 +113,12 @@ CODE_SAMPLE
}
return null;
}
private function shouldSkipPropertyFetch(PropertyFetch $propertyFetch, ObjectType $objectType) : bool
private function shouldSkipPropertyFetch(PropertyFetch $propertyFetch, ObjectType $objectType, Scope $scope) : bool
{
if (!$this->isObjectType($propertyFetch->var, $objectType)) {
return \true;
}
if (!$this->magicPropertyFetchAnalyzer->isMagicOnType($propertyFetch, $objectType)) {
if (!$this->magicPropertyFetchAnalyzer->isMagicOnType($propertyFetch, $objectType, $scope)) {
return \true;
}
return $this->propertyFetchAnalyzer->isPropertyToSelf($propertyFetch);

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = 'ef257221acece7d2ea66c292fceb2718c87e0b53';
public const PACKAGE_VERSION = 'c0a042c3b68eb657d7e525ae2c2648d0ec96fb19';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-05-16 10:27:10';
public const RELEASE_DATE = '2023-05-16 12:32:32';
/**
* @var int
*/

View File

@ -11,9 +11,7 @@ use PHPStan\Type\ErrorType;
use PHPStan\Type\MixedType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\TypeWithClassName;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\NodeTypeResolver\NodeTypeResolver;
/**
* Utils for PropertyFetch Node:
@ -42,7 +40,7 @@ final class MagicPropertyFetchAnalyzer
$this->nodeTypeResolver = $nodeTypeResolver;
$this->reflectionProvider = $reflectionProvider;
}
public function isMagicOnType(PropertyFetch $propertyFetch, ObjectType $objectType) : bool
public function isMagicOnType(PropertyFetch $propertyFetch, ObjectType $objectType, Scope $scope) : bool
{
$varNodeType = $this->nodeTypeResolver->getType($propertyFetch);
if ($varNodeType instanceof ErrorType) {
@ -58,17 +56,13 @@ final class MagicPropertyFetchAnalyzer
if ($nodeName === null) {
return \false;
}
return !$this->hasPublicProperty($propertyFetch, $nodeName);
return !$this->hasPublicProperty($propertyFetch, $nodeName, $scope);
}
/**
* @param \PhpParser\Node\Expr\PropertyFetch|\PhpParser\Node\Expr\StaticPropertyFetch $expr
*/
private function hasPublicProperty($expr, string $propertyName) : bool
private function hasPublicProperty($expr, string $propertyName, Scope $scope) : bool
{
$scope = $expr->getAttribute(AttributeKey::SCOPE);
if (!$scope instanceof Scope) {
throw new ShouldNotHappenException();
}
if ($expr instanceof PropertyFetch) {
$propertyFetchType = $scope->getType($expr->var);
} else {

2
vendor/autoload.php vendored
View File

@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit2ce54a6325f982a5ff5f31046b3d06cd::getLoader();
return ComposerAutoloaderInitbecc49e92c90914d9f48d7a2c7da99f5::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit2ce54a6325f982a5ff5f31046b3d06cd
class ComposerAutoloaderInitbecc49e92c90914d9f48d7a2c7da99f5
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInit2ce54a6325f982a5ff5f31046b3d06cd
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit2ce54a6325f982a5ff5f31046b3d06cd', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInitbecc49e92c90914d9f48d7a2c7da99f5', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit2ce54a6325f982a5ff5f31046b3d06cd', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInitbecc49e92c90914d9f48d7a2c7da99f5', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit2ce54a6325f982a5ff5f31046b3d06cd::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInitbecc49e92c90914d9f48d7a2c7da99f5::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInit2ce54a6325f982a5ff5f31046b3d06cd::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInitbecc49e92c90914d9f48d7a2c7da99f5::$files;
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInit2ce54a6325f982a5ff5f31046b3d06cd
class ComposerStaticInitbecc49e92c90914d9f48d7a2c7da99f5
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -3103,9 +3103,9 @@ class ComposerStaticInit2ce54a6325f982a5ff5f31046b3d06cd
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit2ce54a6325f982a5ff5f31046b3d06cd::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit2ce54a6325f982a5ff5f31046b3d06cd::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit2ce54a6325f982a5ff5f31046b3d06cd::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInitbecc49e92c90914d9f48d7a2c7da99f5::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitbecc49e92c90914d9f48d7a2c7da99f5::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitbecc49e92c90914d9f48d7a2c7da99f5::$classMap;
}, null, ClassLoader::class);
}