Updated Rector to commit 5965ddd37bf4e44553822ae16165c2de4b052f42

5965ddd37b [TypeDeclaration] Add Closure support on ReturnTypeFromStrictParamRector (#4633)
This commit is contained in:
Tomas Votruba 2023-08-03 14:19:00 +00:00
parent 3619383db1
commit 8e45114f90
9 changed files with 61 additions and 33 deletions

View File

@ -7,10 +7,12 @@ use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\AssignRef;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\FunctionLike;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_;
use PhpParser\Node\Stmt\Return_;
@ -73,14 +75,14 @@ CODE_SAMPLE
*/
public function getNodeTypes() : array
{
return [ClassMethod::class, Function_::class];
return [ClassMethod::class, Function_::class, Closure::class];
}
public function provideMinPhpVersion() : int
{
return PhpVersionFeature::NULLABLE_TYPE;
}
/**
* @param ClassMethod|Function_ $node
* @param ClassMethod|Function_|Closure $node
*/
public function refactorWithScope(Node $node, Scope $scope) : ?Node
{
@ -119,14 +121,14 @@ CODE_SAMPLE
{
$return = null;
$this->traverseNodesWithCallable($stmts, static function (Node $node) use(&$return) : ?int {
if (!$node instanceof Return_) {
return null;
}
// skip scope nesting
if ($node instanceof FunctionLike) {
if ($node instanceof Class_ || $node instanceof FunctionLike) {
$return = null;
return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
}
if (!$node instanceof Return_) {
return null;
}
if (!$node->expr instanceof Variable) {
$return = null;
return NodeTraverser::STOP_TRAVERSAL;
@ -144,6 +146,10 @@ CODE_SAMPLE
$paramName = $this->getName($param);
$isParamModified = \false;
$this->traverseNodesWithCallable($stmts, function (Node $node) use($paramName, &$isParamModified) : ?int {
// skip scope nesting
if ($node instanceof Class_ || $node instanceof FunctionLike) {
return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
}
if ($node instanceof AssignRef && $this->isName($node->expr, $paramName)) {
$isParamModified = \true;
return NodeTraverser::STOP_TRAVERSAL;
@ -163,7 +169,7 @@ CODE_SAMPLE
return $isParamModified;
}
/**
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $node
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $node
*/
private function shouldSkipNode($node) : bool
{

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '79953f61e341fdb7263316b34eeaa2be737d12ef';
public const PACKAGE_VERSION = '5965ddd37bf4e44553822ae16165c2de4b052f42';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-08-03 21:00:56';
public const RELEASE_DATE = '2023-08-03 21:10:58';
/**
* @var int
*/

2
vendor/autoload.php vendored
View File

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

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitf3635f7070cdd35c0d9b3bdb494eb86c
class ComposerAutoloaderInit8fb289ced77cade3611c17e426037547
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInitf3635f7070cdd35c0d9b3bdb494eb86c
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitf3635f7070cdd35c0d9b3bdb494eb86c', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit8fb289ced77cade3611c17e426037547', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInitf3635f7070cdd35c0d9b3bdb494eb86c', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit8fb289ced77cade3611c17e426037547', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitf3635f7070cdd35c0d9b3bdb494eb86c::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit8fb289ced77cade3611c17e426037547::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInitf3635f7070cdd35c0d9b3bdb494eb86c::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInit8fb289ced77cade3611c17e426037547::$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 ComposerStaticInitf3635f7070cdd35c0d9b3bdb494eb86c
class ComposerStaticInit8fb289ced77cade3611c17e426037547
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -3025,9 +3025,9 @@ class ComposerStaticInitf3635f7070cdd35c0d9b3bdb494eb86c
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitf3635f7070cdd35c0d9b3bdb494eb86c::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitf3635f7070cdd35c0d9b3bdb494eb86c::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitf3635f7070cdd35c0d9b3bdb494eb86c::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit8fb289ced77cade3611c17e426037547::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit8fb289ced77cade3611c17e426037547::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit8fb289ced77cade3611c17e426037547::$classMap;
}, null, ClassLoader::class);
}

View File

@ -1986,12 +1986,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-downgrade-php.git",
"reference": "059d48366ee50115006a8d26ede574d70da724d2"
"reference": "c8cb23a7a65d236b24705fe507158864a1832533"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-downgrade-php\/zipball\/059d48366ee50115006a8d26ede574d70da724d2",
"reference": "059d48366ee50115006a8d26ede574d70da724d2",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-downgrade-php\/zipball\/c8cb23a7a65d236b24705fe507158864a1832533",
"reference": "c8cb23a7a65d236b24705fe507158864a1832533",
"shasum": ""
},
"require": {
@ -2016,7 +2016,7 @@
"tomasvotruba\/type-coverage": "^0.2",
"tomasvotruba\/unused-public": "^0.1"
},
"time": "2023-08-03T13:01:47+00:00",
"time": "2023-08-03T14:13:34+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {
@ -2043,7 +2043,7 @@
"description": "Rector downgrade PHP rules",
"support": {
"issues": "https:\/\/github.com\/rectorphp\/rector-downgrade-php\/issues",
"source": "https:\/\/github.com\/rectorphp\/rector-downgrade-php\/tree\/0.15.1"
"source": "https:\/\/github.com\/rectorphp\/rector-downgrade-php\/tree\/main"
},
"install-path": "..\/rector\/rector-downgrade-php"
},

File diff suppressed because one or more lines are too long

View File

@ -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 1c50ebb'), '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 059d483'), '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 0438162'), '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 1c50ebb'), '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 c8cb23a'), '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 0438162'), '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()
{
}

View File

@ -31,6 +31,7 @@ use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @changelog https://www.php.net/manual/en/function.array-filter.php#refsect1-function.array-filter-changelog
* @see https://3v4l.org/lqHFA
*
* @see \Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeArrayFilterNullableCallbackRector\DowngradeArrayFilterNullableCallbackRectorTest
*/
@ -93,20 +94,24 @@ CODE_SAMPLE
return null;
}
// direct null check ConstFetch
if ($args[1]->value instanceof ConstFetch && $this->valueResolver->isNull($args[1]->value)) {
$secondArg = $args[1];
if ($secondArg->value instanceof ConstFetch && $this->valueResolver->isNull($secondArg->value)) {
$args = [$args[0]];
$node->args = $args;
return $node;
}
if ($this->shouldSkipSecondArg($args[1]->value)) {
if ($this->shouldSkip($secondArg->value)) {
return null;
}
$node->args[1] = new Arg($this->createNewArgFirstTernary($args));
$node->args[2] = new Arg($this->createNewArgSecondTernary($args));
return $node;
}
private function shouldSkipSecondArg(Expr $expr) : bool
private function shouldSkip(Expr $expr) : bool
{
if ($this->isAlreadyConditionedToNull($expr)) {
return \true;
}
if (\in_array(\get_class($expr), [String_::class, Closure::class, ArrowFunction::class, Array_::class], \true)) {
return \true;
}
@ -119,10 +124,9 @@ CODE_SAMPLE
private function createNewArgFirstTernary(array $args) : Ternary
{
$identical = new Identical($args[1]->value, $this->nodeFactory->createNull());
$vVariable = new Variable('v');
$arrowFunction = new ArrowFunction(['expr' => new BooleanNot(new Empty_($vVariable))]);
$arrowFunction->params = [new Param($vVariable), new Param(new Variable('k'))];
$arrowFunction->returnType = new Identifier('bool');
$dummyVariable = new Variable('value');
$booleanNot = new BooleanNot(new Empty_($dummyVariable));
$arrowFunction = $this->createArrowFunction($booleanNot, $dummyVariable);
return new Ternary($identical, $arrowFunction, $args[1]->value);
}
/**
@ -134,4 +138,22 @@ CODE_SAMPLE
$constFetch = new ConstFetch(new Name('ARRAY_FILTER_USE_BOTH'));
return new Ternary($identical, $constFetch, isset($args[2]) ? $args[2]->value : new LNumber(0));
}
private function isAlreadyConditionedToNull(Expr $expr) : bool
{
if (!$expr instanceof Ternary) {
return \false;
}
if (!$expr->cond instanceof Identical) {
return \false;
}
$identical = $expr->cond;
return $this->valueResolver->isNull($identical->right);
}
private function createArrowFunction(BooleanNot $booleanNot, Variable $dummyVariable) : ArrowFunction
{
$arrowFunction = new ArrowFunction(['expr' => $booleanNot]);
$arrowFunction->params = [new Param($dummyVariable), new Param(new Variable('key'))];
$arrowFunction->returnType = new Identifier('bool');
return $arrowFunction;
}
}