From 4d73ef43e26b43391619fbd5fd14994d5af2dac8 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Wed, 9 Feb 2022 12:17:46 +0000 Subject: [PATCH] Updated Rector to commit bc0eac36f4eece9f824efdb71c55ae59355d6a09 https://github.com/rectorphp/rector-src/commit/bc0eac36f4eece9f824efdb71c55ae59355d6a09 Fix PHPStan parser for different PHP version parsing (#1791) --- config/phpstan/parser.neon | 14 +----- ...radeJsonDecodeNullAssociativeArgRector.php | 47 ++++++------------- src/Application/VersionResolver.php | 4 +- vendor/autoload.php | 2 +- vendor/composer/autoload_real.php | 14 +++--- vendor/composer/autoload_static.php | 8 ++-- vendor/scoper-autoload.php | 10 ++-- 7 files changed, 34 insertions(+), 65 deletions(-) diff --git a/config/phpstan/parser.neon b/config/phpstan/parser.neon index b1f5eecd45e..623e87feb66 100644 --- a/config/phpstan/parser.neon +++ b/config/phpstan/parser.neon @@ -12,18 +12,11 @@ services: cachedNodesByStringCountMax: %cache.nodesByStringCountMax% autowired: false - cachedRectorSimpleParser: - class: PHPStan\Parser\CachedParser - arguments: - originalParser: @rectorSimpleParser - cachedNodesByStringCountMax: %cache.nodesByStringCountMax% - autowired: false - pathRoutingParser: class: PHPStan\Parser\PathRoutingParser arguments: currentPhpVersionRichParser: @cachedRectorParser - currentPhpVersionSimpleParser: @cachedRectorSimpleParser + currentPhpVersionSimpleParser: @cachedRectorParser php8Parser: @php8Parser autowired: false @@ -33,8 +26,3 @@ services: parser: @currentPhpVersionPhpParser lexer: @currentPhpVersionLexer autowired: no - - rectorSimpleParser: - class: PHPStan\Parser\SimpleParser - arguments: - parser: @currentPhpVersionPhpParser diff --git a/rules/DowngradePhp72/Rector/FuncCall/DowngradeJsonDecodeNullAssociativeArgRector.php b/rules/DowngradePhp72/Rector/FuncCall/DowngradeJsonDecodeNullAssociativeArgRector.php index 1a74b0c88fe..9be8f21b091 100644 --- a/rules/DowngradePhp72/Rector/FuncCall/DowngradeJsonDecodeNullAssociativeArgRector.php +++ b/rules/DowngradePhp72/Rector/FuncCall/DowngradeJsonDecodeNullAssociativeArgRector.php @@ -4,24 +4,19 @@ declare (strict_types=1); namespace Rector\DowngradePhp72\Rector\FuncCall; use PhpParser\Node; -use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\BinaryOp\Identical; -use PhpParser\Node\Expr\Cast\Bool_; use PhpParser\Node\Expr\ConstFetch; use PhpParser\Node\Expr\FuncCall; -use PhpParser\Node\Expr\PropertyFetch; -use PhpParser\Node\Expr\StaticPropertyFetch; -use PhpParser\Node\Expr\Variable; -use PhpParser\Node\Stmt\Expression; +use PhpParser\Node\Expr\Ternary; use PHPStan\Type\BooleanType; use Rector\Core\NodeAnalyzer\ArgsAnalyzer; -use Rector\Core\NodeManipulator\IfManipulator; use Rector\Core\Rector\AbstractRector; -use Rector\NodeTypeResolver\Node\AttributeKey; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * @see \Rector\Tests\DowngradePhp72\Rector\FuncCall\DowngradeJsonDecodeNullAssociativeArgRector\DowngradeJsonDecodeNullAssociativeArgRectorTest + * + * @changelog https://3v4l.org/b1mA6 */ final class DowngradeJsonDecodeNullAssociativeArgRector extends \Rector\Core\Rector\AbstractRector { @@ -30,21 +25,13 @@ final class DowngradeJsonDecodeNullAssociativeArgRector extends \Rector\Core\Rec * @var \Rector\Core\NodeAnalyzer\ArgsAnalyzer */ private $argsAnalyzer; - /** - * @readonly - * @var \Rector\Core\NodeManipulator\IfManipulator - */ - private $ifManipulator; - public function __construct(\Rector\Core\NodeAnalyzer\ArgsAnalyzer $argsAnalyzer, \Rector\Core\NodeManipulator\IfManipulator $ifManipulator) + public function __construct(\Rector\Core\NodeAnalyzer\ArgsAnalyzer $argsAnalyzer) { $this->argsAnalyzer = $argsAnalyzer; - $this->ifManipulator = $ifManipulator; } public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition { return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Downgrade json_decode() with null associative argument function', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample(<<<'CODE_SAMPLE' -declare(strict_types=1); - function exactlyNull(string $json) { $value = json_decode($json, null); @@ -56,8 +43,6 @@ function possiblyNull(string $json, ?bool $associative) } CODE_SAMPLE , <<<'CODE_SAMPLE' -declare(strict_types=1); - function exactlyNull(string $json) { $value = json_decode($json, true); @@ -65,10 +50,7 @@ function exactlyNull(string $json) function possiblyNull(string $json, ?bool $associative) { - if ($associative === null) { - $associative = true; - } - $value = json_decode($json, $associative); + $value = json_decode($json, $associative === null ?: $associative); } CODE_SAMPLE )]); @@ -96,23 +78,22 @@ CODE_SAMPLE return null; } $associativeValue = $args[1]->value; - if ($associativeValue instanceof \PhpParser\Node\Expr\Cast\Bool_) { + // already converted + if ($associativeValue instanceof \PhpParser\Node\Expr\Ternary && $associativeValue->if === null) { return null; } - $type = $this->nodeTypeResolver->getType($associativeValue); - if ($type instanceof \PHPStan\Type\BooleanType) { + $associativeValueType = $this->nodeTypeResolver->getType($associativeValue); + if ($associativeValueType instanceof \PHPStan\Type\BooleanType) { return null; } if ($associativeValue instanceof \PhpParser\Node\Expr\ConstFetch && $this->valueResolver->isNull($associativeValue)) { - $node->args[1]->value = $this->nodeFactory->createTrue(); + $args[1]->value = $this->nodeFactory->createTrue(); return $node; } - if (!\in_array(\get_class($associativeValue), [\PhpParser\Node\Expr\Variable::class, \PhpParser\Node\Expr\PropertyFetch::class, \PhpParser\Node\Expr\StaticPropertyFetch::class], \true)) { - return null; - } - $currentExpression = $node->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::CURRENT_STATEMENT); - $if = $this->ifManipulator->createIfExpr(new \PhpParser\Node\Expr\BinaryOp\Identical($associativeValue, $this->nodeFactory->createNull()), new \PhpParser\Node\Stmt\Expression(new \PhpParser\Node\Expr\Assign($associativeValue, $this->nodeFactory->createTrue()))); - $this->nodesToAddCollector->addNodeBeforeNode($if, $currentExpression); + // add conditional ternary + $nullIdentical = new \PhpParser\Node\Expr\BinaryOp\Identical($associativeValue, $this->nodeFactory->createNull()); + $ternary = new \PhpParser\Node\Expr\Ternary($nullIdentical, null, $associativeValue); + $args[1]->value = $ternary; return $node; } } diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 16afdfe479d..c44dbc9b405 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -16,11 +16,11 @@ final class VersionResolver /** * @var string */ - public const PACKAGE_VERSION = '94ef798f75158dae46d65d72bfcecb3b13c54e5a'; + public const PACKAGE_VERSION = 'bc0eac36f4eece9f824efdb71c55ae59355d6a09'; /** * @var string */ - public const RELEASE_DATE = '2022-02-09 00:59:39'; + public const RELEASE_DATE = '2022-02-09 12:09:37'; public static function resolvePackageVersion() : string { $process = new \RectorPrefix20220209\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__); diff --git a/vendor/autoload.php b/vendor/autoload.php index 708ac4d98f6..9a947cc4dc7 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -4,4 +4,4 @@ require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInit41f3f32042275afa1ccab66d160713f1::getLoader(); +return ComposerAutoloaderInit8ece194b09efc381d9934271b9692a3c::getLoader(); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index 08c46ccef24..0dc97e554e7 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInit41f3f32042275afa1ccab66d160713f1 +class ComposerAutoloaderInit8ece194b09efc381d9934271b9692a3c { private static $loader; @@ -22,15 +22,15 @@ class ComposerAutoloaderInit41f3f32042275afa1ccab66d160713f1 return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInit41f3f32042275afa1ccab66d160713f1', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInit8ece194b09efc381d9934271b9692a3c', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__))); - spl_autoload_unregister(array('ComposerAutoloaderInit41f3f32042275afa1ccab66d160713f1', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInit8ece194b09efc381d9934271b9692a3c', 'loadClassLoader')); $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); if ($useStaticLoader) { require __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInit41f3f32042275afa1ccab66d160713f1::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInit8ece194b09efc381d9934271b9692a3c::getInitializer($loader)); } else { $classMap = require __DIR__ . '/autoload_classmap.php'; if ($classMap) { @@ -42,12 +42,12 @@ class ComposerAutoloaderInit41f3f32042275afa1ccab66d160713f1 $loader->register(true); if ($useStaticLoader) { - $includeFiles = Composer\Autoload\ComposerStaticInit41f3f32042275afa1ccab66d160713f1::$files; + $includeFiles = Composer\Autoload\ComposerStaticInit8ece194b09efc381d9934271b9692a3c::$files; } else { $includeFiles = require __DIR__ . '/autoload_files.php'; } foreach ($includeFiles as $fileIdentifier => $file) { - composerRequire41f3f32042275afa1ccab66d160713f1($fileIdentifier, $file); + composerRequire8ece194b09efc381d9934271b9692a3c($fileIdentifier, $file); } return $loader; @@ -59,7 +59,7 @@ class ComposerAutoloaderInit41f3f32042275afa1ccab66d160713f1 * @param string $file * @return void */ -function composerRequire41f3f32042275afa1ccab66d160713f1($fileIdentifier, $file) +function composerRequire8ece194b09efc381d9934271b9692a3c($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 9adb7c5cee4..6bd933bce3c 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInit41f3f32042275afa1ccab66d160713f1 +class ComposerStaticInit8ece194b09efc381d9934271b9692a3c { public static $files = array ( '0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php', @@ -3865,9 +3865,9 @@ class ComposerStaticInit41f3f32042275afa1ccab66d160713f1 public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInit41f3f32042275afa1ccab66d160713f1::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInit41f3f32042275afa1ccab66d160713f1::$prefixDirsPsr4; - $loader->classMap = ComposerStaticInit41f3f32042275afa1ccab66d160713f1::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInit8ece194b09efc381d9934271b9692a3c::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInit8ece194b09efc381d9934271b9692a3c::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInit8ece194b09efc381d9934271b9692a3c::$classMap; }, null, ClassLoader::class); } diff --git a/vendor/scoper-autoload.php b/vendor/scoper-autoload.php index 46217b1dede..3044602e71d 100644 --- a/vendor/scoper-autoload.php +++ b/vendor/scoper-autoload.php @@ -9,8 +9,8 @@ $loader = require_once __DIR__.'/autoload.php'; if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) { spl_autoload_call('RectorPrefix20220209\AutoloadIncluder'); } -if (!class_exists('ComposerAutoloaderInit41f3f32042275afa1ccab66d160713f1', false) && !interface_exists('ComposerAutoloaderInit41f3f32042275afa1ccab66d160713f1', false) && !trait_exists('ComposerAutoloaderInit41f3f32042275afa1ccab66d160713f1', false)) { - spl_autoload_call('RectorPrefix20220209\ComposerAutoloaderInit41f3f32042275afa1ccab66d160713f1'); +if (!class_exists('ComposerAutoloaderInit8ece194b09efc381d9934271b9692a3c', false) && !interface_exists('ComposerAutoloaderInit8ece194b09efc381d9934271b9692a3c', false) && !trait_exists('ComposerAutoloaderInit8ece194b09efc381d9934271b9692a3c', false)) { + spl_autoload_call('RectorPrefix20220209\ComposerAutoloaderInit8ece194b09efc381d9934271b9692a3c'); } if (!class_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !interface_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !trait_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false)) { spl_autoload_call('RectorPrefix20220209\Helmich\TypoScriptParser\Parser\AST\Statement'); @@ -71,9 +71,9 @@ if (!function_exists('print_node')) { return \RectorPrefix20220209\print_node(...func_get_args()); } } -if (!function_exists('composerRequire41f3f32042275afa1ccab66d160713f1')) { - function composerRequire41f3f32042275afa1ccab66d160713f1() { - return \RectorPrefix20220209\composerRequire41f3f32042275afa1ccab66d160713f1(...func_get_args()); +if (!function_exists('composerRequire8ece194b09efc381d9934271b9692a3c')) { + function composerRequire8ece194b09efc381d9934271b9692a3c() { + return \RectorPrefix20220209\composerRequire8ece194b09efc381d9934271b9692a3c(...func_get_args()); } } if (!function_exists('scanPath')) {