Updated Rector to commit 529defd2de2b8ea122d0d7326ca0b054a22a030d

529defd2de [TypeDeclaration] Using native type scope get on ReturnTypeInferer (#4648)
This commit is contained in:
Tomas Votruba 2023-08-04 14:11:13 +00:00
parent 5ed75de032
commit b2fa3fba80
13 changed files with 36 additions and 48 deletions

View File

@ -197,7 +197,7 @@ final class ReturnTypeInferer
foreach ($returnsWithExpr as $returnWithExpr) {
/** @var Expr $expr */
$expr = $returnWithExpr->expr;
$type = $this->nodeTypeResolver->getType($expr);
$type = $this->nodeTypeResolver->getNativeType($expr);
if (!$type instanceof BenevolentUnionType) {
return $unionType;
}

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\ArrowFunction;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\FunctionLike;
@ -95,7 +96,7 @@ final class ReturnedNodesReturnTypeInfererTypeInferer
return $this->resolveNoLocalReturnNodes($classReflection, $functionLike);
}
foreach ($localReturnNodes as $localReturnNode) {
$returnedExprType = $this->nodeTypeResolver->getType($localReturnNode);
$returnedExprType = $localReturnNode->expr instanceof Expr ? $this->nodeTypeResolver->getNativeType($localReturnNode->expr) : $this->nodeTypeResolver->getType($localReturnNode);
$returnedExprType = $this->correctWithNestedType($returnedExprType, $localReturnNode, $functionLike);
$types[] = $this->splArrayFixedTypeNarrower->narrow($returnedExprType);
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = 'ae767eb1fe01f65c9d5a1e5c2a4c067e95b5386e';
public const PACKAGE_VERSION = '529defd2de2b8ea122d0d7326ca0b054a22a030d';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-08-04 13:19:03';
public const RELEASE_DATE = '2023-08-04 21:07:35';
/**
* @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 ComposerAutoloaderInit71f0f2a7e0ed04e361f293b6bf815620::getLoader();
return ComposerAutoloaderInitaed1c703ebc52bf0bfb9c0829d01beb1::getLoader();

View File

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

View File

@ -1986,12 +1986,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-downgrade-php.git",
"reference": "84f216de0340817b2e2b3572069fe8846d59e254"
"reference": "8df23f0cabdf045dc4e131f8aa9a4f8e3c61295c"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-downgrade-php\/zipball\/84f216de0340817b2e2b3572069fe8846d59e254",
"reference": "84f216de0340817b2e2b3572069fe8846d59e254",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-downgrade-php\/zipball\/8df23f0cabdf045dc4e131f8aa9a4f8e3c61295c",
"reference": "8df23f0cabdf045dc4e131f8aa9a4f8e3c61295c",
"shasum": ""
},
"require": {
@ -2000,6 +2000,7 @@
"require-dev": {
"phpstan\/extension-installer": "^1.3",
"phpstan\/phpstan": "^1.9",
"phpstan\/phpstan-deprecation-rules": "^1.1",
"phpstan\/phpstan-webmozart-assert": "^1.2",
"phpunit\/phpunit": "^10.1",
"rector\/phpstan-rules": "^0.6",
@ -2016,7 +2017,7 @@
"tomasvotruba\/type-coverage": "^0.2",
"tomasvotruba\/unused-public": "^0.1"
},
"time": "2023-08-04T13:26:26+00:00",
"time": "2023-08-04T13:45:50+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {

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 84f216d'), '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 8df23f0'), '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

@ -9,6 +9,7 @@
"require-dev": {
"phpstan\/extension-installer": "^1.3",
"phpstan\/phpstan": "^1.9",
"phpstan\/phpstan-deprecation-rules": "^1.1",
"phpstan\/phpstan-webmozart-assert": "^1.2",
"phpunit\/phpunit": "^10.1",
"rector\/phpstan-rules": "^0.6",

View File

@ -19,7 +19,6 @@ use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\ClassConst;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\If_;
use Rector\Core\NodeManipulator\IfManipulator;
use Rector\Core\Rector\AbstractRector;
use Rector\DowngradePhp72\NodeAnalyzer\RegexFuncAnalyzer;
use Rector\DowngradePhp72\NodeManipulator\BitwiseFlagCleaner;
@ -30,11 +29,6 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
*/
final class DowngradePregUnmatchedAsNullConstantRector extends AbstractRector
{
/**
* @readonly
* @var \Rector\Core\NodeManipulator\IfManipulator
*/
private $ifManipulator;
/**
* @readonly
* @var \Rector\DowngradePhp72\NodeManipulator\BitwiseFlagCleaner
@ -50,9 +44,8 @@ final class DowngradePregUnmatchedAsNullConstantRector extends AbstractRector
* @var string
*/
private const UNMATCHED_NULL_FLAG = 'PREG_UNMATCHED_AS_NULL';
public function __construct(IfManipulator $ifManipulator, BitwiseFlagCleaner $bitwiseFlagCleaner, RegexFuncAnalyzer $regexFuncAnalyzer)
public function __construct(BitwiseFlagCleaner $bitwiseFlagCleaner, RegexFuncAnalyzer $regexFuncAnalyzer)
{
$this->ifManipulator = $ifManipulator;
$this->bitwiseFlagCleaner = $bitwiseFlagCleaner;
$this->regexFuncAnalyzer = $regexFuncAnalyzer;
}
@ -150,7 +143,7 @@ CODE_SAMPLE
{
$variablePass = new Variable('value');
$assign = new Assign($variablePass, $this->nodeFactory->createNull());
$if = $this->ifManipulator->createIfStmt(new Identical($variablePass, new String_('')), new Expression($assign));
$if = $this->createIf($variablePass, $assign);
$param = new Param($variablePass, null, null, \true);
$closure = new Closure(['params' => [$param], 'stmts' => [$if]]);
$arguments = $this->nodeFactory->createArgs([$variable, $closure]);
@ -200,4 +193,9 @@ CODE_SAMPLE
}
return null;
}
private function createIf(Variable $variable, Assign $assign) : If_
{
$conditionIdentical = new Identical($variable, new String_(''));
return new If_($conditionIdentical, ['stmts' => [new Expression($assign)]]);
}
}

View File

@ -23,7 +23,6 @@ use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\Return_;
use Rector\Core\NodeManipulator\BinaryOpManipulator;
use Rector\Core\NodeManipulator\IfManipulator;
use Rector\Core\Rector\AbstractRector;
use Rector\NodeAnalyzer\CoalesceAnalyzer;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
@ -35,11 +34,6 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
*/
final class DowngradeThrowExprRector extends AbstractRector
{
/**
* @readonly
* @var \Rector\Core\NodeManipulator\IfManipulator
*/
private $ifManipulator;
/**
* @readonly
* @var \Rector\NodeAnalyzer\CoalesceAnalyzer
@ -50,9 +44,8 @@ final class DowngradeThrowExprRector extends AbstractRector
* @var \Rector\Core\NodeManipulator\BinaryOpManipulator
*/
private $binaryOpManipulator;
public function __construct(IfManipulator $ifManipulator, CoalesceAnalyzer $coalesceAnalyzer, BinaryOpManipulator $binaryOpManipulator)
public function __construct(CoalesceAnalyzer $coalesceAnalyzer, BinaryOpManipulator $binaryOpManipulator)
{
$this->ifManipulator = $ifManipulator;
$this->coalesceAnalyzer = $coalesceAnalyzer;
$this->binaryOpManipulator = $binaryOpManipulator;
}
@ -131,7 +124,7 @@ CODE_SAMPLE
return null;
}
$inversedTernaryExpr = $this->binaryOpManipulator->inverseNode($ternary->cond);
$if = $this->ifManipulator->createIfStmt($inversedTernaryExpr, new Expression($ternary->else));
$if = new If_($inversedTernaryExpr, ['stmts' => [new Expression($ternary->else)]]);
if (!$assign instanceof Assign) {
return $if;
}
@ -150,7 +143,7 @@ CODE_SAMPLE
return null;
}
$condExpr = $this->createCondExpr($coalesce);
$if = $this->ifManipulator->createIfStmt($condExpr, new Expression($coalesce->right));
$if = new If_($condExpr, ['stmts' => [new Expression($coalesce->right)]]);
if (!$assign instanceof Assign) {
return $if;
}

View File

@ -20,7 +20,6 @@ use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\If_;
use PHPStan\Type\ObjectType;
use Rector\Core\NodeManipulator\IfManipulator;
use Rector\Core\Rector\AbstractRector;
use Rector\Naming\Naming\VariableNaming;
use Rector\NodeCollector\BinaryOpConditionsCollector;
@ -37,11 +36,6 @@ final class DowngradeReflectionClassGetConstantsFilterRector extends AbstractRec
* @var \Rector\Naming\Naming\VariableNaming
*/
private $variableNaming;
/**
* @readonly
* @var \Rector\Core\NodeManipulator\IfManipulator
*/
private $ifManipulator;
/**
* @readonly
* @var \Rector\NodeCollector\BinaryOpConditionsCollector
@ -51,10 +45,9 @@ final class DowngradeReflectionClassGetConstantsFilterRector extends AbstractRec
* @var array<string, string>
*/
private const MAP_CONSTANT_TO_METHOD = ['IS_PUBLIC' => 'isPublic', 'IS_PROTECTED' => 'isProtected', 'IS_PRIVATE' => 'isPrivate'];
public function __construct(VariableNaming $variableNaming, IfManipulator $ifManipulator, BinaryOpConditionsCollector $binaryOpConditionsCollector)
public function __construct(VariableNaming $variableNaming, BinaryOpConditionsCollector $binaryOpConditionsCollector)
{
$this->variableNaming = $variableNaming;
$this->ifManipulator = $ifManipulator;
$this->binaryOpConditionsCollector = $binaryOpConditionsCollector;
}
/**
@ -225,7 +218,8 @@ CODE_SAMPLE
$ifs = [];
foreach ($classConstFetchNames as $classConstFetchName) {
$methodCallName = self::MAP_CONSTANT_TO_METHOD[$classConstFetchName];
$ifs[] = $this->ifManipulator->createIfStmt(new MethodCall($valueVariable, $methodCallName), new Expression(new Assign($arrayDimFetch, $methodCall)));
$if = new If_(new MethodCall($valueVariable, $methodCallName), ['stmts' => [new Expression(new Assign($arrayDimFetch, $methodCall))]]);
$ifs[] = $if;
}
return $ifs;
}