Skip to content

Commit

Permalink
Updated Rector to commit 36e88e13e5d41db048494b497d59ae0e96c877f0
Browse files Browse the repository at this point in the history
rectorphp/rector-src@36e88e1 [TypeDeclaration] Add Closure support on NumericReturnTypeFromStrictScalarReturnsRector (#4631)
  • Loading branch information
TomasVotruba committed Aug 3, 2023
1 parent 8451dc0 commit 59b728d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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;
Expand All @@ -24,7 +25,6 @@
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;
Expand All @@ -35,15 +35,6 @@
*/
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'
Expand Down Expand Up @@ -71,10 +62,10 @@ public function resolve(int $first, int $second): int
*/
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
{
Expand All @@ -89,7 +80,7 @@ public function refactor(Node $node) : ?Node
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;
Expand All @@ -98,9 +89,6 @@ public function refactor(Node $node) : ?Node
}
// @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;
Expand All @@ -110,7 +98,7 @@ public function provideMinPhpVersion() : int
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_
{
Expand All @@ -129,13 +117,13 @@ private function matchRootReturnWithExpr($functionLike) : ?Return_
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;
Expand All @@ -156,11 +144,4 @@ private function refactorBinaryOp(BinaryOp $binaryOp, $functionLike)
}
return null;
}
private function isBinaryOpContainingNonTypedParam(BinaryOp $binaryOp) : bool
{
if ($this->exprAnalyzer->isNonTypedFromParam($binaryOp->left)) {
return \true;
}
return $this->exprAnalyzer->isNonTypedFromParam($binaryOp->right);
}
}
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion vendor/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInit598db246124106a074f9a5b61c70e3ef::getLoader();
return ComposerAutoloaderInit3d41daa140625cb5a46044552327926a::getLoader();
10 changes: 5 additions & 5 deletions vendor/composer/autoload_real.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// autoload_real.php @generated by Composer

class ComposerAutoloaderInit598db246124106a074f9a5b61c70e3ef
class ComposerAutoloaderInit3d41daa140625cb5a46044552327926a
{
private static $loader;

Expand All @@ -22,17 +22,17 @@ public static function getLoader()
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;
Expand Down
8 changes: 4 additions & 4 deletions vendor/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Composer\Autoload;

class ComposerStaticInit598db246124106a074f9a5b61c70e3ef
class ComposerStaticInit3d41daa140625cb5a46044552327926a
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 59b728d

Please sign in to comment.