mirror of
https://github.com/rectorphp/rector.git
synced 2025-04-13 12:02:09 +02:00
Updated Rector to commit b0105f24cf32cfe12438e85c5033aa79bce9a1a4
b0105f24cf
[PHPStanStaticTypeMapper] Allow Closure type on ClosureTypeMapper based on PHP versions (#4785)
This commit is contained in:
parent
a8b42110be
commit
480a54b9d7
@ -11,6 +11,8 @@ use PHPStan\PhpDocParser\Ast\Type\TypeNode;
|
||||
use PHPStan\Type\ClosureType;
|
||||
use PHPStan\Type\Type;
|
||||
use Rector\BetterPhpDocParser\ValueObject\Type\FullyQualifiedIdentifierTypeNode;
|
||||
use Rector\Core\Php\PhpVersionProvider;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
use Rector\PhpDocParser\PhpDocParser\PhpDocNodeTraverser;
|
||||
use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface;
|
||||
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
|
||||
@ -19,6 +21,15 @@ use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
|
||||
*/
|
||||
final class ClosureTypeMapper implements TypeMapperInterface
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\Php\PhpVersionProvider
|
||||
*/
|
||||
private $phpVersionProvider;
|
||||
public function __construct(PhpVersionProvider $phpVersionProvider)
|
||||
{
|
||||
$this->phpVersionProvider = $phpVersionProvider;
|
||||
}
|
||||
/**
|
||||
* @return class-string<Type>
|
||||
*/
|
||||
@ -50,7 +61,19 @@ final class ClosureTypeMapper implements TypeMapperInterface
|
||||
*/
|
||||
public function mapToPhpParserNode(Type $type, string $typeKind) : ?Node
|
||||
{
|
||||
if ($typeKind === TypeKind::PROPERTY) {
|
||||
// ref https://3v4l.org/iKMK6#v5.3.29
|
||||
if ($typeKind === TypeKind::PARAM && $this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::ANONYMOUS_FUNCTION_PARAM_TYPE)) {
|
||||
return new FullyQualified('Closure');
|
||||
}
|
||||
// ref https://3v4l.org/g8WvW#v7.4.0
|
||||
if ($typeKind === TypeKind::PROPERTY && $this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::TYPED_PROPERTIES)) {
|
||||
return new FullyQualified('Closure');
|
||||
}
|
||||
if ($typeKind !== TypeKind::RETURN) {
|
||||
return null;
|
||||
}
|
||||
// ref https://3v4l.org/nUreN#v7.0.0
|
||||
if (!$this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::ANONYMOUS_FUNCTION_RETURN_TYPE)) {
|
||||
return null;
|
||||
}
|
||||
return new FullyQualified('Closure');
|
||||
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '7899f2b186919d8b6bec30272f5e3046ec0793bd';
|
||||
public const PACKAGE_VERSION = 'b0105f24cf32cfe12438e85c5033aa79bce9a1a4';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-08-14 07:31:46';
|
||||
public const RELEASE_DATE = '2023-08-14 07:36:31';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
@ -3,7 +3,6 @@
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Core\NodeAnalyzer;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PHPStan\Type\CallableType;
|
||||
use PHPStan\Type\NullType;
|
||||
@ -29,7 +28,7 @@ final class PropertyAnalyzer
|
||||
if ($propertyType instanceof NullType) {
|
||||
return \true;
|
||||
}
|
||||
if ($this->isForbiddenType($property, $propertyType)) {
|
||||
if ($this->isForbiddenType($propertyType)) {
|
||||
return \true;
|
||||
}
|
||||
if (!$propertyType instanceof UnionType) {
|
||||
@ -37,23 +36,23 @@ final class PropertyAnalyzer
|
||||
}
|
||||
$types = $propertyType->getTypes();
|
||||
foreach ($types as $type) {
|
||||
if ($this->isForbiddenType($property, $type)) {
|
||||
if ($this->isForbiddenType($type)) {
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
private function isForbiddenType(Property $property, Type $type) : bool
|
||||
private function isForbiddenType(Type $type) : bool
|
||||
{
|
||||
if ($type instanceof NonExistingObjectType) {
|
||||
return \true;
|
||||
}
|
||||
return $this->isCallableType($property, $type);
|
||||
return $this->isCallableType($type);
|
||||
}
|
||||
private function isCallableType(Property $property, Type $type) : bool
|
||||
private function isCallableType(Type $type) : bool
|
||||
{
|
||||
if ($type instanceof TypeWithClassName && $type->getClassName() === 'Closure') {
|
||||
return !$property->type instanceof Node;
|
||||
return \false;
|
||||
}
|
||||
return $type instanceof CallableType;
|
||||
}
|
||||
|
@ -32,6 +32,10 @@ final class PhpVersionFeature
|
||||
* @var int
|
||||
*/
|
||||
public const ELVIS_OPERATOR = \Rector\Core\ValueObject\PhpVersion::PHP_53;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public const ANONYMOUS_FUNCTION_PARAM_TYPE = \Rector\Core\ValueObject\PhpVersion::PHP_53;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
@ -147,6 +151,10 @@ final class PhpVersionFeature
|
||||
* @var int
|
||||
*/
|
||||
public const WRAP_VARIABLE_VARIABLE = \Rector\Core\ValueObject\PhpVersion::PHP_70;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public const ANONYMOUS_FUNCTION_RETURN_TYPE = \Rector\Core\ValueObject\PhpVersion::PHP_70;
|
||||
/**
|
||||
* @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 ComposerAutoloaderInita964e0a56465619b8c0fa01369eb27c6::getLoader();
|
||||
return ComposerAutoloaderInit4e479c6ca392702f962040c7fa54d1aa::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 ComposerAutoloaderInita964e0a56465619b8c0fa01369eb27c6
|
||||
class ComposerAutoloaderInit4e479c6ca392702f962040c7fa54d1aa
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@ -22,17 +22,17 @@ class ComposerAutoloaderInita964e0a56465619b8c0fa01369eb27c6
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInita964e0a56465619b8c0fa01369eb27c6', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit4e479c6ca392702f962040c7fa54d1aa', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInita964e0a56465619b8c0fa01369eb27c6', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit4e479c6ca392702f962040c7fa54d1aa', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInita964e0a56465619b8c0fa01369eb27c6::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit4e479c6ca392702f962040c7fa54d1aa::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInita964e0a56465619b8c0fa01369eb27c6::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit4e479c6ca392702f962040c7fa54d1aa::$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 ComposerStaticInita964e0a56465619b8c0fa01369eb27c6
|
||||
class ComposerStaticInit4e479c6ca392702f962040c7fa54d1aa
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
@ -2959,9 +2959,9 @@ class ComposerStaticInita964e0a56465619b8c0fa01369eb27c6
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInita964e0a56465619b8c0fa01369eb27c6::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInita964e0a56465619b8c0fa01369eb27c6::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInita964e0a56465619b8c0fa01369eb27c6::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit4e479c6ca392702f962040c7fa54d1aa::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit4e479c6ca392702f962040c7fa54d1aa::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit4e479c6ca392702f962040c7fa54d1aa::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user