Skip to content

Commit

Permalink
Updated Rector to commit b0105f24cf32cfe12438e85c5033aa79bce9a1a4
Browse files Browse the repository at this point in the history
rectorphp/rector-src@b0105f2 [PHPStanStaticTypeMapper] Allow Closure type on ClosureTypeMapper based on PHP versions (#4785)
  • Loading branch information
TomasVotruba committed Aug 14, 2023
1 parent a8b4211 commit 480a54b
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
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;
Expand All @@ -19,6 +21,15 @@
*/
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>
*/
Expand Down Expand Up @@ -50,7 +61,19 @@ public function mapToPHPStanPhpDocTypeNode(Type $type) : TypeNode
*/
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');
Expand Down
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 = '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
*/
Expand Down
13 changes: 6 additions & 7 deletions src/NodeAnalyzer/PropertyAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,31 +28,31 @@ public function hasForbiddenType(Property $property) : bool
if ($propertyType instanceof NullType) {
return \true;
}
if ($this->isForbiddenType($property, $propertyType)) {
if ($this->isForbiddenType($propertyType)) {
return \true;
}
if (!$propertyType instanceof UnionType) {
return \false;
}
$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;
}
Expand Down
8 changes: 8 additions & 0 deletions src/ValueObject/PhpVersionFeature.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
*/
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 ComposerAutoloaderInita964e0a56465619b8c0fa01369eb27c6::getLoader();
return ComposerAutoloaderInit4e479c6ca392702f962040c7fa54d1aa::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 ComposerAutoloaderInita964e0a56465619b8c0fa01369eb27c6
class ComposerAutoloaderInit4e479c6ca392702f962040c7fa54d1aa
{
private static $loader;

Expand All @@ -22,17 +22,17 @@ public static function getLoader()
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;
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 ComposerStaticInita964e0a56465619b8c0fa01369eb27c6
class ComposerStaticInit4e479c6ca392702f962040c7fa54d1aa
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 480a54b

Please sign in to comment.