mirror of
https://github.com/rectorphp/rector.git
synced 2025-03-18 14:29:42 +01:00
Updated Rector to commit 36e88e13e5d41db048494b497d59ae0e96c877f0
36e88e13e5
[TypeDeclaration] Add Closure support on NumericReturnTypeFromStrictScalarReturnsRector (#4631)
This commit is contained in:
parent
8451dc0475
commit
59b728d5fa
@ -14,6 +14,7 @@ use PhpParser\Node\Expr\BinaryOp\Mul;
|
||||
use PhpParser\Node\Expr\BinaryOp\Plus;
|
||||
use PhpParser\Node\Expr\BinaryOp\ShiftLeft;
|
||||
use PhpParser\Node\Expr\BinaryOp\ShiftRight;
|
||||
use PhpParser\Node\Expr\Closure;
|
||||
use PhpParser\Node\Expr\PostDec;
|
||||
use PhpParser\Node\Expr\PostInc;
|
||||
use PhpParser\Node\Expr\PreDec;
|
||||
@ -24,7 +25,6 @@ use PhpParser\Node\Stmt\Function_;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
use PHPStan\Type\FloatType;
|
||||
use PHPStan\Type\IntegerType;
|
||||
use Rector\Core\NodeAnalyzer\ExprAnalyzer;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
|
||||
@ -35,15 +35,6 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
*/
|
||||
final class NumericReturnTypeFromStrictScalarReturnsRector extends AbstractRector implements MinPhpVersionInterface
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\NodeAnalyzer\ExprAnalyzer
|
||||
*/
|
||||
private $exprAnalyzer;
|
||||
public function __construct(ExprAnalyzer $exprAnalyzer)
|
||||
{
|
||||
$this->exprAnalyzer = $exprAnalyzer;
|
||||
}
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Change numeric return type based on strict returns type operations', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
@ -71,10 +62,10 @@ CODE_SAMPLE
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [ClassMethod::class, Function_::class];
|
||||
return [ClassMethod::class, Function_::class, Closure::class];
|
||||
}
|
||||
/**
|
||||
* @param ClassMethod|Function_ $node
|
||||
* @param ClassMethod|Function_|Closure $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
@ -89,7 +80,7 @@ CODE_SAMPLE
|
||||
return null;
|
||||
}
|
||||
if ($return->expr instanceof PreInc || $return->expr instanceof PostInc || $return->expr instanceof PostDec || $return->expr instanceof PreDec) {
|
||||
$exprType = $this->getType($return->expr);
|
||||
$exprType = $this->nodeTypeResolver->getNativeType($return->expr);
|
||||
if ($exprType instanceof IntegerType) {
|
||||
$node->returnType = new Identifier('int');
|
||||
return $node;
|
||||
@ -98,9 +89,6 @@ CODE_SAMPLE
|
||||
}
|
||||
// @see https://chat.openai.com/share/a9e4fb74-5366-4c4c-9998-d6caeb8b5acc
|
||||
if ($return->expr instanceof Minus || $return->expr instanceof Plus || $return->expr instanceof Mul || $return->expr instanceof Mod || $return->expr instanceof BitwiseAnd || $return->expr instanceof ShiftRight || $return->expr instanceof ShiftLeft || $return->expr instanceof BitwiseOr) {
|
||||
if ($this->isBinaryOpContainingNonTypedParam($return->expr)) {
|
||||
return null;
|
||||
}
|
||||
return $this->refactorBinaryOp($return->expr, $node);
|
||||
}
|
||||
return null;
|
||||
@ -110,7 +98,7 @@ CODE_SAMPLE
|
||||
return PhpVersionFeature::SCALAR_TYPES;
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $functionLike
|
||||
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike
|
||||
*/
|
||||
private function matchRootReturnWithExpr($functionLike) : ?Return_
|
||||
{
|
||||
@ -129,13 +117,13 @@ CODE_SAMPLE
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $functionLike
|
||||
* @return null|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Stmt\ClassMethod
|
||||
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike
|
||||
* @return null|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Expr\Closure
|
||||
*/
|
||||
private function refactorBinaryOp(BinaryOp $binaryOp, $functionLike)
|
||||
{
|
||||
$leftType = $this->getType($binaryOp->left);
|
||||
$rightType = $this->getType($binaryOp->right);
|
||||
$leftType = $this->nodeTypeResolver->getNativeType($binaryOp->left);
|
||||
$rightType = $this->nodeTypeResolver->getNativeType($binaryOp->right);
|
||||
if ($leftType instanceof IntegerType && $rightType instanceof IntegerType) {
|
||||
$functionLike->returnType = new Identifier('int');
|
||||
return $functionLike;
|
||||
@ -156,11 +144,4 @@ CODE_SAMPLE
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private function isBinaryOpContainingNonTypedParam(BinaryOp $binaryOp) : bool
|
||||
{
|
||||
if ($this->exprAnalyzer->isNonTypedFromParam($binaryOp->left)) {
|
||||
return \true;
|
||||
}
|
||||
return $this->exprAnalyzer->isNonTypedFromParam($binaryOp->right);
|
||||
}
|
||||
}
|
||||
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '0.17.9';
|
||||
public const PACKAGE_VERSION = '36e88e13e5d41db048494b497d59ae0e96c877f0';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-08-03 14:44:07';
|
||||
public const RELEASE_DATE = '2023-08-03 20:52:40';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
|
||||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit598db246124106a074f9a5b61c70e3ef::getLoader();
|
||||
return ComposerAutoloaderInit3d41daa140625cb5a46044552327926a::getLoader();
|
||||
|
10
vendor/composer/autoload_real.php
vendored
10
vendor/composer/autoload_real.php
vendored
@ -2,7 +2,7 @@
|
||||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit598db246124106a074f9a5b61c70e3ef
|
||||
class ComposerAutoloaderInit3d41daa140625cb5a46044552327926a
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@ -22,17 +22,17 @@ class ComposerAutoloaderInit598db246124106a074f9a5b61c70e3ef
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit598db246124106a074f9a5b61c70e3ef', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit3d41daa140625cb5a46044552327926a', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit598db246124106a074f9a5b61c70e3ef', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit3d41daa140625cb5a46044552327926a', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit598db246124106a074f9a5b61c70e3ef::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit3d41daa140625cb5a46044552327926a::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit598db246124106a074f9a5b61c70e3ef::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit3d41daa140625cb5a46044552327926a::$files;
|
||||
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
8
vendor/composer/autoload_static.php
vendored
8
vendor/composer/autoload_static.php
vendored
@ -4,7 +4,7 @@
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit598db246124106a074f9a5b61c70e3ef
|
||||
class ComposerStaticInit3d41daa140625cb5a46044552327926a
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
@ -3025,9 +3025,9 @@ class ComposerStaticInit598db246124106a074f9a5b61c70e3ef
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit598db246124106a074f9a5b61c70e3ef::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit598db246124106a074f9a5b61c70e3ef::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit598db246124106a074f9a5b61c70e3ef::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit3d41daa140625cb5a46044552327926a::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit3d41daa140625cb5a46044552327926a::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit3d41daa140625cb5a46044552327926a::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user