mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 21:38:22 +01:00
Updated Rector to commit 7740446b9569f8e03f64dedf4e1330fe52b98b3e
7740446b95
Drop AttributeKey::SCOPE in RemoveUnusedVariableAssignRector (#4141)
This commit is contained in:
parent
bc14b9b983
commit
74feb951d2
@ -7,8 +7,10 @@ use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Closure;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Type\Type;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\Rector\AbstractScopeAwareRector;
|
||||
use Rector\Core\ValueObject\PhpVersion;
|
||||
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
|
||||
use Rector\TypeDeclaration\NodeAnalyzer\ReturnTypeAnalyzer\StrictScalarReturnTypeAnalyzer;
|
||||
@ -19,7 +21,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @see \Rector\Tests\CodeQuality\Rector\ClassMethod\ReturnTypeFromStrictScalarReturnExprRector\ReturnTypeFromStrictScalarReturnExprRectorTest
|
||||
*/
|
||||
final class ReturnTypeFromStrictScalarReturnExprRector extends AbstractRector implements MinPhpVersionInterface
|
||||
final class ReturnTypeFromStrictScalarReturnExprRector extends AbstractScopeAwareRector implements MinPhpVersionInterface
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
@ -76,12 +78,12 @@ CODE_SAMPLE
|
||||
/**
|
||||
* @param ClassMethod|Function_|Closure $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
public function refactorWithScope(Node $node, Scope $scope) : ?Node
|
||||
{
|
||||
if ($node->returnType !== null) {
|
||||
return null;
|
||||
}
|
||||
$scalarReturnType = $this->strictScalarReturnTypeAnalyzer->matchAlwaysScalarReturnType($node);
|
||||
$scalarReturnType = $this->strictScalarReturnTypeAnalyzer->matchAlwaysScalarReturnType($node, $scope);
|
||||
if (!$scalarReturnType instanceof Type) {
|
||||
return null;
|
||||
}
|
||||
|
@ -102,9 +102,7 @@ CODE_SAMPLE
|
||||
$currentStmt = $classMethodStmts[$stmtPosition];
|
||||
/** @var Assign $assign */
|
||||
$assign = $currentStmt->expr;
|
||||
/** @var Scope $assignScope */
|
||||
$assignScope = $assign->getAttribute(AttributeKey::SCOPE);
|
||||
if ($this->hasCallLikeInAssignExpr($assign, $assignScope)) {
|
||||
if ($this->hasCallLikeInAssignExpr($assign, $scope)) {
|
||||
// clean safely
|
||||
$cleanAssignedExpr = $this->cleanCastedExpr($assign->expr);
|
||||
$node->stmts[$stmtPosition] = new Expression($cleanAssignedExpr);
|
||||
|
@ -3,9 +3,9 @@
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Php81\Rector\ClassConst;
|
||||
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Reflection\ReflectionProvider;
|
||||
use Rector\Core\Rector\AbstractScopeAwareRector;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
|
@ -7,6 +7,7 @@ use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\Closure;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Type\Type;
|
||||
use Rector\NodeTypeResolver\PHPStan\Type\TypeFactory;
|
||||
use Rector\TypeDeclaration\TypeAnalyzer\AlwaysStrictScalarExprAnalyzer;
|
||||
@ -36,7 +37,7 @@ final class StrictScalarReturnTypeAnalyzer
|
||||
/**
|
||||
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Expr\Closure|\PhpParser\Node\Stmt\Function_ $functionLike
|
||||
*/
|
||||
public function matchAlwaysScalarReturnType($functionLike) : ?Type
|
||||
public function matchAlwaysScalarReturnType($functionLike, Scope $scope) : ?Type
|
||||
{
|
||||
$returns = $this->alwaysStrictReturnAnalyzer->matchAlwaysStrictReturns($functionLike);
|
||||
if ($returns === null) {
|
||||
@ -48,7 +49,7 @@ final class StrictScalarReturnTypeAnalyzer
|
||||
if (!$return->expr instanceof Expr) {
|
||||
return null;
|
||||
}
|
||||
$scalarType = $this->alwaysStrictScalarExprAnalyzer->matchStrictScalarExpr($return->expr);
|
||||
$scalarType = $this->alwaysStrictScalarExprAnalyzer->matchStrictScalarExpr($return->expr, $scope);
|
||||
if (!$scalarType instanceof Type) {
|
||||
return null;
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ final class AlwaysStrictScalarExprAnalyzer
|
||||
$this->reflectionProvider = $reflectionProvider;
|
||||
$this->nodeTypeResolver = $nodeTypeResolver;
|
||||
}
|
||||
public function matchStrictScalarExpr(Expr $expr) : ?Type
|
||||
public function matchStrictScalarExpr(Expr $expr, Scope $scope) : ?Type
|
||||
{
|
||||
if ($expr instanceof Concat) {
|
||||
return new StringType();
|
||||
@ -67,7 +67,7 @@ final class AlwaysStrictScalarExprAnalyzer
|
||||
return null;
|
||||
}
|
||||
if ($expr instanceof FuncCall) {
|
||||
return $this->resolveFuncCallType($expr);
|
||||
return $this->resolveFuncCallType($expr, $scope);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -111,7 +111,7 @@ final class AlwaysStrictScalarExprAnalyzer
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private function resolveFuncCallType(FuncCall $funcCall) : ?Type
|
||||
private function resolveFuncCallType(FuncCall $funcCall, Scope $scope) : ?Type
|
||||
{
|
||||
if (!$funcCall->name instanceof Name) {
|
||||
return null;
|
||||
@ -123,10 +123,6 @@ final class AlwaysStrictScalarExprAnalyzer
|
||||
if (!$functionReflection instanceof NativeFunctionReflection) {
|
||||
return null;
|
||||
}
|
||||
$scope = $funcCall->getAttribute(AttributeKey::SCOPE);
|
||||
if (!$scope instanceof Scope) {
|
||||
return null;
|
||||
}
|
||||
$parametersAcceptor = ParametersAcceptorSelectorVariantsWrapper::select($functionReflection, $funcCall, $scope);
|
||||
$returnType = $parametersAcceptor->getReturnType();
|
||||
if (!$this->isScalarType($returnType)) {
|
||||
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '0f100f0ec5c9f54afa8eafda0e7f2ce78c738529';
|
||||
public const PACKAGE_VERSION = '7740446b9569f8e03f64dedf4e1330fe52b98b3e';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-06-09 19:02:12';
|
||||
public const RELEASE_DATE = '2023-06-09 19:03:02';
|
||||
/**
|
||||
* @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 ComposerAutoloaderInit8ba21c9c8daacad4fc503ef6418f1570::getLoader();
|
||||
return ComposerAutoloaderInit804f83a051c964179cca52e5be452050::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 ComposerAutoloaderInit8ba21c9c8daacad4fc503ef6418f1570
|
||||
class ComposerAutoloaderInit804f83a051c964179cca52e5be452050
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@ -22,17 +22,17 @@ class ComposerAutoloaderInit8ba21c9c8daacad4fc503ef6418f1570
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit8ba21c9c8daacad4fc503ef6418f1570', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit804f83a051c964179cca52e5be452050', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit8ba21c9c8daacad4fc503ef6418f1570', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit804f83a051c964179cca52e5be452050', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit8ba21c9c8daacad4fc503ef6418f1570::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit804f83a051c964179cca52e5be452050::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit8ba21c9c8daacad4fc503ef6418f1570::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit804f83a051c964179cca52e5be452050::$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 ComposerStaticInit8ba21c9c8daacad4fc503ef6418f1570
|
||||
class ComposerStaticInit804f83a051c964179cca52e5be452050
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
@ -3128,9 +3128,9 @@ class ComposerStaticInit8ba21c9c8daacad4fc503ef6418f1570
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit8ba21c9c8daacad4fc503ef6418f1570::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit8ba21c9c8daacad4fc503ef6418f1570::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit8ba21c9c8daacad4fc503ef6418f1570::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit804f83a051c964179cca52e5be452050::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit804f83a051c964179cca52e5be452050::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit804f83a051c964179cca52e5be452050::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user