Updated Rector to commit 6b7aac835934de48c034aa8b2bad886616566e06

6b7aac8359 [Php81] Remove IntersectionTypesRector as rely on docblock (#4784)
This commit is contained in:
Tomas Votruba 2023-08-14 06:41:08 +00:00
parent 480a54b9d7
commit 867dc4426c
8 changed files with 15 additions and 158 deletions

View File

@ -10,11 +10,10 @@ use Rector\Php81\Rector\Class_\SpatieEnumClassToEnumRector;
use Rector\Php81\Rector\ClassConst\FinalizePublicClassConstantRector;
use Rector\Php81\Rector\ClassMethod\NewInInitializerRector;
use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector;
use Rector\Php81\Rector\FunctionLike\IntersectionTypesRector;
use Rector\Php81\Rector\MethodCall\MyCLabsMethodCallToEnumConstRector;
use Rector\Php81\Rector\MethodCall\SpatieEnumMethodCallToEnumConstRector;
use Rector\Php81\Rector\Property\ReadOnlyPropertyRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnNeverTypeRector;
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->rules([ReturnNeverTypeRector::class, MyCLabsClassToEnumRector::class, MyCLabsMethodCallToEnumConstRector::class, FinalizePublicClassConstantRector::class, ReadOnlyPropertyRector::class, SpatieEnumClassToEnumRector::class, SpatieEnumMethodCallToEnumConstRector::class, NewInInitializerRector::class, IntersectionTypesRector::class, NullToStrictStringFuncCallArgRector::class, FirstClassCallableRector::class]);
$rectorConfig->rules([ReturnNeverTypeRector::class, MyCLabsClassToEnumRector::class, MyCLabsMethodCallToEnumConstRector::class, FinalizePublicClassConstantRector::class, ReadOnlyPropertyRector::class, SpatieEnumClassToEnumRector::class, SpatieEnumMethodCallToEnumConstRector::class, NewInInitializerRector::class, NullToStrictStringFuncCallArgRector::class, FirstClassCallableRector::class]);
};

View File

@ -1,4 +1,4 @@
# 355 Rules Overview
# 354 Rules Overview
<br>
@ -40,7 +40,7 @@
- [Php80](#php80) (16)
- [Php81](#php81) (10)
- [Php81](#php81) (9)
- [Php82](#php82) (4)
@ -5070,27 +5070,6 @@ Upgrade array callable to first class callable
<br>
### IntersectionTypesRector
Change docs to intersection types, where possible (properties are covered by TypedPropertyRector (@todo))
- class: [`Rector\Php81\Rector\FunctionLike\IntersectionTypesRector`](../rules/Php81/Rector/FunctionLike/IntersectionTypesRector.php)
```diff
final class SomeClass
{
- /**
- * @param Foo&Bar $types
- */
- public function process($types)
+ public function process(Foo&Bar $types)
{
}
}
```
<br>
### MyCLabsClassToEnumRector
Refactor MyCLabs enum class to native Enum

View File

@ -1,119 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Php81\Rector\FunctionLike;
use PhpParser\Node;
use PhpParser\Node\Expr\ArrowFunction;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_;
use PHPStan\Type\IntersectionType;
use PHPStan\Type\TypeWithClassName;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\Tests\Php81\Rector\FunctionLike\IntersectionTypesRector\IntersectionTypesRectorTest
*/
final class IntersectionTypesRector extends AbstractRector implements MinPhpVersionInterface
{
/**
* @var bool
*/
private $hasChanged = \false;
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Change docs to intersection types, where possible (properties are covered by TypedPropertyRector (@todo))', [new CodeSample(<<<'CODE_SAMPLE'
final class SomeClass
{
/**
* @param Foo&Bar $types
*/
public function process($types)
{
}
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
final class SomeClass
{
public function process(Foo&Bar $types)
{
}
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [ArrowFunction::class, Closure::class, ClassMethod::class, Function_::class];
}
/**
* @param ArrowFunction|Closure|ClassMethod|Function_ $node
*/
public function refactor(Node $node) : ?Node
{
$this->hasChanged = \false;
$phpDocInfo = $this->phpDocInfoFactory->createFromNode($node);
if (!$phpDocInfo instanceof PhpDocInfo) {
return null;
}
$this->refactorParamTypes($node, $phpDocInfo);
// $this->refactorReturnType($node, $phpDocInfo);
if ($this->hasChanged) {
return $node;
}
return null;
}
public function provideMinPhpVersion() : int
{
return PhpVersionFeature::INTERSECTION_TYPES;
}
/**
* @param \PhpParser\Node\Expr\ArrowFunction|\PhpParser\Node\Expr\Closure|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $functionLike
*/
private function refactorParamTypes($functionLike, PhpDocInfo $phpDocInfo) : void
{
foreach ($functionLike->params as $param) {
if ($param->type !== null) {
continue;
}
/** @var string $paramName */
$paramName = $this->getName($param->var);
$paramType = $phpDocInfo->getParamType($paramName);
if (!$paramType instanceof IntersectionType) {
continue;
}
if (!$this->isIntersectionableType($paramType)) {
continue;
}
$phpParserIntersectionType = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($paramType, TypeKind::PARAM);
if (!$phpParserIntersectionType instanceof Node\IntersectionType) {
continue;
}
$param->type = $phpParserIntersectionType;
$this->hasChanged = \true;
}
}
/**
* Only class-type are supported https://wiki.php.net/rfc/pure-intersection-types#supported_types
*/
private function isIntersectionableType(IntersectionType $intersectionType) : bool
{
foreach ($intersectionType->getTypes() as $intersectionedType) {
if ($intersectionedType instanceof TypeWithClassName) {
continue;
}
return \false;
}
return \true;
}
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = 'b0105f24cf32cfe12438e85c5033aa79bce9a1a4';
public const PACKAGE_VERSION = '6b7aac835934de48c034aa8b2bad886616566e06';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-08-14 07:36:31';
public const RELEASE_DATE = '2023-08-14 07:36:48';
/**
* @var int
*/

2
vendor/autoload.php vendored
View File

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

View File

@ -2217,7 +2217,6 @@ return array(
'Rector\\Php81\\Rector\\Class_\\MyCLabsClassToEnumRector' => $baseDir . '/rules/Php81/Rector/Class_/MyCLabsClassToEnumRector.php',
'Rector\\Php81\\Rector\\Class_\\SpatieEnumClassToEnumRector' => $baseDir . '/rules/Php81/Rector/Class_/SpatieEnumClassToEnumRector.php',
'Rector\\Php81\\Rector\\FuncCall\\NullToStrictStringFuncCallArgRector' => $baseDir . '/rules/Php81/Rector/FuncCall/NullToStrictStringFuncCallArgRector.php',
'Rector\\Php81\\Rector\\FunctionLike\\IntersectionTypesRector' => $baseDir . '/rules/Php81/Rector/FunctionLike/IntersectionTypesRector.php',
'Rector\\Php81\\Rector\\MethodCall\\MyCLabsMethodCallToEnumConstRector' => $baseDir . '/rules/Php81/Rector/MethodCall/MyCLabsMethodCallToEnumConstRector.php',
'Rector\\Php81\\Rector\\MethodCall\\SpatieEnumMethodCallToEnumConstRector' => $baseDir . '/rules/Php81/Rector/MethodCall/SpatieEnumMethodCallToEnumConstRector.php',
'Rector\\Php81\\Rector\\Property\\ReadOnlyPropertyRector' => $baseDir . '/rules/Php81/Rector/Property/ReadOnlyPropertyRector.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit4e479c6ca392702f962040c7fa54d1aa
class ComposerAutoloaderInitd0491821a1f961d1d51360ac6370685e
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInit4e479c6ca392702f962040c7fa54d1aa
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit4e479c6ca392702f962040c7fa54d1aa', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInitd0491821a1f961d1d51360ac6370685e', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit4e479c6ca392702f962040c7fa54d1aa', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInitd0491821a1f961d1d51360ac6370685e', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit4e479c6ca392702f962040c7fa54d1aa::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInitd0491821a1f961d1d51360ac6370685e::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInit4e479c6ca392702f962040c7fa54d1aa::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInitd0491821a1f961d1d51360ac6370685e::$files;
$requireFile = \Closure::bind(static function ($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 ComposerStaticInit4e479c6ca392702f962040c7fa54d1aa
class ComposerStaticInitd0491821a1f961d1d51360ac6370685e
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -2470,7 +2470,6 @@ class ComposerStaticInit4e479c6ca392702f962040c7fa54d1aa
'Rector\\Php81\\Rector\\Class_\\MyCLabsClassToEnumRector' => __DIR__ . '/../..' . '/rules/Php81/Rector/Class_/MyCLabsClassToEnumRector.php',
'Rector\\Php81\\Rector\\Class_\\SpatieEnumClassToEnumRector' => __DIR__ . '/../..' . '/rules/Php81/Rector/Class_/SpatieEnumClassToEnumRector.php',
'Rector\\Php81\\Rector\\FuncCall\\NullToStrictStringFuncCallArgRector' => __DIR__ . '/../..' . '/rules/Php81/Rector/FuncCall/NullToStrictStringFuncCallArgRector.php',
'Rector\\Php81\\Rector\\FunctionLike\\IntersectionTypesRector' => __DIR__ . '/../..' . '/rules/Php81/Rector/FunctionLike/IntersectionTypesRector.php',
'Rector\\Php81\\Rector\\MethodCall\\MyCLabsMethodCallToEnumConstRector' => __DIR__ . '/../..' . '/rules/Php81/Rector/MethodCall/MyCLabsMethodCallToEnumConstRector.php',
'Rector\\Php81\\Rector\\MethodCall\\SpatieEnumMethodCallToEnumConstRector' => __DIR__ . '/../..' . '/rules/Php81/Rector/MethodCall/SpatieEnumMethodCallToEnumConstRector.php',
'Rector\\Php81\\Rector\\Property\\ReadOnlyPropertyRector' => __DIR__ . '/../..' . '/rules/Php81/Rector/Property/ReadOnlyPropertyRector.php',
@ -2959,9 +2958,9 @@ class ComposerStaticInit4e479c6ca392702f962040c7fa54d1aa
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit4e479c6ca392702f962040c7fa54d1aa::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit4e479c6ca392702f962040c7fa54d1aa::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit4e479c6ca392702f962040c7fa54d1aa::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInitd0491821a1f961d1d51360ac6370685e::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitd0491821a1f961d1d51360ac6370685e::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitd0491821a1f961d1d51360ac6370685e::$classMap;
}, null, ClassLoader::class);
}