mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 21:38:22 +01:00
Updated Rector to commit 656836093ea0abd96860af062fdf6f67afe1f504
656836093e
[CodeQuality] Deprecate NarrowUnionTypeDocRector as focused on docblocks, and moving to type declarations (#3848)
This commit is contained in:
parent
83531b9b9d
commit
18b46b9b72
@ -12,7 +12,6 @@ use Rector\CodeQuality\Rector\Catch_\ThrowWithPreviousExceptionRector;
|
||||
use Rector\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector;
|
||||
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
|
||||
use Rector\CodeQuality\Rector\ClassMethod\InlineArrayReturnAssignRector;
|
||||
use Rector\CodeQuality\Rector\ClassMethod\NarrowUnionTypeDocRector;
|
||||
use Rector\CodeQuality\Rector\ClassMethod\OptionalParametersAfterRequiredRector;
|
||||
use Rector\CodeQuality\Rector\ClassMethod\ReturnTypeFromStrictScalarReturnExprRector;
|
||||
use Rector\CodeQuality\Rector\Concat\JoinStringConcatRector;
|
||||
@ -113,5 +112,5 @@ return static function (RectorConfig $rectorConfig) : void {
|
||||
'mbstrrpos' => 'mb_strrpos',
|
||||
'mbsubstr' => 'mb_substr',
|
||||
]);
|
||||
$rectorConfig->rules([CombinedAssignRector::class, SimplifyEmptyArrayCheckRector::class, ReplaceMultipleBooleanNotRector::class, ForeachToInArrayRector::class, SimplifyForeachToCoalescingRector::class, SimplifyFuncGetArgsCountRector::class, SimplifyInArrayValuesRector::class, SimplifyStrposLowerRector::class, GetClassToInstanceOfRector::class, SimplifyArraySearchRector::class, SimplifyConditionsRector::class, SimplifyIfNotNullReturnRector::class, SimplifyIfReturnBoolRector::class, SimplifyUselessVariableRector::class, UnnecessaryTernaryExpressionRector::class, RemoveExtraParametersRector::class, SimplifyDeMorganBinaryRector::class, SimplifyTautologyTernaryRector::class, SimplifyForeachToArrayFilterRector::class, SingleInArrayToCompareRector::class, SimplifyIfElseToTernaryRector::class, JoinStringConcatRector::class, ConsecutiveNullCompareReturnsToNullCoalesceQueueRector::class, ExplicitBoolCompareRector::class, CombineIfRector::class, UseIdenticalOverEqualWithSameTypeRector::class, SimplifyBoolIdenticalTrueRector::class, SimplifyRegexPatternRector::class, BooleanNotIdenticalToNotIdenticalRector::class, StrvalToTypeCastRector::class, FloatvalToTypeCastRector::class, CallableThisArrayToAnonymousFunctionRector::class, AndAssignsToSeparateLinesRector::class, CompactToVariablesRector::class, CompleteDynamicPropertiesRector::class, IsAWithStringWithThirdArgumentRector::class, StrlenZeroToIdenticalEmptyStringRector::class, RemoveAlwaysTrueConditionSetInConstructorRector::class, ThrowWithPreviousExceptionRector::class, RemoveSoleValueSprintfRector::class, ShortenElseIfRector::class, AddPregQuoteDelimiterRector::class, ArrayMergeOfNonArraysToSimpleArrayRector::class, IntvalToTypeCastRector::class, BoolvalToTypeCastRector::class, ArrayKeyExistsTernaryThenValueToCoalescingRector::class, AbsolutizeRequireAndIncludePathRector::class, ChangeArrayPushToArrayAssignRector::class, ForRepeatedCountToOwnVariableRector::class, ForeachItemsAssignToEmptyArrayToAssignRector::class, InlineIfToExplicitIfRector::class, ArrayKeysAndInArrayToArrayKeyExistsRector::class, UnusedForeachValueToArrayKeysRector::class, CommonNotEqualRector::class, SetTypeToCastRector::class, LogicalToBooleanRector::class, VarToPublicPropertyRector::class, IssetOnPropertyObjectToPropertyExistsRector::class, NewStaticToNewSelfRector::class, UnwrapSprintfOneArgumentRector::class, SwitchNegatedTernaryRector::class, SingularSwitchToIfRector::class, SimplifyIfNullableReturnRector::class, NarrowUnionTypeDocRector::class, FuncGetArgsToVariadicParamRector::class, CallUserFuncToMethodCallRector::class, CallUserFuncWithArrowFunctionToInlineRector::class, CountArrayToEmptyArrayComparisonRector::class, FlipTypeControlToUseExclusiveTypeRector::class, ExplicitMethodCallOverMagicGetSetRector::class, InlineArrayReturnAssignRector::class, InlineIsAInstanceOfRector::class, TernaryFalseExpressionToIfRector::class, InlineConstructorDefaultToPropertyRector::class, ReturnTypeFromStrictScalarReturnExprRector::class, TernaryEmptyArrayArrayDimFetchToCoalesceRector::class, OptionalParametersAfterRequiredRector::class, SimplifyEmptyCheckOnEmptyArrayRector::class, SwitchTrueToIfRector::class, CleanupUnneededNullsafeOperatorRector::class, MakeTypedPropertyNullableIfCheckedRector::class, DisallowedEmptyRuleFixerRector::class]);
|
||||
$rectorConfig->rules([CombinedAssignRector::class, SimplifyEmptyArrayCheckRector::class, ReplaceMultipleBooleanNotRector::class, ForeachToInArrayRector::class, SimplifyForeachToCoalescingRector::class, SimplifyFuncGetArgsCountRector::class, SimplifyInArrayValuesRector::class, SimplifyStrposLowerRector::class, GetClassToInstanceOfRector::class, SimplifyArraySearchRector::class, SimplifyConditionsRector::class, SimplifyIfNotNullReturnRector::class, SimplifyIfReturnBoolRector::class, SimplifyUselessVariableRector::class, UnnecessaryTernaryExpressionRector::class, RemoveExtraParametersRector::class, SimplifyDeMorganBinaryRector::class, SimplifyTautologyTernaryRector::class, SimplifyForeachToArrayFilterRector::class, SingleInArrayToCompareRector::class, SimplifyIfElseToTernaryRector::class, JoinStringConcatRector::class, ConsecutiveNullCompareReturnsToNullCoalesceQueueRector::class, ExplicitBoolCompareRector::class, CombineIfRector::class, UseIdenticalOverEqualWithSameTypeRector::class, SimplifyBoolIdenticalTrueRector::class, SimplifyRegexPatternRector::class, BooleanNotIdenticalToNotIdenticalRector::class, StrvalToTypeCastRector::class, FloatvalToTypeCastRector::class, CallableThisArrayToAnonymousFunctionRector::class, AndAssignsToSeparateLinesRector::class, CompactToVariablesRector::class, CompleteDynamicPropertiesRector::class, IsAWithStringWithThirdArgumentRector::class, StrlenZeroToIdenticalEmptyStringRector::class, RemoveAlwaysTrueConditionSetInConstructorRector::class, ThrowWithPreviousExceptionRector::class, RemoveSoleValueSprintfRector::class, ShortenElseIfRector::class, AddPregQuoteDelimiterRector::class, ArrayMergeOfNonArraysToSimpleArrayRector::class, IntvalToTypeCastRector::class, BoolvalToTypeCastRector::class, ArrayKeyExistsTernaryThenValueToCoalescingRector::class, AbsolutizeRequireAndIncludePathRector::class, ChangeArrayPushToArrayAssignRector::class, ForRepeatedCountToOwnVariableRector::class, ForeachItemsAssignToEmptyArrayToAssignRector::class, InlineIfToExplicitIfRector::class, ArrayKeysAndInArrayToArrayKeyExistsRector::class, UnusedForeachValueToArrayKeysRector::class, CommonNotEqualRector::class, SetTypeToCastRector::class, LogicalToBooleanRector::class, VarToPublicPropertyRector::class, IssetOnPropertyObjectToPropertyExistsRector::class, NewStaticToNewSelfRector::class, UnwrapSprintfOneArgumentRector::class, SwitchNegatedTernaryRector::class, SingularSwitchToIfRector::class, SimplifyIfNullableReturnRector::class, FuncGetArgsToVariadicParamRector::class, CallUserFuncToMethodCallRector::class, CallUserFuncWithArrowFunctionToInlineRector::class, CountArrayToEmptyArrayComparisonRector::class, FlipTypeControlToUseExclusiveTypeRector::class, ExplicitMethodCallOverMagicGetSetRector::class, InlineArrayReturnAssignRector::class, InlineIsAInstanceOfRector::class, TernaryFalseExpressionToIfRector::class, InlineConstructorDefaultToPropertyRector::class, ReturnTypeFromStrictScalarReturnExprRector::class, TernaryEmptyArrayArrayDimFetchToCoalesceRector::class, OptionalParametersAfterRequiredRector::class, SimplifyEmptyCheckOnEmptyArrayRector::class, SwitchTrueToIfRector::class, CleanupUnneededNullsafeOperatorRector::class, MakeTypedPropertyNullableIfCheckedRector::class, DisallowedEmptyRuleFixerRector::class]);
|
||||
};
|
||||
|
@ -4,15 +4,12 @@ declare (strict_types=1);
|
||||
namespace Rector\PHPStanStaticTypeMapper\TypeAnalyzer;
|
||||
|
||||
use PHPStan\Type\ArrayType;
|
||||
use PHPStan\Type\Constant\ConstantStringType;
|
||||
use PHPStan\Type\IterableType;
|
||||
use PHPStan\Type\NullType;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use PHPStan\Type\ObjectWithoutClassType;
|
||||
use PHPStan\Type\TypeWithClassName;
|
||||
use PHPStan\Type\UnionType;
|
||||
use Rector\PHPStanStaticTypeMapper\ValueObject\UnionTypeAnalysis;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
use Traversable;
|
||||
final class UnionTypeAnalyzer
|
||||
{
|
||||
@ -56,52 +53,6 @@ final class UnionTypeAnalyzer
|
||||
}
|
||||
return $typesWithClassNames;
|
||||
}
|
||||
public function hasObjectWithoutClassType(UnionType $unionType) : bool
|
||||
{
|
||||
$types = $unionType->getTypes();
|
||||
foreach ($types as $type) {
|
||||
if ($type instanceof ObjectWithoutClassType) {
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
public function hasObjectWithoutClassTypeWithOnlyFullyQualifiedObjectType(UnionType $unionType) : bool
|
||||
{
|
||||
$types = $unionType->getTypes();
|
||||
foreach ($types as $type) {
|
||||
if ($type instanceof ObjectWithoutClassType) {
|
||||
continue;
|
||||
}
|
||||
if (!$type instanceof FullyQualifiedObjectType) {
|
||||
return \false;
|
||||
}
|
||||
}
|
||||
return \true;
|
||||
}
|
||||
public function isScalar(UnionType $unionType) : bool
|
||||
{
|
||||
$types = $unionType->getTypes();
|
||||
if (\count($types) !== 4) {
|
||||
return \false;
|
||||
}
|
||||
foreach ($types as $type) {
|
||||
if ($type->isString()->yes() && !$type instanceof ConstantStringType) {
|
||||
continue;
|
||||
}
|
||||
if ($type->isFloat()->yes()) {
|
||||
continue;
|
||||
}
|
||||
if ($type->isInteger()->yes()) {
|
||||
continue;
|
||||
}
|
||||
if ($type->isBoolean()->yes()) {
|
||||
continue;
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
return \true;
|
||||
}
|
||||
public function isNullable(UnionType $unionType, bool $checkTwoTypes = \false) : bool
|
||||
{
|
||||
$types = $unionType->getTypes();
|
||||
|
@ -5,28 +5,14 @@ namespace Rector\CodeQuality\Rector\ClassMethod;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
|
||||
use PHPStan\Type\UnionType;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\PHPStanStaticTypeMapper\TypeAnalyzer\UnionTypeAnalyzer;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @see \Rector\Tests\CodeQuality\Rector\ClassMethod\NarrowUnionTypeDocRector\NarrowUnionTypeDocRectorTest
|
||||
* @deprecated This split is deprecated as dangerous to rely on docblock strings. Instead, use strict type declaration rules.
|
||||
*/
|
||||
final class NarrowUnionTypeDocRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\PHPStanStaticTypeMapper\TypeAnalyzer\UnionTypeAnalyzer
|
||||
*/
|
||||
private $unionTypeAnalyzer;
|
||||
public function __construct(UnionTypeAnalyzer $unionTypeAnalyzer)
|
||||
{
|
||||
$this->unionTypeAnalyzer = $unionTypeAnalyzer;
|
||||
}
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Changes docblock by narrowing type', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
@ -63,54 +49,9 @@ CODE_SAMPLE
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node);
|
||||
$params = $node->getParams();
|
||||
$hasChanged = \false;
|
||||
foreach ($params as $key => $param) {
|
||||
/** @var string $paramName */
|
||||
$paramName = $this->getName($param->var);
|
||||
$paramType = $phpDocInfo->getParamType($paramName);
|
||||
if (!$paramType instanceof UnionType) {
|
||||
continue;
|
||||
}
|
||||
if ($this->unionTypeAnalyzer->isScalar($paramType)) {
|
||||
$this->changeDocObjectScalar($key, $phpDocInfo);
|
||||
$hasChanged = \true;
|
||||
continue;
|
||||
}
|
||||
if ($this->unionTypeAnalyzer->hasObjectWithoutClassType($paramType)) {
|
||||
$this->changeDocObjectWithoutClassType($paramType, $key, $phpDocInfo);
|
||||
$hasChanged = \true;
|
||||
}
|
||||
}
|
||||
if ($hasChanged) {
|
||||
return $node;
|
||||
}
|
||||
$errorMessage = \sprintf('Rule "%s" is deprecated, as we moved from docblocks for type declarations. Use strict type rules instead', self::class);
|
||||
\trigger_error($errorMessage, \E_USER_WARNING);
|
||||
\sleep(3);
|
||||
return null;
|
||||
}
|
||||
private function changeDocObjectWithoutClassType(UnionType $unionType, int $key, PhpDocInfo $phpDocInfo) : void
|
||||
{
|
||||
if (!$this->unionTypeAnalyzer->hasObjectWithoutClassTypeWithOnlyFullyQualifiedObjectType($unionType)) {
|
||||
return;
|
||||
}
|
||||
$types = $unionType->getTypes();
|
||||
$resultType = '';
|
||||
foreach ($types as $type) {
|
||||
if ($type instanceof FullyQualifiedObjectType) {
|
||||
$resultType .= $type->getClassName() . '|';
|
||||
}
|
||||
}
|
||||
$resultType = \rtrim($resultType, '|');
|
||||
$paramTagValueNodes = $phpDocInfo->getParamTagValueNodes();
|
||||
if (isset($paramTagValueNodes[$key])) {
|
||||
$paramTagValueNodes[$key]->type = new IdentifierTypeNode($resultType);
|
||||
}
|
||||
}
|
||||
private function changeDocObjectScalar(int $key, PhpDocInfo $phpDocInfo) : void
|
||||
{
|
||||
$paramTagValueNodes = $phpDocInfo->getParamTagValueNodes();
|
||||
if (isset($paramTagValueNodes[$key])) {
|
||||
$paramTagValueNodes[$key]->type = new IdentifierTypeNode('scalar');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ use Rector\VersionBonding\Contract\MinPhpVersionInterface;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @deprecated This split is deprecated as dangerous to rely on doblock strings. Instead, use strict type declaration rules.
|
||||
* @deprecated This split is deprecated as dangerous to rely on docblock strings. Instead, use strict type declaration rules.
|
||||
*/
|
||||
final class UnionTypesRector extends AbstractRector implements MinPhpVersionInterface
|
||||
{
|
||||
|
@ -101,6 +101,7 @@ final class VisibilityManipulator
|
||||
$this->replaceVisibilityFlag($node, Visibility::PRIVATE);
|
||||
}
|
||||
/**
|
||||
* @api
|
||||
* @param \PhpParser\Node\Stmt\Class_|\PhpParser\Node\Stmt\ClassConst $node
|
||||
*/
|
||||
public function removeFinal($node) : void
|
||||
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '4ac2cf87c569ec8ebea4d631d684439c16dd296d';
|
||||
public const PACKAGE_VERSION = '656836093ea0abd96860af062fdf6f67afe1f504';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-05-14 16:45:41';
|
||||
public const RELEASE_DATE = '2023-05-14 16:53:35';
|
||||
/**
|
||||
* @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 ComposerAutoloaderInit5334ed6dce4a35a0df9c8e69b44ad504::getLoader();
|
||||
return ComposerAutoloaderInitdc63d1d77983e59462b2fefb99369e9f::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 ComposerAutoloaderInit5334ed6dce4a35a0df9c8e69b44ad504
|
||||
class ComposerAutoloaderInitdc63d1d77983e59462b2fefb99369e9f
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@ -22,17 +22,17 @@ class ComposerAutoloaderInit5334ed6dce4a35a0df9c8e69b44ad504
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit5334ed6dce4a35a0df9c8e69b44ad504', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInitdc63d1d77983e59462b2fefb99369e9f', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit5334ed6dce4a35a0df9c8e69b44ad504', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInitdc63d1d77983e59462b2fefb99369e9f', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit5334ed6dce4a35a0df9c8e69b44ad504::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInitdc63d1d77983e59462b2fefb99369e9f::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit5334ed6dce4a35a0df9c8e69b44ad504::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInitdc63d1d77983e59462b2fefb99369e9f::$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 ComposerStaticInit5334ed6dce4a35a0df9c8e69b44ad504
|
||||
class ComposerStaticInitdc63d1d77983e59462b2fefb99369e9f
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
@ -3109,9 +3109,9 @@ class ComposerStaticInit5334ed6dce4a35a0df9c8e69b44ad504
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit5334ed6dce4a35a0df9c8e69b44ad504::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit5334ed6dce4a35a0df9c8e69b44ad504::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit5334ed6dce4a35a0df9c8e69b44ad504::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInitdc63d1d77983e59462b2fefb99369e9f::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInitdc63d1d77983e59462b2fefb99369e9f::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInitdc63d1d77983e59462b2fefb99369e9f::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user