Updated Rector to commit fc90ad2eb4cd62c02a5f6a2b235e0217dc8c9077

fc90ad2eb4 [TypeDeclaration] Skip implements mixed, and already has typed return on AddReturnTypeDeclarationRector (#2509)
This commit is contained in:
Tomas Votruba 2022-06-16 15:16:19 +00:00
parent a5f127b615
commit 3bf77b5204
5 changed files with 32 additions and 17 deletions

View File

@ -4,14 +4,17 @@ declare (strict_types=1);
namespace Rector\TypeDeclaration\Rector\ClassMethod;
use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\Type\ArrayType;
use PHPStan\Type\MixedType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Php\PhpVersionProvider;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\NodeTypeResolver\TypeComparator\TypeComparator;
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
use Rector\TypeDeclaration\ValueObject\AddReturnTypeDeclaration;
@ -80,13 +83,14 @@ CODE_SAMPLE
public function refactor(Node $node) : ?Node
{
foreach ($this->methodReturnTypes as $methodReturnType) {
if (!$this->isObjectType($node, $methodReturnType->getObjectType())) {
$objectType = $methodReturnType->getObjectType();
if (!$this->isObjectType($node, $objectType)) {
continue;
}
if (!$this->isName($node, $methodReturnType->getMethod())) {
continue;
}
$this->processClassMethodNodeWithTypehints($node, $methodReturnType->getReturnType());
$this->processClassMethodNodeWithTypehints($node, $methodReturnType->getReturnType(), $objectType);
if (!$this->hasChanged) {
return null;
}
@ -102,8 +106,19 @@ CODE_SAMPLE
Assert::allIsAOf($configuration, AddReturnTypeDeclaration::class);
$this->methodReturnTypes = $configuration;
}
private function processClassMethodNodeWithTypehints(ClassMethod $classMethod, Type $newType) : void
private function processClassMethodNodeWithTypehints(ClassMethod $classMethod, Type $newType, ObjectType $objectType) : void
{
if ($newType instanceof MixedType) {
$class = $classMethod->getAttribute(AttributeKey::PARENT_NODE);
if (!$class instanceof Class_) {
return;
}
$className = (string) $this->nodeNameResolver->getName($class);
$currentObjectType = new ObjectType($className);
if (!$objectType->equals($currentObjectType) && $classMethod->returnType !== null) {
return;
}
}
// remove it
if ($newType instanceof MixedType && !$this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::MIXED_TYPE)) {
$classMethod->returnType = null;

View File

@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = '7b86097258194b383af82a9b7d3f965dc69c5e11';
public const PACKAGE_VERSION = 'fc90ad2eb4cd62c02a5f6a2b235e0217dc8c9077';
/**
* @var string
*/
public const RELEASE_DATE = '2022-06-16 16:12:30';
public const RELEASE_DATE = '2022-06-16 17:10:30';
/**
* @var int
*/

2
vendor/autoload.php vendored
View File

@ -9,4 +9,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit55c9ec0aa53043bfc396e3721d5efac2::getLoader();
return ComposerAutoloaderInit7f6a7d5b2f7f04bc6b3f4be81c842809::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit55c9ec0aa53043bfc396e3721d5efac2
class ComposerAutoloaderInit7f6a7d5b2f7f04bc6b3f4be81c842809
{
private static $loader;
@ -22,19 +22,19 @@ class ComposerAutoloaderInit55c9ec0aa53043bfc396e3721d5efac2
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit55c9ec0aa53043bfc396e3721d5efac2', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit7f6a7d5b2f7f04bc6b3f4be81c842809', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit55c9ec0aa53043bfc396e3721d5efac2', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit7f6a7d5b2f7f04bc6b3f4be81c842809', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit55c9ec0aa53043bfc396e3721d5efac2::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit7f6a7d5b2f7f04bc6b3f4be81c842809::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$includeFiles = \Composer\Autoload\ComposerStaticInit55c9ec0aa53043bfc396e3721d5efac2::$files;
$includeFiles = \Composer\Autoload\ComposerStaticInit7f6a7d5b2f7f04bc6b3f4be81c842809::$files;
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire55c9ec0aa53043bfc396e3721d5efac2($fileIdentifier, $file);
composerRequire7f6a7d5b2f7f04bc6b3f4be81c842809($fileIdentifier, $file);
}
return $loader;
@ -46,7 +46,7 @@ class ComposerAutoloaderInit55c9ec0aa53043bfc396e3721d5efac2
* @param string $file
* @return void
*/
function composerRequire55c9ec0aa53043bfc396e3721d5efac2($fileIdentifier, $file)
function composerRequire7f6a7d5b2f7f04bc6b3f4be81c842809($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInit55c9ec0aa53043bfc396e3721d5efac2
class ComposerStaticInit7f6a7d5b2f7f04bc6b3f4be81c842809
{
public static $files = array (
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
@ -3396,9 +3396,9 @@ class ComposerStaticInit55c9ec0aa53043bfc396e3721d5efac2
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit55c9ec0aa53043bfc396e3721d5efac2::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit55c9ec0aa53043bfc396e3721d5efac2::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit55c9ec0aa53043bfc396e3721d5efac2::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit7f6a7d5b2f7f04bc6b3f4be81c842809::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit7f6a7d5b2f7f04bc6b3f4be81c842809::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit7f6a7d5b2f7f04bc6b3f4be81c842809::$classMap;
}, null, ClassLoader::class);
}