From d7eced92e22c2aea65fd900c1f420c26589480d8 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Wed, 24 May 2023 09:36:58 +0000 Subject: [PATCH] Updated Rector to commit c504b2f11f2b732a744ad804b3a4b5afc30e2841 https://github.com/rectorphp/rector-src/commit/c504b2f11f2b732a744ad804b3a4b5afc30e2841 Refactor PARENT_NODE away from GetClassOnNullRector (#3944) --- .../Rector/FuncCall/GetClassOnNullRector.php | 119 ++++++------------ .../AddVoidReturnTypeWhereNoReturnRector.php | 2 - src/Application/VersionResolver.php | 4 +- vendor/autoload.php | 2 +- vendor/bin/neon-lint | 5 +- vendor/bin/php-parse | 5 +- vendor/bin/phpstan | 5 +- vendor/bin/phpstan.phar | 5 +- vendor/composer/autoload_real.php | 10 +- vendor/composer/autoload_static.php | 8 +- 10 files changed, 55 insertions(+), 110 deletions(-) diff --git a/rules/Php72/Rector/FuncCall/GetClassOnNullRector.php b/rules/Php72/Rector/FuncCall/GetClassOnNullRector.php index e287713fc36..edf724e0f0d 100644 --- a/rules/Php72/Rector/FuncCall/GetClassOnNullRector.php +++ b/rules/Php72/Rector/FuncCall/GetClassOnNullRector.php @@ -5,11 +5,11 @@ namespace Rector\Php72\Rector\FuncCall; use PhpParser\Node; use PhpParser\Node\Arg; -use PhpParser\Node\Expr\BinaryOp\Identical; use PhpParser\Node\Expr\BinaryOp\NotIdentical; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\Ternary; use PhpParser\Node\Stmt\Class_; +use PhpParser\NodeTraverser; use PHPStan\Analyser\Scope; use PHPStan\Type\NullType; use Rector\Core\Rector\AbstractScopeAwareRector; @@ -58,55 +58,47 @@ CODE_SAMPLE */ public function getNodeTypes() : array { - return [FuncCall::class]; + return [Class_::class]; } /** - * @param FuncCall $node + * @param Class_ $node */ public function refactorWithScope(Node $node, Scope $scope) : ?Node { - if (!$this->isName($node, 'get_class')) { - return null; - } - if (!isset($node->getArgs()[0])) { - return null; - } - $firstArg = $node->getArgs()[0]; - $firstArgValue = $firstArg->value; - if (!$scope->isInClass()) { - return null; - } - // possibly already changed - if ($this->shouldSkip($node)) { - return null; - } - $firstArgType = $this->getType($firstArgValue); - if (!$this->nodeTypeResolver->isNullableType($firstArgValue) && !$firstArgType instanceof NullType) { - return null; - } - $notIdentical = new NotIdentical($firstArgValue, $this->nodeFactory->createNull()); - $funcCall = $this->createGetClassFuncCall($node); - $selfClassConstFetch = $this->nodeFactory->createClassConstReference('self'); - return new Ternary($notIdentical, $funcCall, $selfClassConstFetch); - } - private function shouldSkip(FuncCall $funcCall) : bool - { - $isJustAdded = (bool) $funcCall->getAttribute(AttributeKey::DO_NOT_CHANGE); - if ($isJustAdded) { - return \true; - } - $classLike = $this->betterNodeFinder->findParentType($funcCall, Class_::class); - if (!$classLike instanceof Class_) { - return \true; - } - $parentNode = $funcCall->getAttribute(AttributeKey::PARENT_NODE); - if ($parentNode instanceof Ternary) { - if ($this->isIdenticalToNotNull($funcCall, $parentNode)) { - return \true; + $hasChanged = \false; + $this->traverseNodesWithCallable($node, function (Node $node) use(&$hasChanged) { + if ($node instanceof Ternary) { + return NodeTraverser::STOP_TRAVERSAL; } - return $this->isNotIdenticalToNull($funcCall, $parentNode); + if (!$node instanceof FuncCall) { + return null; + } + // just created func call + if ($node->getAttribute(AttributeKey::DO_NOT_CHANGE) === \true) { + return null; + } + if (!$this->isName($node, 'get_class')) { + return null; + } + $firstArg = $node->getArgs()[0] ?? null; + if (!$firstArg instanceof Arg) { + return null; + } + $firstArgValue = $firstArg->value; + $firstArgType = $this->getType($firstArgValue); + if (!$this->nodeTypeResolver->isNullableType($firstArgValue) && !$firstArgType instanceof NullType) { + return null; + } + $notIdentical = new NotIdentical($firstArgValue, $this->nodeFactory->createNull()); + $funcCall = $this->createGetClassFuncCall($node); + $selfClassConstFetch = $this->nodeFactory->createClassConstReference('self'); + $hasChanged = \true; + return new Ternary($notIdentical, $funcCall, $selfClassConstFetch); + }); + if ($hasChanged) { + return $node; } - return \false; + return null; } private function createGetClassFuncCall(FuncCall $oldFuncCall) : FuncCall { @@ -114,45 +106,4 @@ CODE_SAMPLE $funcCall->setAttribute(AttributeKey::DO_NOT_CHANGE, \true); return $funcCall; } - /** - * E.g. "$value === [!null] ? get_class($value)" - */ - private function isIdenticalToNotNull(FuncCall $funcCall, Ternary $ternary) : bool - { - if (!$ternary->cond instanceof Identical) { - return \false; - } - if (!isset($funcCall->getArgs()[0])) { - return \false; - } - if ($this->nodeComparator->areNodesEqual($ternary->cond->left, $funcCall->getArgs()[0]->value) && !$this->valueResolver->isNull($ternary->cond->right)) { - return \true; - } - if (!$this->nodeComparator->areNodesEqual($ternary->cond->right, $funcCall->getArgs()[0]->value)) { - return \false; - } - return !$this->valueResolver->isNull($ternary->cond->left); - } - /** - * E.g. "$value !== null ? get_class($value)" - */ - private function isNotIdenticalToNull(FuncCall $funcCall, Ternary $ternary) : bool - { - if (!$ternary->cond instanceof NotIdentical) { - return \false; - } - if (!isset($funcCall->getArgs()[0])) { - return \false; - } - if (!$funcCall->args[0] instanceof Arg) { - return \false; - } - if ($this->nodeComparator->areNodesEqual($ternary->cond->left, $funcCall->args[0]->value) && $this->valueResolver->isNull($ternary->cond->right)) { - return \true; - } - if (!$this->nodeComparator->areNodesEqual($ternary->cond->right, $funcCall->args[0]->value)) { - return \false; - } - return $this->valueResolver->isNull($ternary->cond->left); - } } diff --git a/rules/TypeDeclaration/Rector/ClassMethod/AddVoidReturnTypeWhereNoReturnRector.php b/rules/TypeDeclaration/Rector/ClassMethod/AddVoidReturnTypeWhereNoReturnRector.php index 97810bd66d1..c16fcd1f992 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/AddVoidReturnTypeWhereNoReturnRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/AddVoidReturnTypeWhereNoReturnRector.php @@ -6,7 +6,6 @@ namespace Rector\TypeDeclaration\Rector\ClassMethod; use PhpParser\Node; use PhpParser\Node\Expr\Closure; use PhpParser\Node\Identifier; -use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Function_; use PHPStan\Reflection\ClassReflection; @@ -17,7 +16,6 @@ use Rector\Core\Contract\Rector\AllowEmptyConfigurableRectorInterface; use Rector\Core\Rector\AbstractRector; use Rector\Core\Reflection\ReflectionResolver; use Rector\Core\ValueObject\PhpVersionFeature; -use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\TypeDeclaration\TypeInferer\SilentVoidResolver; use Rector\VendorLocker\NodeVendorLocker\ClassMethodReturnVendorLockResolver; use Rector\VersionBonding\Contract\MinPhpVersionInterface; diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index a30e5255bc0..369b2515b6a 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -19,12 +19,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = '3eadce164860c1d4465e40fd5e07fb11d3aa1b99'; + public const PACKAGE_VERSION = 'c504b2f11f2b732a744ad804b3a4b5afc30e2841'; /** * @api * @var string */ - public const RELEASE_DATE = '2023-05-24 04:15:17'; + public const RELEASE_DATE = '2023-05-24 09:31:55'; /** * @var int */ diff --git a/vendor/autoload.php b/vendor/autoload.php index 77be95bd0db..aaa12dece8f 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) { require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInitb7b74474b87e58ef937ad854d6d77003::getLoader(); +return ComposerAutoloaderInitd1e79f67f253438ff69fc93ef401a7af::getLoader(); diff --git a/vendor/bin/neon-lint b/vendor/bin/neon-lint index 778204aebad..10b1dfce098 100644 --- a/vendor/bin/neon-lint +++ b/vendor/bin/neon-lint @@ -88,8 +88,7 @@ if (\PHP_VERSION_ID < 80000) { } } if (\function_exists('stream_get_wrappers') && \in_array('phpvfscomposer', \stream_get_wrappers(), \true) || \function_exists('stream_wrapper_register') && \stream_wrapper_register('phpvfscomposer', 'RectorPrefix202305\\Composer\\BinProxyWrapper')) { - include "phpvfscomposer://" . __DIR__ . '/..' . '/nette/neon/bin/neon-lint'; - exit(0); + return include "phpvfscomposer://" . __DIR__ . '/..' . '/nette/neon/bin/neon-lint'; } } -include __DIR__ . '/..' . '/nette/neon/bin/neon-lint'; +return include __DIR__ . '/..' . '/nette/neon/bin/neon-lint'; diff --git a/vendor/bin/php-parse b/vendor/bin/php-parse index 97a25344bfc..616d1d504b6 100644 --- a/vendor/bin/php-parse +++ b/vendor/bin/php-parse @@ -88,8 +88,7 @@ if (\PHP_VERSION_ID < 80000) { } } if (\function_exists('stream_get_wrappers') && \in_array('phpvfscomposer', \stream_get_wrappers(), \true) || \function_exists('stream_wrapper_register') && \stream_wrapper_register('phpvfscomposer', 'RectorPrefix202305\\Composer\\BinProxyWrapper')) { - include "phpvfscomposer://" . __DIR__ . '/..' . '/nikic/php-parser/bin/php-parse'; - exit(0); + return include "phpvfscomposer://" . __DIR__ . '/..' . '/nikic/php-parser/bin/php-parse'; } } -include __DIR__ . '/..' . '/nikic/php-parser/bin/php-parse'; +return include __DIR__ . '/..' . '/nikic/php-parser/bin/php-parse'; diff --git a/vendor/bin/phpstan b/vendor/bin/phpstan index 7299c940cfa..567cd088bab 100644 --- a/vendor/bin/phpstan +++ b/vendor/bin/phpstan @@ -88,8 +88,7 @@ if (\PHP_VERSION_ID < 80000) { } } if (\function_exists('stream_get_wrappers') && \in_array('phpvfscomposer', \stream_get_wrappers(), \true) || \function_exists('stream_wrapper_register') && \stream_wrapper_register('phpvfscomposer', 'RectorPrefix202305\\Composer\\BinProxyWrapper')) { - include "phpvfscomposer://" . __DIR__ . '/..' . '/phpstan/phpstan/phpstan'; - exit(0); + return include "phpvfscomposer://" . __DIR__ . '/..' . '/phpstan/phpstan/phpstan'; } } -include __DIR__ . '/..' . '/phpstan/phpstan/phpstan'; +return include __DIR__ . '/..' . '/phpstan/phpstan/phpstan'; diff --git a/vendor/bin/phpstan.phar b/vendor/bin/phpstan.phar index caa3e24f8ab..fecf96f69d9 100644 --- a/vendor/bin/phpstan.phar +++ b/vendor/bin/phpstan.phar @@ -112,9 +112,8 @@ if (PHP_VERSION_ID < 80000) { (function_exists('stream_get_wrappers') && in_array('phpvfscomposer', stream_get_wrappers(), true)) || (function_exists('stream_wrapper_register') && stream_wrapper_register('phpvfscomposer', 'Composer\BinProxyWrapper')) ) { - include("phpvfscomposer://" . __DIR__ . '/..'.'/phpstan/phpstan/phpstan.phar'); - exit(0); + return include("phpvfscomposer://" . __DIR__ . '/..'.'/phpstan/phpstan/phpstan.phar'); } } -include __DIR__ . '/..'.'/phpstan/phpstan/phpstan.phar'; +return include __DIR__ . '/..'.'/phpstan/phpstan/phpstan.phar'; diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index 61133331d15..991e096d065 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInitb7b74474b87e58ef937ad854d6d77003 +class ComposerAutoloaderInitd1e79f67f253438ff69fc93ef401a7af { private static $loader; @@ -22,17 +22,17 @@ class ComposerAutoloaderInitb7b74474b87e58ef937ad854d6d77003 return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInitb7b74474b87e58ef937ad854d6d77003', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInitd1e79f67f253438ff69fc93ef401a7af', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); - spl_autoload_unregister(array('ComposerAutoloaderInitb7b74474b87e58ef937ad854d6d77003', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInitd1e79f67f253438ff69fc93ef401a7af', 'loadClassLoader')); require __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInitb7b74474b87e58ef937ad854d6d77003::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInitd1e79f67f253438ff69fc93ef401a7af::getInitializer($loader)); $loader->setClassMapAuthoritative(true); $loader->register(true); - $filesToLoad = \Composer\Autoload\ComposerStaticInitb7b74474b87e58ef937ad854d6d77003::$files; + $filesToLoad = \Composer\Autoload\ComposerStaticInitd1e79f67f253438ff69fc93ef401a7af::$files; $requireFile = \Closure::bind(static function ($fileIdentifier, $file) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index f9e31cde4f4..ff29701d6a4 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInitb7b74474b87e58ef937ad854d6d77003 +class ComposerStaticInitd1e79f67f253438ff69fc93ef401a7af { public static $files = array ( 'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php', @@ -3106,9 +3106,9 @@ class ComposerStaticInitb7b74474b87e58ef937ad854d6d77003 public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInitb7b74474b87e58ef937ad854d6d77003::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInitb7b74474b87e58ef937ad854d6d77003::$prefixDirsPsr4; - $loader->classMap = ComposerStaticInitb7b74474b87e58ef937ad854d6d77003::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInitd1e79f67f253438ff69fc93ef401a7af::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInitd1e79f67f253438ff69fc93ef401a7af::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInitd1e79f67f253438ff69fc93ef401a7af::$classMap; }, null, ClassLoader::class); }