diff --git a/rules/CodeQuality/Rector/ClassMethod/ReturnTypeFromStrictScalarReturnExprRector.php b/rules/CodeQuality/Rector/ClassMethod/ReturnTypeFromStrictScalarReturnExprRector.php index ddec41fe2c1..9f140346cb9 100644 --- a/rules/CodeQuality/Rector/ClassMethod/ReturnTypeFromStrictScalarReturnExprRector.php +++ b/rules/CodeQuality/Rector/ClassMethod/ReturnTypeFromStrictScalarReturnExprRector.php @@ -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; } diff --git a/rules/DeadCode/Rector/Assign/RemoveUnusedVariableAssignRector.php b/rules/DeadCode/Rector/Assign/RemoveUnusedVariableAssignRector.php index 3f80d5a07a0..737c9e231ff 100644 --- a/rules/DeadCode/Rector/Assign/RemoveUnusedVariableAssignRector.php +++ b/rules/DeadCode/Rector/Assign/RemoveUnusedVariableAssignRector.php @@ -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); diff --git a/rules/Php81/Rector/ClassConst/FinalizePublicClassConstantRector.php b/rules/Php81/Rector/ClassConst/FinalizePublicClassConstantRector.php index fc7a5ce2b16..ddf1fa46abb 100644 --- a/rules/Php81/Rector/ClassConst/FinalizePublicClassConstantRector.php +++ b/rules/Php81/Rector/ClassConst/FinalizePublicClassConstantRector.php @@ -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; diff --git a/rules/TypeDeclaration/NodeAnalyzer/ReturnTypeAnalyzer/StrictScalarReturnTypeAnalyzer.php b/rules/TypeDeclaration/NodeAnalyzer/ReturnTypeAnalyzer/StrictScalarReturnTypeAnalyzer.php index 046aea5f12c..c0ef2adbb82 100644 --- a/rules/TypeDeclaration/NodeAnalyzer/ReturnTypeAnalyzer/StrictScalarReturnTypeAnalyzer.php +++ b/rules/TypeDeclaration/NodeAnalyzer/ReturnTypeAnalyzer/StrictScalarReturnTypeAnalyzer.php @@ -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; } diff --git a/rules/TypeDeclaration/TypeAnalyzer/AlwaysStrictScalarExprAnalyzer.php b/rules/TypeDeclaration/TypeAnalyzer/AlwaysStrictScalarExprAnalyzer.php index 841102df602..de4ee4d370b 100644 --- a/rules/TypeDeclaration/TypeAnalyzer/AlwaysStrictScalarExprAnalyzer.php +++ b/rules/TypeDeclaration/TypeAnalyzer/AlwaysStrictScalarExprAnalyzer.php @@ -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)) { diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 9e49a290223..7cf7db41647 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -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 */ diff --git a/vendor/autoload.php b/vendor/autoload.php index ec875a2ce15..c44ef827990 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) { require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInit8ba21c9c8daacad4fc503ef6418f1570::getLoader(); +return ComposerAutoloaderInit804f83a051c964179cca52e5be452050::getLoader(); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index 1d8fc18ccb5..d40cb5c0f79 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -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; diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 2fb80d5c099..a6a8c830b92 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -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); }