mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-06 19:30:50 +00:00
Updated Rector to commit e81691f1c6
e81691f1c6
[DowngradePhp80] Add DowngradeMixedTypeTypedPropertyRector (#2579)
This commit is contained in:
parent
ec6f7db42d
commit
f2b6b30624
|
@ -31,6 +31,7 @@ use Rector\DowngradePhp80\Rector\MethodCall\DowngradeReflectionGetAttributesRect
|
|||
use Rector\DowngradePhp80\Rector\MethodCall\DowngradeReflectionPropertyGetDefaultValueRector;
|
||||
use Rector\DowngradePhp80\Rector\New_\DowngradeArbitraryExpressionsSupportRector;
|
||||
use Rector\DowngradePhp80\Rector\NullsafeMethodCall\DowngradeNullsafeToTernaryOperatorRector;
|
||||
use Rector\DowngradePhp80\Rector\Property\DowngradeMixedTypeTypedPropertyRector;
|
||||
use Rector\DowngradePhp80\Rector\Property\DowngradeUnionTypeTypedPropertyRector;
|
||||
use Rector\DowngradePhp80\Rector\StaticCall\DowngradePhpTokenRector;
|
||||
use Rector\DowngradePhp80\ValueObject\DowngradeAttributeToAnnotation;
|
||||
|
@ -74,4 +75,5 @@ return static function (RectorConfig $rectorConfig) : void {
|
|||
$rectorConfig->rule(DowngradeArrayFilterNullableCallbackRector::class);
|
||||
$rectorConfig->rule(DowngradeNumberFormatNoFourthArgRector::class);
|
||||
$rectorConfig->rule(DowngradeStringReturnTypeOnToStringRector::class);
|
||||
$rectorConfig->rule(DowngradeMixedTypeTypedPropertyRector::class);
|
||||
};
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\DowngradePhp80\Rector\Property;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PHPStan\Type\MixedType;
|
||||
use Rector\CodeQuality\NodeFactory\PropertyTypeDecorator;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @see \Rector\Tests\DowngradePhp80\Rector\Property\DowngradeMixedTypeTypedPropertyRector\DowngradeMixedTypeTypedPropertyRectorTest
|
||||
*/
|
||||
final class DowngradeMixedTypeTypedPropertyRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\CodeQuality\NodeFactory\PropertyTypeDecorator
|
||||
*/
|
||||
private $propertyTypeDecorator;
|
||||
public function __construct(PropertyTypeDecorator $propertyTypeDecorator)
|
||||
{
|
||||
$this->propertyTypeDecorator = $propertyTypeDecorator;
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [Property::class];
|
||||
}
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Removes mixed type property type definition, adding `@var` annotations instead.', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
private mixed $property;
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
private $property;
|
||||
}
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
}
|
||||
/**
|
||||
* @param Property $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
if ($node->type === null) {
|
||||
return null;
|
||||
}
|
||||
if ($this->shouldSkip($node)) {
|
||||
return null;
|
||||
}
|
||||
$this->propertyTypeDecorator->decoratePropertyWithDocBlock($node, $node->type);
|
||||
$node->type = null;
|
||||
return $node;
|
||||
}
|
||||
private function shouldSkip(Property $property) : bool
|
||||
{
|
||||
if ($property->type === null) {
|
||||
return \true;
|
||||
}
|
||||
$type = $this->staticTypeMapper->mapPhpParserNodePHPStanType($property->type);
|
||||
if (!$type instanceof MixedType) {
|
||||
return \true;
|
||||
}
|
||||
return !$type->isExplicitMixed();
|
||||
}
|
||||
}
|
|
@ -16,11 +16,11 @@ final class VersionResolver
|
|||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '89a684f2b79f746464051f751e7291e5a2591ce2';
|
||||
public const PACKAGE_VERSION = 'e81691f1c68a976c1589830642cd45873389d962';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2022-06-27 10:26:21';
|
||||
public const RELEASE_DATE = '2022-06-27 14:26:13';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
|
@ -9,4 +9,4 @@ if (PHP_VERSION_ID < 50600) {
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInitca158ca952e68f74d38e1c9412f0fb32::getLoader();
|
||||
return ComposerAutoloaderInit7054cd214c077d9a6af690023f8bc423::getLoader();
|
||||
|
|
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
|
@ -1948,6 +1948,7 @@ return array(
|
|||
'Rector\\DowngradePhp80\\Rector\\MethodCall\\DowngradeReflectionPropertyGetDefaultValueRector' => $baseDir . '/rules/DowngradePhp80/Rector/MethodCall/DowngradeReflectionPropertyGetDefaultValueRector.php',
|
||||
'Rector\\DowngradePhp80\\Rector\\New_\\DowngradeArbitraryExpressionsSupportRector' => $baseDir . '/rules/DowngradePhp80/Rector/New_/DowngradeArbitraryExpressionsSupportRector.php',
|
||||
'Rector\\DowngradePhp80\\Rector\\NullsafeMethodCall\\DowngradeNullsafeToTernaryOperatorRector' => $baseDir . '/rules/DowngradePhp80/Rector/NullsafeMethodCall/DowngradeNullsafeToTernaryOperatorRector.php',
|
||||
'Rector\\DowngradePhp80\\Rector\\Property\\DowngradeMixedTypeTypedPropertyRector' => $baseDir . '/rules/DowngradePhp80/Rector/Property/DowngradeMixedTypeTypedPropertyRector.php',
|
||||
'Rector\\DowngradePhp80\\Rector\\Property\\DowngradeUnionTypeTypedPropertyRector' => $baseDir . '/rules/DowngradePhp80/Rector/Property/DowngradeUnionTypeTypedPropertyRector.php',
|
||||
'Rector\\DowngradePhp80\\Rector\\StaticCall\\DowngradePhpTokenRector' => $baseDir . '/rules/DowngradePhp80/Rector/StaticCall/DowngradePhpTokenRector.php',
|
||||
'Rector\\DowngradePhp80\\Reflection\\DefaultParameterValueResolver' => $baseDir . '/rules/DowngradePhp80/Reflection/DefaultParameterValueResolver.php',
|
||||
|
|
14
vendor/composer/autoload_real.php
vendored
14
vendor/composer/autoload_real.php
vendored
|
@ -2,7 +2,7 @@
|
|||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInitca158ca952e68f74d38e1c9412f0fb32
|
||||
class ComposerAutoloaderInit7054cd214c077d9a6af690023f8bc423
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,19 +22,19 @@ class ComposerAutoloaderInitca158ca952e68f74d38e1c9412f0fb32
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInitca158ca952e68f74d38e1c9412f0fb32', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit7054cd214c077d9a6af690023f8bc423', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInitca158ca952e68f74d38e1c9412f0fb32', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit7054cd214c077d9a6af690023f8bc423', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInitca158ca952e68f74d38e1c9412f0fb32::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit7054cd214c077d9a6af690023f8bc423::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$includeFiles = \Composer\Autoload\ComposerStaticInitca158ca952e68f74d38e1c9412f0fb32::$files;
|
||||
$includeFiles = \Composer\Autoload\ComposerStaticInit7054cd214c077d9a6af690023f8bc423::$files;
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
composerRequireca158ca952e68f74d38e1c9412f0fb32($fileIdentifier, $file);
|
||||
composerRequire7054cd214c077d9a6af690023f8bc423($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
|
@ -46,7 +46,7 @@ class ComposerAutoloaderInitca158ca952e68f74d38e1c9412f0fb32
|
|||
* @param string $file
|
||||
* @return void
|
||||
*/
|
||||
function composerRequireca158ca952e68f74d38e1c9412f0fb32($fileIdentifier, $file)
|
||||
function composerRequire7054cd214c077d9a6af690023f8bc423($fileIdentifier, $file)
|
||||
{
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
|
9
vendor/composer/autoload_static.php
vendored
9
vendor/composer/autoload_static.php
vendored
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInitca158ca952e68f74d38e1c9412f0fb32
|
||||
class ComposerStaticInit7054cd214c077d9a6af690023f8bc423
|
||||
{
|
||||
public static $files = array (
|
||||
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
|
||||
|
@ -2249,6 +2249,7 @@ class ComposerStaticInitca158ca952e68f74d38e1c9412f0fb32
|
|||
'Rector\\DowngradePhp80\\Rector\\MethodCall\\DowngradeReflectionPropertyGetDefaultValueRector' => __DIR__ . '/../..' . '/rules/DowngradePhp80/Rector/MethodCall/DowngradeReflectionPropertyGetDefaultValueRector.php',
|
||||
'Rector\\DowngradePhp80\\Rector\\New_\\DowngradeArbitraryExpressionsSupportRector' => __DIR__ . '/../..' . '/rules/DowngradePhp80/Rector/New_/DowngradeArbitraryExpressionsSupportRector.php',
|
||||
'Rector\\DowngradePhp80\\Rector\\NullsafeMethodCall\\DowngradeNullsafeToTernaryOperatorRector' => __DIR__ . '/../..' . '/rules/DowngradePhp80/Rector/NullsafeMethodCall/DowngradeNullsafeToTernaryOperatorRector.php',
|
||||
'Rector\\DowngradePhp80\\Rector\\Property\\DowngradeMixedTypeTypedPropertyRector' => __DIR__ . '/../..' . '/rules/DowngradePhp80/Rector/Property/DowngradeMixedTypeTypedPropertyRector.php',
|
||||
'Rector\\DowngradePhp80\\Rector\\Property\\DowngradeUnionTypeTypedPropertyRector' => __DIR__ . '/../..' . '/rules/DowngradePhp80/Rector/Property/DowngradeUnionTypeTypedPropertyRector.php',
|
||||
'Rector\\DowngradePhp80\\Rector\\StaticCall\\DowngradePhpTokenRector' => __DIR__ . '/../..' . '/rules/DowngradePhp80/Rector/StaticCall/DowngradePhpTokenRector.php',
|
||||
'Rector\\DowngradePhp80\\Reflection\\DefaultParameterValueResolver' => __DIR__ . '/../..' . '/rules/DowngradePhp80/Reflection/DefaultParameterValueResolver.php',
|
||||
|
@ -3407,9 +3408,9 @@ class ComposerStaticInitca158ca952e68f74d38e1c9412f0fb32
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInitca158ca952e68f74d38e1c9412f0fb32::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInitca158ca952e68f74d38e1c9412f0fb32::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInitca158ca952e68f74d38e1c9412f0fb32::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit7054cd214c077d9a6af690023f8bc423::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit7054cd214c077d9a6af690023f8bc423::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit7054cd214c077d9a6af690023f8bc423::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user