Skip to content

Commit

Permalink
Updated Rector to commit aa7282195caab5889ee067ca3fb5eda62f26ed1b
Browse files Browse the repository at this point in the history
rectorphp/rector-src@aa72821 [TypeDeclaration] Add return static object support on ReturnTypeFromStrictFluentReturnRector (#4916)
  • Loading branch information
TomasVotruba committed Sep 5, 2023
1 parent dbdeb21 commit 4c7551d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Type\ObjectType;
use PHPStan\Type\StaticType;
use PHPStan\Type\ThisType;
use Rector\Core\Php\PhpVersionProvider;
use Rector\Core\Rector\AbstractScopeAwareRector;
Expand Down Expand Up @@ -100,18 +101,31 @@ public function refactorWithScope(Node $node, Scope $scope) : ?Node
return null;
}
$returnType = $this->returnTypeInferer->inferFunctionLike($node);
if ($returnType instanceof StaticType && $returnType->getStaticObjectType()->getClassName() === $classReflection->getName()) {
return $this->processAddReturnSelfOrStatic($node, $classReflection);
}
if ($returnType instanceof ObjectType && $returnType->getClassName() === $classReflection->getName()) {
$node->returnType = new Name('self');
return $node;
}
if (!$returnType instanceof ThisType) {
return null;
}
if ($classReflection->isAnonymous() || $classReflection->isFinalByKeyword() || !$this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::STATIC_RETURN_TYPE)) {
$node->returnType = new Name('self');
} else {
$node->returnType = new Name('static');
return $this->processAddReturnSelfOrStatic($node, $classReflection);
}
private function processAddReturnSelfOrStatic(ClassMethod $classMethod, ClassReflection $classReflection) : ClassMethod
{
$classMethod->returnType = $this->shouldSelf($classReflection) ? new Name('self') : new Name('static');
return $classMethod;
}
private function shouldSelf(ClassReflection $classReflection) : bool
{
if ($classReflection->isAnonymous()) {
return \true;
}
if ($classReflection->isFinalByKeyword()) {
return \true;
}
return $node;
return !$this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::STATIC_RETURN_TYPE);
}
}
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 = '6d009ccad0aacd102fdacba00eb59b32a1104582';
public const PACKAGE_VERSION = 'aa7282195caab5889ee067ca3fb5eda62f26ed1b';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-09-05 22:45:59';
public const RELEASE_DATE = '2023-09-05 17:00:45';
/**
* @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 ComposerAutoloaderInitdcd48cf0745b1bcb0282fbb71bca3b11::getLoader();
return ComposerAutoloaderInit9e2986b0cd0945b57061a07173b90a79::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 ComposerAutoloaderInitdcd48cf0745b1bcb0282fbb71bca3b11
class ComposerAutoloaderInit9e2986b0cd0945b57061a07173b90a79
{
private static $loader;

Expand All @@ -22,17 +22,17 @@ public static function getLoader()
return self::$loader;
}

spl_autoload_register(array('ComposerAutoloaderInitdcd48cf0745b1bcb0282fbb71bca3b11', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit9e2986b0cd0945b57061a07173b90a79', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInitdcd48cf0745b1bcb0282fbb71bca3b11', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit9e2986b0cd0945b57061a07173b90a79', 'loadClassLoader'));

require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitdcd48cf0745b1bcb0282fbb71bca3b11::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit9e2986b0cd0945b57061a07173b90a79::getInitializer($loader));

$loader->setClassMapAuthoritative(true);
$loader->register(true);

$filesToLoad = \Composer\Autoload\ComposerStaticInitdcd48cf0745b1bcb0282fbb71bca3b11::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInit9e2986b0cd0945b57061a07173b90a79::$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 ComposerStaticInitdcd48cf0745b1bcb0282fbb71bca3b11
class ComposerStaticInit9e2986b0cd0945b57061a07173b90a79
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
Expand Down Expand Up @@ -2612,9 +2612,9 @@ class ComposerStaticInitdcd48cf0745b1bcb0282fbb71bca3b11
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitdcd48cf0745b1bcb0282fbb71bca3b11::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitdcd48cf0745b1bcb0282fbb71bca3b11::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitdcd48cf0745b1bcb0282fbb71bca3b11::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit9e2986b0cd0945b57061a07173b90a79::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit9e2986b0cd0945b57061a07173b90a79::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit9e2986b0cd0945b57061a07173b90a79::$classMap;

}, null, ClassLoader::class);
}
Expand Down

0 comments on commit 4c7551d

Please sign in to comment.