From 27ee0144e3dafbe86e8bc186af5db13aab4eeef9 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 19 Nov 2024 23:27:44 +0700 Subject: [PATCH 01/27] Use rector-src#dev-upgrade-to-php-parser5-and-phpstan-2 --- composer.json | 10 +++------- phpstan.neon | 33 +++++++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/composer.json b/composer.json index 3236c8e5..b712cb8d 100644 --- a/composer.json +++ b/composer.json @@ -8,14 +8,10 @@ }, "require-dev": { "phpstan/extension-installer": "^1.3", - "phpstan/phpstan": "^1.10", - "phpstan/phpstan-webmozart-assert": "^1.2", + "phpstan/phpstan": "^2.0", "phpunit/phpunit": "^10.5", - "rector/rector-src": "dev-main", - "rector/type-perfect": "^1.0", + "rector/rector-src": "dev-upgrade-to-php-parser5-and-phpstan-2", "symplify/easy-coding-standard": "^12.3", - "symplify/phpstan-extensions": "^11.4", - "symplify/phpstan-rules": "^13.0", "symplify/rule-doc-generator": "^12.2", "symplify/vendor-patches": "^11.3", "tomasvotruba/class-leak": "^1.0", @@ -33,7 +29,7 @@ "classmap": ["stubs"] }, "scripts": { - "phpstan": "vendor/bin/phpstan analyse --ansi --error-format symplify", + "phpstan": "vendor/bin/phpstan analyse --ansi", "check-cs": "vendor/bin/ecs check --ansi", "fix-cs": "vendor/bin/ecs check --fix --ansi" }, diff --git a/phpstan.neon b/phpstan.neon index 031c676e..155418cc 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,6 +1,7 @@ -includes: - - vendor/symplify/phpstan-rules/config/symplify-rules.neon - - vendor/symplify/phpstan-rules/config/rector-rules.neon +# to be enabled later once rector upgraded to use phpstan v2 +# includes: +# - vendor/symplify/phpstan-rules/config/symplify-rules.neon +# - vendor/symplify/phpstan-rules/config/rector-rules.neon parameters: level: 8 @@ -10,6 +11,8 @@ parameters: # requires exact closure types checkMissingCallableSignature: true + treatPhpDocTypesAsCertain: false + paths: - src - config @@ -24,11 +27,12 @@ parameters: - '*/Source/*' # see https://github.com/rectorphp/type-perfect/ - type_perfect: - no_mixed: true - null_over_false: true - narrow_param: true - narrow_return: true +# to be enabled later once rector upgraded to use phpstan v2 +# type_perfect: +# no_mixed: true +# null_over_false: true +# narrow_param: true +# narrow_return: true ignoreErrors: # php enum value minus @@ -55,3 +59,16 @@ parameters: message: '#Parameter \#1 \$attributeClass of class Rector\\DowngradePhp80\\ValueObject\\DowngradeAttributeToAnnotation constructor expects class\-string, string given#' path: "config/*" + # more advanced usage, but not always working + # see https://github.com/rectorphp/rector-src/actions/runs/11798721617/job/32865546672?pr=6422#step:5:110 + - '#Doing instanceof PHPStan\\Type\\.+ is error\-prone and deprecated#' + + # follow parent signature + - + identifier: return.unusedType + + # phpstan instanceof + - + identifier: phpstanApi.instanceofAssumption + + - '#Asking about instanceof PHPStan\\.* is not covered by backward compatibility promise#' From 0249dd841b77ed4a061c06ebd53aa6900934d8ce Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 19 Nov 2024 23:33:56 +0700 Subject: [PATCH 02/27] update to php-parser 5 nodes --- .../NodeManipulator/JsonConstCleaner.php | 10 +++++----- .../PhpDoc/NativeParamToPhpDocDecorator.php | 3 ++- ...owngradePregUnmatchedAsNullConstantRector.php | 4 ++-- .../ConstFetch/DowngradePhp73JsonConstRector.php | 5 ----- .../SetCookieOptionsArrayToArgumentsRector.php | 2 +- .../DowngradeListReferenceAssignmentRector.php | 16 ++++++++-------- .../DowngradeFlexibleHeredocSyntaxRector.php | 6 +++--- ...edByNewlineOnlyMaybeWithSemicolonAnalyzer.php | 2 +- .../Rector/Array_/DowngradeArraySpreadRector.php | 2 +- .../ArrowFunctionToAnonymousFunctionRector.php | 2 +- .../DowngradeContravariantArgumentTypeRector.php | 4 ++-- .../DowngradeNumericLiteralSeparatorRector.php | 14 +++++++------- .../NodeAnalyzer/UnnamedArgumentResolver.php | 4 ++-- .../DowngradeDereferenceableOperationRector.php | 4 ++-- ...wngradeAbstractPrivateMethodInTraitRector.php | 4 ++-- .../DowngradeTrailingCommasInParamUseRector.php | 2 +- .../Class_/DowngradePropertyPromotionRector.php | 4 ++-- .../Expression/DowngradeMatchToSwitchRector.php | 2 +- ...owngradeArrayFilterNullableCallbackRector.php | 4 ++-- .../FuncCall/DowngradeStrEndsWithRector.php | 6 +++--- .../FuncCall/DowngradeStrStartsWithRector.php | 6 +++--- ...deReflectionClassGetConstantsFilterRector.php | 2 +- .../DowngradeUnionTypeTypedPropertyRector.php | 2 +- .../StaticCall/DowngradePhpTokenRector.php | 6 +++--- .../NodeAnalyzer/ArraySpreadAnalyzer.php | 2 +- .../ArrayMergeFromArraySpreadFactory.php | 4 ++-- .../DowngradeArraySpreadStringKeyRector.php | 2 +- .../DowngradeFirstClassCallableSyntaxRector.php | 2 +- .../LNumber/DowngradeOctalNumberRector.php | 8 ++++---- .../PhpDocFromTypeDeclarationDecorator.php | 5 +++-- 30 files changed, 68 insertions(+), 71 deletions(-) diff --git a/rules/DowngradePhp72/NodeManipulator/JsonConstCleaner.php b/rules/DowngradePhp72/NodeManipulator/JsonConstCleaner.php index ead1f9c8..6b2ce54a 100644 --- a/rules/DowngradePhp72/NodeManipulator/JsonConstCleaner.php +++ b/rules/DowngradePhp72/NodeManipulator/JsonConstCleaner.php @@ -4,11 +4,11 @@ namespace Rector\DowngradePhp72\NodeManipulator; +use PhpParser\Node\Scalar\Int_; use PhpParser\Node; use PhpParser\Node\Expr; use PhpParser\Node\Expr\BinaryOp\BitwiseOr; use PhpParser\Node\Expr\ConstFetch; -use PhpParser\Node\Scalar\LNumber; use Rector\Enum\JsonConstant; use Rector\NodeNameResolver\NodeNameResolver; use Rector\NodeTypeResolver\Node\AttributeKey; @@ -35,19 +35,19 @@ public function clean(ConstFetch|BitwiseOr $node, array $constants): Expr|null /** * @param array $constants */ - private function cleanByConstFetch(ConstFetch $constFetch, array $constants): ?LNumber + private function cleanByConstFetch(ConstFetch $constFetch, array $constants): ?Int_ { if (! $this->nodeNameResolver->isNames($constFetch, $constants)) { return null; } - return new LNumber(0); + return new Int_(0); } /** * @param array $constants */ - private function cleanByBitwiseOr(BitwiseOr $bitwiseOr, array $constants): null|Expr|LNumber + private function cleanByBitwiseOr(BitwiseOr $bitwiseOr, array $constants): null|Expr|Int_ { $isLeftTransformed = $this->isTransformed($bitwiseOr->left, $constants); $isRightTransformed = $this->isTransformed($bitwiseOr->right, $constants); @@ -64,7 +64,7 @@ private function cleanByBitwiseOr(BitwiseOr $bitwiseOr, array $constants): null| return $bitwiseOr->right; } - return new LNumber(0); + return new Int_(0); } /** diff --git a/rules/DowngradePhp72/PhpDoc/NativeParamToPhpDocDecorator.php b/rules/DowngradePhp72/PhpDoc/NativeParamToPhpDocDecorator.php index be2298be..ea68d72c 100644 --- a/rules/DowngradePhp72/PhpDoc/NativeParamToPhpDocDecorator.php +++ b/rules/DowngradePhp72/PhpDoc/NativeParamToPhpDocDecorator.php @@ -4,6 +4,7 @@ namespace Rector\DowngradePhp72\PhpDoc; +use PhpParser\Node; use PhpParser\Node\Expr; use PhpParser\Node\Param; use PhpParser\Node\Stmt\ClassMethod; @@ -29,7 +30,7 @@ public function __construct( public function decorate(ClassMethod $classMethod, Param $param): void { - if ($param->type === null) { + if (!$param->type instanceof Node) { return; } diff --git a/rules/DowngradePhp72/Rector/FuncCall/DowngradePregUnmatchedAsNullConstantRector.php b/rules/DowngradePhp72/Rector/FuncCall/DowngradePregUnmatchedAsNullConstantRector.php index 36f6b999..460ccd88 100644 --- a/rules/DowngradePhp72/Rector/FuncCall/DowngradePregUnmatchedAsNullConstantRector.php +++ b/rules/DowngradePhp72/Rector/FuncCall/DowngradePregUnmatchedAsNullConstantRector.php @@ -4,6 +4,7 @@ namespace Rector\DowngradePhp72\Rector\FuncCall; +use PhpParser\Node\Scalar\Int_; use PhpParser\Node; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\BinaryOp\BitwiseOr; @@ -14,7 +15,6 @@ use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Param; -use PhpParser\Node\Scalar\LNumber; use PhpParser\Node\Scalar\String_; use PhpParser\Node\Stmt; use PhpParser\Node\Stmt\ClassConst; @@ -150,7 +150,7 @@ private function refactorClassConst(ClassConst $classConst): ?ClassConst continue; } - $classConst->consts[$key]->value = new LNumber(512); + $classConst->consts[$key]->value = new Int_(512); return $classConst; } diff --git a/rules/DowngradePhp73/Rector/ConstFetch/DowngradePhp73JsonConstRector.php b/rules/DowngradePhp73/Rector/ConstFetch/DowngradePhp73JsonConstRector.php index 7677d90c..1fe795c5 100644 --- a/rules/DowngradePhp73/Rector/ConstFetch/DowngradePhp73JsonConstRector.php +++ b/rules/DowngradePhp73/Rector/ConstFetch/DowngradePhp73JsonConstRector.php @@ -266,11 +266,6 @@ private function hasConstFetchInBitwiseOr(BitwiseOr $bitwiseOr, string $constNam $found = false; foreach ([$bitwiseOr->left, $bitwiseOr->right] as $subNode) { - // Only `Node` instances can hold the constant. - if (! ($subNode instanceof Node)) { - continue; - } - $found = match (true) { $subNode instanceof BitwiseOr => ( $this->hasConstFetchInBitwiseOr($subNode, $constName) diff --git a/rules/DowngradePhp73/Rector/FuncCall/SetCookieOptionsArrayToArgumentsRector.php b/rules/DowngradePhp73/Rector/FuncCall/SetCookieOptionsArrayToArgumentsRector.php index 05597a21..8ad0a285 100644 --- a/rules/DowngradePhp73/Rector/FuncCall/SetCookieOptionsArrayToArgumentsRector.php +++ b/rules/DowngradePhp73/Rector/FuncCall/SetCookieOptionsArrayToArgumentsRector.php @@ -4,11 +4,11 @@ namespace Rector\DowngradePhp73\Rector\FuncCall; +use PhpParser\Node\ArrayItem; use PhpParser\BuilderHelpers; use PhpParser\Node; use PhpParser\Node\Arg; use PhpParser\Node\Expr\Array_; -use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Scalar\String_; use Rector\Exception\ShouldNotHappenException; diff --git a/rules/DowngradePhp73/Rector/List_/DowngradeListReferenceAssignmentRector.php b/rules/DowngradePhp73/Rector/List_/DowngradeListReferenceAssignmentRector.php index 4e1a95ba..9b9160b3 100644 --- a/rules/DowngradePhp73/Rector/List_/DowngradeListReferenceAssignmentRector.php +++ b/rules/DowngradePhp73/Rector/List_/DowngradeListReferenceAssignmentRector.php @@ -4,16 +4,16 @@ namespace Rector\DowngradePhp73\Rector\List_; +use PhpParser\Node\ArrayItem; +use PhpParser\Node\Scalar\Int_; use PhpParser\BuilderHelpers; use PhpParser\Node; use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\ArrayDimFetch; -use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\AssignRef; use PhpParser\Node\Expr\List_; use PhpParser\Node\Expr\Variable; -use PhpParser\Node\Scalar\LNumber; use PhpParser\Node\Scalar\String_; use PhpParser\Node\Stmt\Expression; use Rector\Rector\AbstractRector; @@ -157,7 +157,7 @@ private function shouldSkipAssign(Assign $assign, List_ | Array_ $arrayOrList): /** * Count the number of params by reference placed at the end * These params are not needed anymore, so they can be removed - * @param (ArrayItem|null)[] $listItems + * @param (ArrayItem | null)[] $listItems */ private function countRightSideMostParamsByRefOrEmpty(array $listItems): int { @@ -192,7 +192,7 @@ private function countRightSideMostParamsByRefOrEmpty(array $listItems): int } /** - * @param (ArrayItem|null)[] $listItems + * @param (ArrayItem | null)[] $listItems * @param (int|string)[] $nestedArrayIndexes * @return Node\Stmt[] */ @@ -250,7 +250,7 @@ private function createAssignRefArrayFromListReferences( * - list(&$a, $b) * - list($a, $b, list(&$c, $d)) * - * @param (ArrayItem|null)[] $items + * @param (ArrayItem | null)[] $items */ private function hasAnyItemByRef(array $items): bool { @@ -262,7 +262,7 @@ private function hasAnyItemByRef(array $items): bool * - list(&$a, &$b) * - list(&$a, &$b, list(&$c, &$d)) * - * @param (ArrayItem|null)[] $items + * @param (ArrayItem | null)[] $items */ private function hasAllItemsByRef(array $items): bool { @@ -278,7 +278,7 @@ private function getArrayItemKey(ArrayItem $arrayItem, int | string $position): return $arrayItem->key->value; } - if ($arrayItem->key instanceof LNumber) { + if ($arrayItem->key instanceof Int_) { return $arrayItem->key->value; } @@ -309,7 +309,7 @@ private function createAssignRefWithArrayDimFetch( } /** - * @param array $arrayItems + * @param array<(ArrayItem | null)> $arrayItems * @return ArrayItem[] */ private function getItemsByRef(array $arrayItems, int $condition): array diff --git a/rules/DowngradePhp73/Rector/String_/DowngradeFlexibleHeredocSyntaxRector.php b/rules/DowngradePhp73/Rector/String_/DowngradeFlexibleHeredocSyntaxRector.php index 7dbeaa25..77fa07e9 100644 --- a/rules/DowngradePhp73/Rector/String_/DowngradeFlexibleHeredocSyntaxRector.php +++ b/rules/DowngradePhp73/Rector/String_/DowngradeFlexibleHeredocSyntaxRector.php @@ -4,8 +4,8 @@ namespace Rector\DowngradePhp73\Rector\String_; +use PhpParser\Node\Scalar\InterpolatedString; use PhpParser\Node; -use PhpParser\Node\Scalar\Encapsed; use PhpParser\Node\Scalar\String_; use Rector\DowngradePhp73\Tokenizer\FollowedByNewlineOnlyMaybeWithSemicolonAnalyzer; use Rector\NodeTypeResolver\Node\AttributeKey; @@ -59,11 +59,11 @@ public function getRuleDefinition(): RuleDefinition */ public function getNodeTypes(): array { - return [String_::class, Encapsed::class]; + return [String_::class, InterpolatedString::class]; } /** - * @param Encapsed|String_ $node + * @param InterpolatedString|String_ $node */ public function refactor(Node $node): ?Node { diff --git a/rules/DowngradePhp73/Tokenizer/FollowedByNewlineOnlyMaybeWithSemicolonAnalyzer.php b/rules/DowngradePhp73/Tokenizer/FollowedByNewlineOnlyMaybeWithSemicolonAnalyzer.php index c1993f05..1072702b 100644 --- a/rules/DowngradePhp73/Tokenizer/FollowedByNewlineOnlyMaybeWithSemicolonAnalyzer.php +++ b/rules/DowngradePhp73/Tokenizer/FollowedByNewlineOnlyMaybeWithSemicolonAnalyzer.php @@ -21,6 +21,6 @@ public function isFollowed(File $file, Node $node): bool return ! isset($oldTokens[$nextTokenPosition]) || isset($oldTokens[$nextTokenPosition][1]) && - \str_starts_with($oldTokens[$nextTokenPosition][1], "\n"); + \str_starts_with((string) $oldTokens[$nextTokenPosition][1], "\n"); } } diff --git a/rules/DowngradePhp74/Rector/Array_/DowngradeArraySpreadRector.php b/rules/DowngradePhp74/Rector/Array_/DowngradeArraySpreadRector.php index 2e08c378..3f569671 100644 --- a/rules/DowngradePhp74/Rector/Array_/DowngradeArraySpreadRector.php +++ b/rules/DowngradePhp74/Rector/Array_/DowngradeArraySpreadRector.php @@ -4,9 +4,9 @@ namespace Rector\DowngradePhp74\Rector\Array_; +use PhpParser\Node\ArrayItem; use PhpParser\Node; use PhpParser\Node\Expr\Array_; -use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\Expr\ClassConstFetch; use PhpParser\Node\Identifier; use PhpParser\Node\Name; diff --git a/rules/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector.php b/rules/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector.php index 55c4045a..c16d7d16 100644 --- a/rules/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector.php +++ b/rules/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector.php @@ -4,12 +4,12 @@ namespace Rector\DowngradePhp74\Rector\ArrowFunction; +use PhpParser\Node\ClosureUse; use PhpParser\Node; use PhpParser\Node\Expr; use PhpParser\Node\Expr\ArrowFunction; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\Closure; -use PhpParser\Node\Expr\ClosureUse; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Stmt\Return_; use PhpParser\Node\Stmt\Throw_; diff --git a/rules/DowngradePhp74/Rector/ClassMethod/DowngradeContravariantArgumentTypeRector.php b/rules/DowngradePhp74/Rector/ClassMethod/DowngradeContravariantArgumentTypeRector.php index 8e7755d6..cf243031 100644 --- a/rules/DowngradePhp74/Rector/ClassMethod/DowngradeContravariantArgumentTypeRector.php +++ b/rules/DowngradePhp74/Rector/ClassMethod/DowngradeContravariantArgumentTypeRector.php @@ -125,7 +125,7 @@ private function isNullableParam(Param $param, ClassMethod|Function_ $functionLi return false; } - if ($param->type === null) { + if (!$param->type instanceof Node) { return false; } @@ -262,7 +262,7 @@ private function refactorParam(Param $param, ClassMethod | Function_ $functionLi private function decorateWithDocBlock(ClassMethod | Function_ $functionLike, Param $param): void { - if ($param->type === null) { + if (!$param->type instanceof Node) { return; } diff --git a/rules/DowngradePhp74/Rector/LNumber/DowngradeNumericLiteralSeparatorRector.php b/rules/DowngradePhp74/Rector/LNumber/DowngradeNumericLiteralSeparatorRector.php index 406f03bc..8caf5cfd 100644 --- a/rules/DowngradePhp74/Rector/LNumber/DowngradeNumericLiteralSeparatorRector.php +++ b/rules/DowngradePhp74/Rector/LNumber/DowngradeNumericLiteralSeparatorRector.php @@ -4,9 +4,9 @@ namespace Rector\DowngradePhp74\Rector\LNumber; +use PhpParser\Node\Scalar\Int_; +use PhpParser\Node\Scalar\Float_; use PhpParser\Node; -use PhpParser\Node\Scalar\DNumber; -use PhpParser\Node\Scalar\LNumber; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; @@ -56,11 +56,11 @@ public function run() */ public function getNodeTypes(): array { - return [LNumber::class, DNumber::class]; + return [Int_::class, Float_::class]; } /** - * @param LNumber|DNumber $node + * @param Int_|Float_ $node */ public function refactor(Node $node): ?Node { @@ -81,16 +81,16 @@ public function refactor(Node $node): ?Node return $node; } - private function shouldSkip(LNumber | DNumber $node, mixed $rawValue): bool + private function shouldSkip(Int_ | Float_ $node, mixed $rawValue): bool { if (! is_string($rawValue)) { return true; } // "_" notation can be applied to decimal numbers only - if ($node instanceof LNumber) { + if ($node instanceof Int_) { $numberKind = $node->getAttribute(AttributeKey::KIND); - if ($numberKind !== LNumber::KIND_DEC) { + if ($numberKind !== Int_::KIND_DEC) { return true; } } diff --git a/rules/DowngradePhp80/NodeAnalyzer/UnnamedArgumentResolver.php b/rules/DowngradePhp80/NodeAnalyzer/UnnamedArgumentResolver.php index 85583cbf..38c9e830 100644 --- a/rules/DowngradePhp80/NodeAnalyzer/UnnamedArgumentResolver.php +++ b/rules/DowngradePhp80/NodeAnalyzer/UnnamedArgumentResolver.php @@ -29,11 +29,11 @@ public function resolveFromReflection( FunctionReflection | MethodReflection $functionLikeReflection, array $currentArgs ): array { - $parametersAcceptorWithPhpDocs = ParametersAcceptorSelector::combineAcceptors( + $extendedParametersAcceptor = ParametersAcceptorSelector::combineAcceptors( $functionLikeReflection->getVariants() ); - $parameters = $parametersAcceptorWithPhpDocs->getParameters(); + $parameters = $extendedParametersAcceptor->getParameters(); if ($functionLikeReflection instanceof NativeFunctionReflection) { $functionLikeReflection = new ReflectionFunction($functionLikeReflection->getName()); diff --git a/rules/DowngradePhp80/Rector/ArrayDimFetch/DowngradeDereferenceableOperationRector.php b/rules/DowngradePhp80/Rector/ArrayDimFetch/DowngradeDereferenceableOperationRector.php index 1ba52266..f93d3675 100644 --- a/rules/DowngradePhp80/Rector/ArrayDimFetch/DowngradeDereferenceableOperationRector.php +++ b/rules/DowngradePhp80/Rector/ArrayDimFetch/DowngradeDereferenceableOperationRector.php @@ -4,10 +4,10 @@ namespace Rector\DowngradePhp80\Rector\ArrayDimFetch; +use PhpParser\Node\Scalar\InterpolatedString; use PhpParser\Node; use PhpParser\Node\Expr; use PhpParser\Node\Expr\ArrayDimFetch; -use PhpParser\Node\Scalar\Encapsed; use PhpParser\Node\Scalar\MagicConst; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\Rector\AbstractRector; @@ -70,7 +70,7 @@ private function shouldSkip(ArrayDimFetch $arrayDimFetch): bool return true; } - if ($arrayDimFetch->var instanceof Encapsed) { + if ($arrayDimFetch->var instanceof InterpolatedString) { return $this->hasParentheses($arrayDimFetch); } diff --git a/rules/DowngradePhp80/Rector/ClassMethod/DowngradeAbstractPrivateMethodInTraitRector.php b/rules/DowngradePhp80/Rector/ClassMethod/DowngradeAbstractPrivateMethodInTraitRector.php index a240c5cd..4426faa0 100644 --- a/rules/DowngradePhp80/Rector/ClassMethod/DowngradeAbstractPrivateMethodInTraitRector.php +++ b/rules/DowngradePhp80/Rector/ClassMethod/DowngradeAbstractPrivateMethodInTraitRector.php @@ -4,8 +4,8 @@ namespace Rector\DowngradePhp80\Rector\ClassMethod; +use PhpParser\Modifiers; use PhpParser\Node; -use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; use PHPStan\Reflection\ClassReflection; use Rector\Rector\AbstractRector; @@ -65,7 +65,7 @@ public function refactor(Node $node): ?Node } // remove abstract - $node->flags -= Class_::MODIFIER_ABSTRACT; + $node->flags -= Modifiers::ABSTRACT; // Add empty array for stmts to generate empty function body $node->stmts = []; diff --git a/rules/DowngradePhp80/Rector/ClassMethod/DowngradeTrailingCommasInParamUseRector.php b/rules/DowngradePhp80/Rector/ClassMethod/DowngradeTrailingCommasInParamUseRector.php index 9e3b2614..7b4de161 100644 --- a/rules/DowngradePhp80/Rector/ClassMethod/DowngradeTrailingCommasInParamUseRector.php +++ b/rules/DowngradePhp80/Rector/ClassMethod/DowngradeTrailingCommasInParamUseRector.php @@ -4,9 +4,9 @@ namespace Rector\DowngradePhp80\Rector\ClassMethod; +use PhpParser\Node\ClosureUse; use PhpParser\Node; use PhpParser\Node\Expr\Closure; -use PhpParser\Node\Expr\ClosureUse; use PhpParser\Node\Param; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Function_; diff --git a/rules/DowngradePhp80/Rector/Class_/DowngradePropertyPromotionRector.php b/rules/DowngradePhp80/Rector/Class_/DowngradePropertyPromotionRector.php index 23f98993..da0b5f6f 100644 --- a/rules/DowngradePhp80/Rector/Class_/DowngradePropertyPromotionRector.php +++ b/rules/DowngradePhp80/Rector/Class_/DowngradePropertyPromotionRector.php @@ -4,6 +4,7 @@ namespace Rector\DowngradePhp80\Rector\Class_; +use PhpParser\Node\PropertyItem; use PhpParser\Comment; use PhpParser\Node; use PhpParser\Node\Expr; @@ -13,7 +14,6 @@ use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\Property; -use PhpParser\Node\Stmt\PropertyProperty; use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; @@ -208,7 +208,7 @@ private function createPropertiesFromParams(ClassMethod $classMethod, array $par /** @var string $name */ $name = $this->getName($param->var); - $property = new Property($param->flags, [new PropertyProperty($name)], [], $param->type); + $property = new Property($param->flags, [new PropertyItem($name)], [], $param->type); $this->decoratePropertyWithParamDocInfo($classMethod, $param, $property); $hasNew = $param->default instanceof Expr && (bool) $this->betterNodeFinder->findFirstInstanceOf( diff --git a/rules/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector.php b/rules/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector.php index 9fe7b01e..a707cbff 100644 --- a/rules/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector.php +++ b/rules/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector.php @@ -4,9 +4,9 @@ namespace Rector\DowngradePhp80\Rector\Expression; +use PhpParser\Node\ArrayItem; use PhpParser\Node; use PhpParser\Node\Arg; -use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\Expr\ArrowFunction; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\CallLike; diff --git a/rules/DowngradePhp80/Rector/FuncCall/DowngradeArrayFilterNullableCallbackRector.php b/rules/DowngradePhp80/Rector/FuncCall/DowngradeArrayFilterNullableCallbackRector.php index b015bbd1..9afd03fa 100644 --- a/rules/DowngradePhp80/Rector/FuncCall/DowngradeArrayFilterNullableCallbackRector.php +++ b/rules/DowngradePhp80/Rector/FuncCall/DowngradeArrayFilterNullableCallbackRector.php @@ -4,6 +4,7 @@ namespace Rector\DowngradePhp80\Rector\FuncCall; +use PhpParser\Node\Scalar\Int_; use PhpParser\Node; use PhpParser\Node\Arg; use PhpParser\Node\Expr; @@ -20,7 +21,6 @@ use PhpParser\Node\Identifier; use PhpParser\Node\Name; use PhpParser\Node\Param; -use PhpParser\Node\Scalar\LNumber; use PhpParser\Node\Scalar\String_; use PHPStan\Type\ArrayType; use PHPStan\Type\ClosureType; @@ -164,7 +164,7 @@ private function createNewArgSecondTernary(array $args): Ternary $identical = new Identical($args[1]->value, $this->nodeFactory->createNull()); $constFetch = new ConstFetch(new Name('ARRAY_FILTER_USE_BOTH')); - return new Ternary($identical, $constFetch, isset($args[2]) ? $args[2]->value : new LNumber(0)); + return new Ternary($identical, $constFetch, isset($args[2]) ? $args[2]->value : new Int_(0)); } private function isAlreadyConditionedToNull(Expr $expr): bool diff --git a/rules/DowngradePhp80/Rector/FuncCall/DowngradeStrEndsWithRector.php b/rules/DowngradePhp80/Rector/FuncCall/DowngradeStrEndsWithRector.php index 2a53d846..d194e51a 100644 --- a/rules/DowngradePhp80/Rector/FuncCall/DowngradeStrEndsWithRector.php +++ b/rules/DowngradePhp80/Rector/FuncCall/DowngradeStrEndsWithRector.php @@ -4,6 +4,7 @@ namespace Rector\DowngradePhp80\Rector\FuncCall; +use PhpParser\Node\Scalar\Int_; use PhpParser\Node; use PhpParser\Node\Arg; use PhpParser\Node\Expr; @@ -13,7 +14,6 @@ use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\UnaryMinus; use PhpParser\Node\Name; -use PhpParser\Node\Scalar\LNumber; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -49,13 +49,13 @@ public function getNodeTypes(): array public function refactor(Node $node): ?Node { if ($node instanceof FuncCall && $this->isName($node->name, 'str_ends_with')) { - return new Identical($this->createSubstrCompareFuncCall($node), new LNumber(0)); + return new Identical($this->createSubstrCompareFuncCall($node), new Int_(0)); } if ($node instanceof BooleanNot) { $funcCall = $node->expr; if ($funcCall instanceof FuncCall && $this->isName($funcCall->name, 'str_ends_with')) { - return new NotIdentical($this->createSubstrCompareFuncCall($funcCall), new LNumber(0)); + return new NotIdentical($this->createSubstrCompareFuncCall($funcCall), new Int_(0)); } } diff --git a/rules/DowngradePhp80/Rector/FuncCall/DowngradeStrStartsWithRector.php b/rules/DowngradePhp80/Rector/FuncCall/DowngradeStrStartsWithRector.php index 0c9ebe03..43cf1c71 100644 --- a/rules/DowngradePhp80/Rector/FuncCall/DowngradeStrStartsWithRector.php +++ b/rules/DowngradePhp80/Rector/FuncCall/DowngradeStrStartsWithRector.php @@ -4,6 +4,7 @@ namespace Rector\DowngradePhp80\Rector\FuncCall; +use PhpParser\Node\Scalar\Int_; use PhpParser\Node; use PhpParser\Node\Arg; use PhpParser\Node\Expr\BinaryOp\Identical; @@ -11,7 +12,6 @@ use PhpParser\Node\Expr\BooleanNot; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Name; -use PhpParser\Node\Scalar\LNumber; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -65,7 +65,7 @@ private function createIdentical(FuncCall $funcCall): Identical $strlenFuncCall = $this->createStrlenFuncCall($funcCall); $strncmpFuncCall = $this->createStrncmpFuncCall($funcCall, $strlenFuncCall); - return new Identical($strncmpFuncCall, new LNumber(0)); + return new Identical($strncmpFuncCall, new Int_(0)); } private function createNotIdenticalStrncmpFuncCall(FuncCall $funcCall): NotIdentical @@ -73,7 +73,7 @@ private function createNotIdenticalStrncmpFuncCall(FuncCall $funcCall): NotIdent $strlenFuncCall = $this->createStrlenFuncCall($funcCall); $strncmpFuncCall = $this->createStrncmpFuncCall($funcCall, $strlenFuncCall); - return new NotIdentical($strncmpFuncCall, new LNumber(0)); + return new NotIdentical($strncmpFuncCall, new Int_(0)); } private function createStrlenFuncCall(FuncCall $funcCall): FuncCall diff --git a/rules/DowngradePhp80/Rector/MethodCall/DowngradeReflectionClassGetConstantsFilterRector.php b/rules/DowngradePhp80/Rector/MethodCall/DowngradeReflectionClassGetConstantsFilterRector.php index 3332d615..e36011f2 100644 --- a/rules/DowngradePhp80/Rector/MethodCall/DowngradeReflectionClassGetConstantsFilterRector.php +++ b/rules/DowngradePhp80/Rector/MethodCall/DowngradeReflectionClassGetConstantsFilterRector.php @@ -4,6 +4,7 @@ namespace Rector\DowngradePhp80\Rector\MethodCall; +use PhpParser\Node\ClosureUse; use PhpParser\Node; use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\ArrayDimFetch; @@ -11,7 +12,6 @@ use PhpParser\Node\Expr\BinaryOp\BitwiseOr; use PhpParser\Node\Expr\ClassConstFetch; use PhpParser\Node\Expr\Closure; -use PhpParser\Node\Expr\ClosureUse; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Identifier; diff --git a/rules/DowngradePhp80/Rector/Property/DowngradeUnionTypeTypedPropertyRector.php b/rules/DowngradePhp80/Rector/Property/DowngradeUnionTypeTypedPropertyRector.php index b5a08cbe..6d07f9e3 100644 --- a/rules/DowngradePhp80/Rector/Property/DowngradeUnionTypeTypedPropertyRector.php +++ b/rules/DowngradePhp80/Rector/Property/DowngradeUnionTypeTypedPropertyRector.php @@ -75,7 +75,7 @@ public function refactor(Node $node): ?Node private function shouldRemoveProperty(Property $property): bool { - if ($property->type === null) { + if (!$property->type instanceof Node) { return false; } diff --git a/rules/DowngradePhp80/Rector/StaticCall/DowngradePhpTokenRector.php b/rules/DowngradePhp80/Rector/StaticCall/DowngradePhpTokenRector.php index b46d5974..47fe0da5 100644 --- a/rules/DowngradePhp80/Rector/StaticCall/DowngradePhpTokenRector.php +++ b/rules/DowngradePhp80/Rector/StaticCall/DowngradePhpTokenRector.php @@ -4,6 +4,7 @@ namespace Rector\DowngradePhp80\Rector\StaticCall; +use PhpParser\Node\Scalar\Int_; use PhpParser\Node; use PhpParser\Node\Arg; use PhpParser\Node\Expr\ArrayDimFetch; @@ -13,7 +14,6 @@ use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Expr\Ternary; use PhpParser\Node\Name; -use PhpParser\Node\Scalar\LNumber; use PHPStan\Type\ObjectType; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; @@ -103,7 +103,7 @@ private function refactorMethodCall(MethodCall $methodCall): ?Ternary } $isArrayFuncCall = new FuncCall(new Name('is_array'), [new Arg($methodCall->var)]); - $arrayDimFetch = new ArrayDimFetch($methodCall->var, new LNumber(0)); + $arrayDimFetch = new ArrayDimFetch($methodCall->var, new Int_(0)); $tokenGetNameFuncCall = new FuncCall(new Name('token_name'), [new Arg($arrayDimFetch)]); return new Ternary($isArrayFuncCall, $tokenGetNameFuncCall, $this->nodeFactory->createNull()); @@ -123,7 +123,7 @@ private function refactorPropertyFetch(PropertyFetch $propertyFetch): ?Ternary $isArrayFuncCall = new FuncCall(new Name('is_array'), [new Arg($propertyFetch->var)]); $arrayDimFetch = new ArrayDimFetch( $propertyFetch->var, - $propertyFetchName === 'id' ? new LNumber(0) : new LNumber(1) + $propertyFetchName === 'id' ? new Int_(0) : new Int_(1) ); return new Ternary($isArrayFuncCall, $arrayDimFetch, $propertyFetch->var); diff --git a/rules/DowngradePhp81/NodeAnalyzer/ArraySpreadAnalyzer.php b/rules/DowngradePhp81/NodeAnalyzer/ArraySpreadAnalyzer.php index c64a8497..8246329f 100644 --- a/rules/DowngradePhp81/NodeAnalyzer/ArraySpreadAnalyzer.php +++ b/rules/DowngradePhp81/NodeAnalyzer/ArraySpreadAnalyzer.php @@ -4,8 +4,8 @@ namespace Rector\DowngradePhp81\NodeAnalyzer; +use PhpParser\Node\ArrayItem; use PhpParser\Node\Expr\Array_; -use PhpParser\Node\Expr\ArrayItem; final class ArraySpreadAnalyzer { diff --git a/rules/DowngradePhp81/NodeFactory/ArrayMergeFromArraySpreadFactory.php b/rules/DowngradePhp81/NodeFactory/ArrayMergeFromArraySpreadFactory.php index c5b5ed1a..1021b055 100644 --- a/rules/DowngradePhp81/NodeFactory/ArrayMergeFromArraySpreadFactory.php +++ b/rules/DowngradePhp81/NodeFactory/ArrayMergeFromArraySpreadFactory.php @@ -4,10 +4,10 @@ namespace Rector\DowngradePhp81\NodeFactory; +use PhpParser\Node\ArrayItem; use PhpParser\Node; use PhpParser\Node\Arg; use PhpParser\Node\Expr\Array_; -use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\Ternary; use PhpParser\Node\Expr\Variable; @@ -92,7 +92,7 @@ private function createArrayMergeFuncCall(array $arrayItems, MutatingScope $muta } /** - * @param array $items + * @param array<(ArrayItem | null)> $items */ private function createArrayItemFromArray(array $items): ArrayItem { diff --git a/rules/DowngradePhp81/Rector/Array_/DowngradeArraySpreadStringKeyRector.php b/rules/DowngradePhp81/Rector/Array_/DowngradeArraySpreadStringKeyRector.php index f6c590c9..f993ba8b 100644 --- a/rules/DowngradePhp81/Rector/Array_/DowngradeArraySpreadStringKeyRector.php +++ b/rules/DowngradePhp81/Rector/Array_/DowngradeArraySpreadStringKeyRector.php @@ -4,9 +4,9 @@ namespace Rector\DowngradePhp81\Rector\Array_; +use PhpParser\Node\ArrayItem; use PhpParser\Node; use PhpParser\Node\Expr\Array_; -use PhpParser\Node\Expr\ArrayItem; use PHPStan\Analyser\MutatingScope; use PHPStan\Type\ArrayType; use PHPStan\Type\IntegerType; diff --git a/rules/DowngradePhp81/Rector/FuncCall/DowngradeFirstClassCallableSyntaxRector.php b/rules/DowngradePhp81/Rector/FuncCall/DowngradeFirstClassCallableSyntaxRector.php index 76bc0dbd..89732a41 100644 --- a/rules/DowngradePhp81/Rector/FuncCall/DowngradeFirstClassCallableSyntaxRector.php +++ b/rules/DowngradePhp81/Rector/FuncCall/DowngradeFirstClassCallableSyntaxRector.php @@ -4,11 +4,11 @@ namespace Rector\DowngradePhp81\Rector\FuncCall; +use PhpParser\Node\ArrayItem; use PhpParser\Node; use PhpParser\Node\Arg; use PhpParser\Node\Expr; use PhpParser\Node\Expr\Array_; -use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\Expr\ClassConstFetch; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\MethodCall; diff --git a/rules/DowngradePhp81/Rector/LNumber/DowngradeOctalNumberRector.php b/rules/DowngradePhp81/Rector/LNumber/DowngradeOctalNumberRector.php index 16bb6061..d22c9936 100644 --- a/rules/DowngradePhp81/Rector/LNumber/DowngradeOctalNumberRector.php +++ b/rules/DowngradePhp81/Rector/LNumber/DowngradeOctalNumberRector.php @@ -4,8 +4,8 @@ namespace Rector\DowngradePhp81\Rector\LNumber; +use PhpParser\Node\Scalar\Int_; use PhpParser\Node; -use PhpParser\Node\Scalar\LNumber; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; @@ -51,16 +51,16 @@ public function run() */ public function getNodeTypes(): array { - return [LNumber::class]; + return [Int_::class]; } /** - * @param LNumber $node + * @param Int_ $node */ public function refactor(Node $node): ?Node { $numberKind = $node->getAttribute(AttributeKey::KIND); - if ($numberKind !== LNumber::KIND_OCT) { + if ($numberKind !== Int_::KIND_OCT) { return null; } diff --git a/src/PhpDocDecorator/PhpDocFromTypeDeclarationDecorator.php b/src/PhpDocDecorator/PhpDocFromTypeDeclarationDecorator.php index d05921b1..89325499 100644 --- a/src/PhpDocDecorator/PhpDocFromTypeDeclarationDecorator.php +++ b/src/PhpDocDecorator/PhpDocFromTypeDeclarationDecorator.php @@ -4,6 +4,7 @@ namespace Rector\PhpDocDecorator; +use PhpParser\Node; use PhpParser\Node\ComplexType; use PhpParser\Node\Expr\ArrowFunction; use PhpParser\Node\Expr\Closure; @@ -110,7 +111,7 @@ public function decorateParam( ClassMethod|Function_|Closure|ArrowFunction $functionLike, array $requiredTypes ): void { - if ($param->type === null) { + if (!$param->type instanceof Node) { return; } @@ -132,7 +133,7 @@ public function decorateParamWithSpecificType( ClassMethod|Function_|Closure|ArrowFunction $functionLike, Type $requireType ): bool { - if ($param->type === null) { + if (!$param->type instanceof Node) { return false; } From 00efc4e18bb97337642372d5e7465ad295117533 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 19 Nov 2024 23:34:20 +0700 Subject: [PATCH 03/27] cs fix --- rules/DowngradePhp72/NodeManipulator/JsonConstCleaner.php | 2 +- rules/DowngradePhp72/PhpDoc/NativeParamToPhpDocDecorator.php | 2 +- .../FuncCall/DowngradePregUnmatchedAsNullConstantRector.php | 2 +- .../FuncCall/SetCookieOptionsArrayToArgumentsRector.php | 2 +- .../Rector/List_/DowngradeListReferenceAssignmentRector.php | 4 ++-- .../Rector/String_/DowngradeFlexibleHeredocSyntaxRector.php | 2 +- .../Rector/Array_/DowngradeArraySpreadRector.php | 2 +- .../ArrowFunction/ArrowFunctionToAnonymousFunctionRector.php | 2 +- .../ClassMethod/DowngradeContravariantArgumentTypeRector.php | 4 ++-- .../Rector/LNumber/DowngradeNumericLiteralSeparatorRector.php | 4 ++-- .../ArrayDimFetch/DowngradeDereferenceableOperationRector.php | 2 +- .../ClassMethod/DowngradeTrailingCommasInParamUseRector.php | 2 +- .../Rector/Class_/DowngradePropertyPromotionRector.php | 2 +- .../Rector/Expression/DowngradeMatchToSwitchRector.php | 2 +- .../FuncCall/DowngradeArrayFilterNullableCallbackRector.php | 2 +- .../Rector/FuncCall/DowngradeStrEndsWithRector.php | 2 +- .../Rector/FuncCall/DowngradeStrStartsWithRector.php | 2 +- .../DowngradeReflectionClassGetConstantsFilterRector.php | 2 +- .../Rector/Property/DowngradeUnionTypeTypedPropertyRector.php | 2 +- .../Rector/StaticCall/DowngradePhpTokenRector.php | 2 +- .../NodeFactory/ArrayMergeFromArraySpreadFactory.php | 2 +- .../Rector/Array_/DowngradeArraySpreadStringKeyRector.php | 2 +- .../FuncCall/DowngradeFirstClassCallableSyntaxRector.php | 2 +- .../Rector/LNumber/DowngradeOctalNumberRector.php | 2 +- src/PhpDocDecorator/PhpDocFromTypeDeclarationDecorator.php | 4 ++-- 25 files changed, 29 insertions(+), 29 deletions(-) diff --git a/rules/DowngradePhp72/NodeManipulator/JsonConstCleaner.php b/rules/DowngradePhp72/NodeManipulator/JsonConstCleaner.php index 6b2ce54a..7fadc85e 100644 --- a/rules/DowngradePhp72/NodeManipulator/JsonConstCleaner.php +++ b/rules/DowngradePhp72/NodeManipulator/JsonConstCleaner.php @@ -4,11 +4,11 @@ namespace Rector\DowngradePhp72\NodeManipulator; -use PhpParser\Node\Scalar\Int_; use PhpParser\Node; use PhpParser\Node\Expr; use PhpParser\Node\Expr\BinaryOp\BitwiseOr; use PhpParser\Node\Expr\ConstFetch; +use PhpParser\Node\Scalar\Int_; use Rector\Enum\JsonConstant; use Rector\NodeNameResolver\NodeNameResolver; use Rector\NodeTypeResolver\Node\AttributeKey; diff --git a/rules/DowngradePhp72/PhpDoc/NativeParamToPhpDocDecorator.php b/rules/DowngradePhp72/PhpDoc/NativeParamToPhpDocDecorator.php index ea68d72c..a59ece69 100644 --- a/rules/DowngradePhp72/PhpDoc/NativeParamToPhpDocDecorator.php +++ b/rules/DowngradePhp72/PhpDoc/NativeParamToPhpDocDecorator.php @@ -30,7 +30,7 @@ public function __construct( public function decorate(ClassMethod $classMethod, Param $param): void { - if (!$param->type instanceof Node) { + if (! $param->type instanceof Node) { return; } diff --git a/rules/DowngradePhp72/Rector/FuncCall/DowngradePregUnmatchedAsNullConstantRector.php b/rules/DowngradePhp72/Rector/FuncCall/DowngradePregUnmatchedAsNullConstantRector.php index 460ccd88..5bb3dc84 100644 --- a/rules/DowngradePhp72/Rector/FuncCall/DowngradePregUnmatchedAsNullConstantRector.php +++ b/rules/DowngradePhp72/Rector/FuncCall/DowngradePregUnmatchedAsNullConstantRector.php @@ -4,7 +4,6 @@ namespace Rector\DowngradePhp72\Rector\FuncCall; -use PhpParser\Node\Scalar\Int_; use PhpParser\Node; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\BinaryOp\BitwiseOr; @@ -15,6 +14,7 @@ use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Param; +use PhpParser\Node\Scalar\Int_; use PhpParser\Node\Scalar\String_; use PhpParser\Node\Stmt; use PhpParser\Node\Stmt\ClassConst; diff --git a/rules/DowngradePhp73/Rector/FuncCall/SetCookieOptionsArrayToArgumentsRector.php b/rules/DowngradePhp73/Rector/FuncCall/SetCookieOptionsArrayToArgumentsRector.php index 8ad0a285..a7b26e43 100644 --- a/rules/DowngradePhp73/Rector/FuncCall/SetCookieOptionsArrayToArgumentsRector.php +++ b/rules/DowngradePhp73/Rector/FuncCall/SetCookieOptionsArrayToArgumentsRector.php @@ -4,10 +4,10 @@ namespace Rector\DowngradePhp73\Rector\FuncCall; -use PhpParser\Node\ArrayItem; use PhpParser\BuilderHelpers; use PhpParser\Node; use PhpParser\Node\Arg; +use PhpParser\Node\ArrayItem; use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Scalar\String_; diff --git a/rules/DowngradePhp73/Rector/List_/DowngradeListReferenceAssignmentRector.php b/rules/DowngradePhp73/Rector/List_/DowngradeListReferenceAssignmentRector.php index 9b9160b3..8b6ccf2f 100644 --- a/rules/DowngradePhp73/Rector/List_/DowngradeListReferenceAssignmentRector.php +++ b/rules/DowngradePhp73/Rector/List_/DowngradeListReferenceAssignmentRector.php @@ -4,16 +4,16 @@ namespace Rector\DowngradePhp73\Rector\List_; -use PhpParser\Node\ArrayItem; -use PhpParser\Node\Scalar\Int_; use PhpParser\BuilderHelpers; use PhpParser\Node; +use PhpParser\Node\ArrayItem; use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\ArrayDimFetch; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\AssignRef; use PhpParser\Node\Expr\List_; use PhpParser\Node\Expr\Variable; +use PhpParser\Node\Scalar\Int_; use PhpParser\Node\Scalar\String_; use PhpParser\Node\Stmt\Expression; use Rector\Rector\AbstractRector; diff --git a/rules/DowngradePhp73/Rector/String_/DowngradeFlexibleHeredocSyntaxRector.php b/rules/DowngradePhp73/Rector/String_/DowngradeFlexibleHeredocSyntaxRector.php index 77fa07e9..8df470e3 100644 --- a/rules/DowngradePhp73/Rector/String_/DowngradeFlexibleHeredocSyntaxRector.php +++ b/rules/DowngradePhp73/Rector/String_/DowngradeFlexibleHeredocSyntaxRector.php @@ -4,8 +4,8 @@ namespace Rector\DowngradePhp73\Rector\String_; -use PhpParser\Node\Scalar\InterpolatedString; use PhpParser\Node; +use PhpParser\Node\Scalar\InterpolatedString; use PhpParser\Node\Scalar\String_; use Rector\DowngradePhp73\Tokenizer\FollowedByNewlineOnlyMaybeWithSemicolonAnalyzer; use Rector\NodeTypeResolver\Node\AttributeKey; diff --git a/rules/DowngradePhp74/Rector/Array_/DowngradeArraySpreadRector.php b/rules/DowngradePhp74/Rector/Array_/DowngradeArraySpreadRector.php index 3f569671..a4814419 100644 --- a/rules/DowngradePhp74/Rector/Array_/DowngradeArraySpreadRector.php +++ b/rules/DowngradePhp74/Rector/Array_/DowngradeArraySpreadRector.php @@ -4,8 +4,8 @@ namespace Rector\DowngradePhp74\Rector\Array_; -use PhpParser\Node\ArrayItem; use PhpParser\Node; +use PhpParser\Node\ArrayItem; use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\ClassConstFetch; use PhpParser\Node\Identifier; diff --git a/rules/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector.php b/rules/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector.php index c16d7d16..f359ad53 100644 --- a/rules/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector.php +++ b/rules/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector.php @@ -4,8 +4,8 @@ namespace Rector\DowngradePhp74\Rector\ArrowFunction; -use PhpParser\Node\ClosureUse; use PhpParser\Node; +use PhpParser\Node\ClosureUse; use PhpParser\Node\Expr; use PhpParser\Node\Expr\ArrowFunction; use PhpParser\Node\Expr\Assign; diff --git a/rules/DowngradePhp74/Rector/ClassMethod/DowngradeContravariantArgumentTypeRector.php b/rules/DowngradePhp74/Rector/ClassMethod/DowngradeContravariantArgumentTypeRector.php index cf243031..7015ed88 100644 --- a/rules/DowngradePhp74/Rector/ClassMethod/DowngradeContravariantArgumentTypeRector.php +++ b/rules/DowngradePhp74/Rector/ClassMethod/DowngradeContravariantArgumentTypeRector.php @@ -125,7 +125,7 @@ private function isNullableParam(Param $param, ClassMethod|Function_ $functionLi return false; } - if (!$param->type instanceof Node) { + if (! $param->type instanceof Node) { return false; } @@ -262,7 +262,7 @@ private function refactorParam(Param $param, ClassMethod | Function_ $functionLi private function decorateWithDocBlock(ClassMethod | Function_ $functionLike, Param $param): void { - if (!$param->type instanceof Node) { + if (! $param->type instanceof Node) { return; } diff --git a/rules/DowngradePhp74/Rector/LNumber/DowngradeNumericLiteralSeparatorRector.php b/rules/DowngradePhp74/Rector/LNumber/DowngradeNumericLiteralSeparatorRector.php index 8caf5cfd..e288b7bd 100644 --- a/rules/DowngradePhp74/Rector/LNumber/DowngradeNumericLiteralSeparatorRector.php +++ b/rules/DowngradePhp74/Rector/LNumber/DowngradeNumericLiteralSeparatorRector.php @@ -4,9 +4,9 @@ namespace Rector\DowngradePhp74\Rector\LNumber; -use PhpParser\Node\Scalar\Int_; -use PhpParser\Node\Scalar\Float_; use PhpParser\Node; +use PhpParser\Node\Scalar\Float_; +use PhpParser\Node\Scalar\Int_; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; diff --git a/rules/DowngradePhp80/Rector/ArrayDimFetch/DowngradeDereferenceableOperationRector.php b/rules/DowngradePhp80/Rector/ArrayDimFetch/DowngradeDereferenceableOperationRector.php index f93d3675..ebe85b65 100644 --- a/rules/DowngradePhp80/Rector/ArrayDimFetch/DowngradeDereferenceableOperationRector.php +++ b/rules/DowngradePhp80/Rector/ArrayDimFetch/DowngradeDereferenceableOperationRector.php @@ -4,10 +4,10 @@ namespace Rector\DowngradePhp80\Rector\ArrayDimFetch; -use PhpParser\Node\Scalar\InterpolatedString; use PhpParser\Node; use PhpParser\Node\Expr; use PhpParser\Node\Expr\ArrayDimFetch; +use PhpParser\Node\Scalar\InterpolatedString; use PhpParser\Node\Scalar\MagicConst; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\Rector\AbstractRector; diff --git a/rules/DowngradePhp80/Rector/ClassMethod/DowngradeTrailingCommasInParamUseRector.php b/rules/DowngradePhp80/Rector/ClassMethod/DowngradeTrailingCommasInParamUseRector.php index 7b4de161..503e36c7 100644 --- a/rules/DowngradePhp80/Rector/ClassMethod/DowngradeTrailingCommasInParamUseRector.php +++ b/rules/DowngradePhp80/Rector/ClassMethod/DowngradeTrailingCommasInParamUseRector.php @@ -4,8 +4,8 @@ namespace Rector\DowngradePhp80\Rector\ClassMethod; -use PhpParser\Node\ClosureUse; use PhpParser\Node; +use PhpParser\Node\ClosureUse; use PhpParser\Node\Expr\Closure; use PhpParser\Node\Param; use PhpParser\Node\Stmt\ClassMethod; diff --git a/rules/DowngradePhp80/Rector/Class_/DowngradePropertyPromotionRector.php b/rules/DowngradePhp80/Rector/Class_/DowngradePropertyPromotionRector.php index da0b5f6f..c4013099 100644 --- a/rules/DowngradePhp80/Rector/Class_/DowngradePropertyPromotionRector.php +++ b/rules/DowngradePhp80/Rector/Class_/DowngradePropertyPromotionRector.php @@ -4,12 +4,12 @@ namespace Rector\DowngradePhp80\Rector\Class_; -use PhpParser\Node\PropertyItem; use PhpParser\Comment; use PhpParser\Node; use PhpParser\Node\Expr; use PhpParser\Node\Expr\New_; use PhpParser\Node\Param; +use PhpParser\Node\PropertyItem; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Expression; diff --git a/rules/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector.php b/rules/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector.php index a707cbff..97bf1523 100644 --- a/rules/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector.php +++ b/rules/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector.php @@ -4,9 +4,9 @@ namespace Rector\DowngradePhp80\Rector\Expression; -use PhpParser\Node\ArrayItem; use PhpParser\Node; use PhpParser\Node\Arg; +use PhpParser\Node\ArrayItem; use PhpParser\Node\Expr\ArrowFunction; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\CallLike; diff --git a/rules/DowngradePhp80/Rector/FuncCall/DowngradeArrayFilterNullableCallbackRector.php b/rules/DowngradePhp80/Rector/FuncCall/DowngradeArrayFilterNullableCallbackRector.php index 9afd03fa..08520f11 100644 --- a/rules/DowngradePhp80/Rector/FuncCall/DowngradeArrayFilterNullableCallbackRector.php +++ b/rules/DowngradePhp80/Rector/FuncCall/DowngradeArrayFilterNullableCallbackRector.php @@ -4,7 +4,6 @@ namespace Rector\DowngradePhp80\Rector\FuncCall; -use PhpParser\Node\Scalar\Int_; use PhpParser\Node; use PhpParser\Node\Arg; use PhpParser\Node\Expr; @@ -21,6 +20,7 @@ use PhpParser\Node\Identifier; use PhpParser\Node\Name; use PhpParser\Node\Param; +use PhpParser\Node\Scalar\Int_; use PhpParser\Node\Scalar\String_; use PHPStan\Type\ArrayType; use PHPStan\Type\ClosureType; diff --git a/rules/DowngradePhp80/Rector/FuncCall/DowngradeStrEndsWithRector.php b/rules/DowngradePhp80/Rector/FuncCall/DowngradeStrEndsWithRector.php index d194e51a..40cdad18 100644 --- a/rules/DowngradePhp80/Rector/FuncCall/DowngradeStrEndsWithRector.php +++ b/rules/DowngradePhp80/Rector/FuncCall/DowngradeStrEndsWithRector.php @@ -4,7 +4,6 @@ namespace Rector\DowngradePhp80\Rector\FuncCall; -use PhpParser\Node\Scalar\Int_; use PhpParser\Node; use PhpParser\Node\Arg; use PhpParser\Node\Expr; @@ -14,6 +13,7 @@ use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\UnaryMinus; use PhpParser\Node\Name; +use PhpParser\Node\Scalar\Int_; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; diff --git a/rules/DowngradePhp80/Rector/FuncCall/DowngradeStrStartsWithRector.php b/rules/DowngradePhp80/Rector/FuncCall/DowngradeStrStartsWithRector.php index 43cf1c71..6dbd2e19 100644 --- a/rules/DowngradePhp80/Rector/FuncCall/DowngradeStrStartsWithRector.php +++ b/rules/DowngradePhp80/Rector/FuncCall/DowngradeStrStartsWithRector.php @@ -4,7 +4,6 @@ namespace Rector\DowngradePhp80\Rector\FuncCall; -use PhpParser\Node\Scalar\Int_; use PhpParser\Node; use PhpParser\Node\Arg; use PhpParser\Node\Expr\BinaryOp\Identical; @@ -12,6 +11,7 @@ use PhpParser\Node\Expr\BooleanNot; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Name; +use PhpParser\Node\Scalar\Int_; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; diff --git a/rules/DowngradePhp80/Rector/MethodCall/DowngradeReflectionClassGetConstantsFilterRector.php b/rules/DowngradePhp80/Rector/MethodCall/DowngradeReflectionClassGetConstantsFilterRector.php index e36011f2..ebb09f5e 100644 --- a/rules/DowngradePhp80/Rector/MethodCall/DowngradeReflectionClassGetConstantsFilterRector.php +++ b/rules/DowngradePhp80/Rector/MethodCall/DowngradeReflectionClassGetConstantsFilterRector.php @@ -4,8 +4,8 @@ namespace Rector\DowngradePhp80\Rector\MethodCall; -use PhpParser\Node\ClosureUse; use PhpParser\Node; +use PhpParser\Node\ClosureUse; use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\ArrayDimFetch; use PhpParser\Node\Expr\Assign; diff --git a/rules/DowngradePhp80/Rector/Property/DowngradeUnionTypeTypedPropertyRector.php b/rules/DowngradePhp80/Rector/Property/DowngradeUnionTypeTypedPropertyRector.php index 6d07f9e3..05e718b4 100644 --- a/rules/DowngradePhp80/Rector/Property/DowngradeUnionTypeTypedPropertyRector.php +++ b/rules/DowngradePhp80/Rector/Property/DowngradeUnionTypeTypedPropertyRector.php @@ -75,7 +75,7 @@ public function refactor(Node $node): ?Node private function shouldRemoveProperty(Property $property): bool { - if (!$property->type instanceof Node) { + if (! $property->type instanceof Node) { return false; } diff --git a/rules/DowngradePhp80/Rector/StaticCall/DowngradePhpTokenRector.php b/rules/DowngradePhp80/Rector/StaticCall/DowngradePhpTokenRector.php index 47fe0da5..512f11fb 100644 --- a/rules/DowngradePhp80/Rector/StaticCall/DowngradePhpTokenRector.php +++ b/rules/DowngradePhp80/Rector/StaticCall/DowngradePhpTokenRector.php @@ -4,7 +4,6 @@ namespace Rector\DowngradePhp80\Rector\StaticCall; -use PhpParser\Node\Scalar\Int_; use PhpParser\Node; use PhpParser\Node\Arg; use PhpParser\Node\Expr\ArrayDimFetch; @@ -14,6 +13,7 @@ use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Expr\Ternary; use PhpParser\Node\Name; +use PhpParser\Node\Scalar\Int_; use PHPStan\Type\ObjectType; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; diff --git a/rules/DowngradePhp81/NodeFactory/ArrayMergeFromArraySpreadFactory.php b/rules/DowngradePhp81/NodeFactory/ArrayMergeFromArraySpreadFactory.php index 1021b055..15d62355 100644 --- a/rules/DowngradePhp81/NodeFactory/ArrayMergeFromArraySpreadFactory.php +++ b/rules/DowngradePhp81/NodeFactory/ArrayMergeFromArraySpreadFactory.php @@ -4,9 +4,9 @@ namespace Rector\DowngradePhp81\NodeFactory; -use PhpParser\Node\ArrayItem; use PhpParser\Node; use PhpParser\Node\Arg; +use PhpParser\Node\ArrayItem; use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\Ternary; diff --git a/rules/DowngradePhp81/Rector/Array_/DowngradeArraySpreadStringKeyRector.php b/rules/DowngradePhp81/Rector/Array_/DowngradeArraySpreadStringKeyRector.php index f993ba8b..b5ed83cd 100644 --- a/rules/DowngradePhp81/Rector/Array_/DowngradeArraySpreadStringKeyRector.php +++ b/rules/DowngradePhp81/Rector/Array_/DowngradeArraySpreadStringKeyRector.php @@ -4,8 +4,8 @@ namespace Rector\DowngradePhp81\Rector\Array_; -use PhpParser\Node\ArrayItem; use PhpParser\Node; +use PhpParser\Node\ArrayItem; use PhpParser\Node\Expr\Array_; use PHPStan\Analyser\MutatingScope; use PHPStan\Type\ArrayType; diff --git a/rules/DowngradePhp81/Rector/FuncCall/DowngradeFirstClassCallableSyntaxRector.php b/rules/DowngradePhp81/Rector/FuncCall/DowngradeFirstClassCallableSyntaxRector.php index 89732a41..e33471e5 100644 --- a/rules/DowngradePhp81/Rector/FuncCall/DowngradeFirstClassCallableSyntaxRector.php +++ b/rules/DowngradePhp81/Rector/FuncCall/DowngradeFirstClassCallableSyntaxRector.php @@ -4,9 +4,9 @@ namespace Rector\DowngradePhp81\Rector\FuncCall; -use PhpParser\Node\ArrayItem; use PhpParser\Node; use PhpParser\Node\Arg; +use PhpParser\Node\ArrayItem; use PhpParser\Node\Expr; use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\ClassConstFetch; diff --git a/rules/DowngradePhp81/Rector/LNumber/DowngradeOctalNumberRector.php b/rules/DowngradePhp81/Rector/LNumber/DowngradeOctalNumberRector.php index d22c9936..7b3ddfbb 100644 --- a/rules/DowngradePhp81/Rector/LNumber/DowngradeOctalNumberRector.php +++ b/rules/DowngradePhp81/Rector/LNumber/DowngradeOctalNumberRector.php @@ -4,8 +4,8 @@ namespace Rector\DowngradePhp81\Rector\LNumber; -use PhpParser\Node\Scalar\Int_; use PhpParser\Node; +use PhpParser\Node\Scalar\Int_; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; diff --git a/src/PhpDocDecorator/PhpDocFromTypeDeclarationDecorator.php b/src/PhpDocDecorator/PhpDocFromTypeDeclarationDecorator.php index 89325499..d88576fd 100644 --- a/src/PhpDocDecorator/PhpDocFromTypeDeclarationDecorator.php +++ b/src/PhpDocDecorator/PhpDocFromTypeDeclarationDecorator.php @@ -111,7 +111,7 @@ public function decorateParam( ClassMethod|Function_|Closure|ArrowFunction $functionLike, array $requiredTypes ): void { - if (!$param->type instanceof Node) { + if (! $param->type instanceof Node) { return; } @@ -133,7 +133,7 @@ public function decorateParamWithSpecificType( ClassMethod|Function_|Closure|ArrowFunction $functionLike, Type $requireType ): bool { - if (!$param->type instanceof Node) { + if (! $param->type instanceof Node) { return false; } From c1ba474585ef057702a5f839215c259d50d86849 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 19 Nov 2024 23:46:58 +0700 Subject: [PATCH 04/27] fix print return --- .../Fixture/arrow_function_inside_call_like.php.inc | 4 ++-- .../Fixture/preserve-by-ref-closureuse.php.inc | 2 +- .../Fixture/with_nullable_return_type.php.inc | 2 +- .../Fixture/with_return_type.php.inc | 2 +- .../Fixture/in_arrow_function.php.inc | 2 +- .../Fixture/in_arrow_function2.php.inc | 2 +- .../Fixture/in_arrow_function_as_invokable.php.inc | 2 +- .../Fixture/in_arrow_function_in_expression.php.inc | 2 +- .../Fixture/in_arrow_function_in_return.php.inc | 2 +- .../DowngradeArrayIsListRector/Fixture/fixture.php.inc | 2 +- .../DowngradeArrayIsListRector/Fixture/inside_if.php.inc | 2 +- .../DowngradeArrayIsListRector/Fixture/inside_return.php.inc | 2 +- .../Fixture/no_scope_parent_assign_from_func_call.php.inc | 2 +- .../DowngradeArrayIsListArrowFunction/Fixture/fixture.php.inc | 2 +- 14 files changed, 15 insertions(+), 15 deletions(-) diff --git a/rules-tests/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector/Fixture/arrow_function_inside_call_like.php.inc b/rules-tests/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector/Fixture/arrow_function_inside_call_like.php.inc index 2cf3f7e6..99f01cbd 100644 --- a/rules-tests/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector/Fixture/arrow_function_inside_call_like.php.inc +++ b/rules-tests/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector/Fixture/arrow_function_inside_call_like.php.inc @@ -33,8 +33,8 @@ class ErrorsConsoleStyle public function table(int $terminalWidth, int $maxHeaderWidth): void { - $f = static function ($rows) use ($terminalWidth, $maxHeaderWidth) : array { - return array_map(static function ($row) use ($terminalWidth, $maxHeaderWidth) : array { + $f = static function ($rows) use ($terminalWidth, $maxHeaderWidth): array { + return array_map(static function ($row) use ($terminalWidth, $maxHeaderWidth): array { return array_map(static function ($s) use ($terminalWidth, $maxHeaderWidth) { if ($terminalWidth > $maxHeaderWidth + 5) { return wordwrap( diff --git a/rules-tests/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector/Fixture/preserve-by-ref-closureuse.php.inc b/rules-tests/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector/Fixture/preserve-by-ref-closureuse.php.inc index cfe9515d..b366b010 100644 --- a/rules-tests/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector/Fixture/preserve-by-ref-closureuse.php.inc +++ b/rules-tests/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector/Fixture/preserve-by-ref-closureuse.php.inc @@ -37,7 +37,7 @@ class PreserveByRefClosureUse $nameScopeMap = []; $f = function () use ($j, &$nameScopeMap): ?int { $nameScopeMap[] = function () use ($j): callable { - return static function (int $i) use ($j) : int { + return static function (int $i) use ($j): int { return $i + $j; }; }; diff --git a/rules-tests/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector/Fixture/with_nullable_return_type.php.inc b/rules-tests/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector/Fixture/with_nullable_return_type.php.inc index 9ba1bcc4..0901d89f 100644 --- a/rules-tests/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector/Fixture/with_nullable_return_type.php.inc +++ b/rules-tests/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector/Fixture/with_nullable_return_type.php.inc @@ -20,7 +20,7 @@ class WithNullableReturnType { public function run() { - $callable = function () : ?string { + $callable = function (): ?string { return 'Hello world'; }; } diff --git a/rules-tests/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector/Fixture/with_return_type.php.inc b/rules-tests/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector/Fixture/with_return_type.php.inc index 3c45e3e3..c25f6210 100644 --- a/rules-tests/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector/Fixture/with_return_type.php.inc +++ b/rules-tests/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector/Fixture/with_return_type.php.inc @@ -20,7 +20,7 @@ class WithReturnType { public function run() { - $callable = function () : string { + $callable = function (): string { return 'Hello world'; }; } diff --git a/rules-tests/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector/Fixture/in_arrow_function.php.inc b/rules-tests/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector/Fixture/in_arrow_function.php.inc index 8decb635..8656ee22 100644 --- a/rules-tests/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector/Fixture/in_arrow_function.php.inc +++ b/rules-tests/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector/Fixture/in_arrow_function.php.inc @@ -36,7 +36,7 @@ final class InArrowFunction ]; $mapped = array_map( - static function (mixed $default) : mixed { + static function (mixed $default): mixed { switch (true) { case is_string($default): return sprintf('"%s"', $default); diff --git a/rules-tests/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector/Fixture/in_arrow_function2.php.inc b/rules-tests/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector/Fixture/in_arrow_function2.php.inc index 8e76b294..a4286efe 100644 --- a/rules-tests/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector/Fixture/in_arrow_function2.php.inc +++ b/rules-tests/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector/Fixture/in_arrow_function2.php.inc @@ -23,7 +23,7 @@ final class InArrowFunction2 { public function run($value) { - $mapped = static function (mixed $default) : mixed { + $mapped = static function (mixed $default): mixed { switch (true) { case is_string($default): return sprintf('"%s"', $default); diff --git a/rules-tests/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector/Fixture/in_arrow_function_as_invokable.php.inc b/rules-tests/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector/Fixture/in_arrow_function_as_invokable.php.inc index 843a4208..3cb037d1 100644 --- a/rules-tests/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector/Fixture/in_arrow_function_as_invokable.php.inc +++ b/rules-tests/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector/Fixture/in_arrow_function_as_invokable.php.inc @@ -21,7 +21,7 @@ final class InArrowFunctionAsInvokable { public function run($value) { - (static function (mixed $default) : mixed { + (static function (mixed $default): mixed { switch (true) { case is_string($default): return sprintf('"%s"', $default); diff --git a/rules-tests/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector/Fixture/in_arrow_function_in_expression.php.inc b/rules-tests/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector/Fixture/in_arrow_function_in_expression.php.inc index 7d91a02b..928b3cff 100644 --- a/rules-tests/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector/Fixture/in_arrow_function_in_expression.php.inc +++ b/rules-tests/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector/Fixture/in_arrow_function_in_expression.php.inc @@ -21,7 +21,7 @@ final class InArrowFunctionInExpression { public function run($value) { - static function (mixed $default) : mixed { + static function (mixed $default): mixed { switch (true) { case is_string($default): return sprintf('"%s"', $default); diff --git a/rules-tests/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector/Fixture/in_arrow_function_in_return.php.inc b/rules-tests/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector/Fixture/in_arrow_function_in_return.php.inc index 1ae2b458..c4d48021 100644 --- a/rules-tests/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector/Fixture/in_arrow_function_in_return.php.inc +++ b/rules-tests/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector/Fixture/in_arrow_function_in_return.php.inc @@ -21,7 +21,7 @@ final class InArrowFunctionInReturn { public function run($value) { - return static function (mixed $default) : mixed { + return static function (mixed $default): mixed { switch (true) { case is_string($default): return sprintf('"%s"', $default); diff --git a/rules-tests/DowngradePhp81/Rector/FuncCall/DowngradeArrayIsListRector/Fixture/fixture.php.inc b/rules-tests/DowngradePhp81/Rector/FuncCall/DowngradeArrayIsListRector/Fixture/fixture.php.inc index ee2c3882..9569f145 100644 --- a/rules-tests/DowngradePhp81/Rector/FuncCall/DowngradeArrayIsListRector/Fixture/fixture.php.inc +++ b/rules-tests/DowngradePhp81/Rector/FuncCall/DowngradeArrayIsListRector/Fixture/fixture.php.inc @@ -10,7 +10,7 @@ array_is_list([1 => 'apple', 'orange']); namespace Rector\Tests\DowngradePhp81\Rector\FuncCall\DowngradeArrayIsListRector\Fixture; -$arrayIsListFunction = function (array $array) : bool { +$arrayIsListFunction = function (array $array): bool { if (function_exists('array_is_list')) { return array_is_list($array); } diff --git a/rules-tests/DowngradePhp81/Rector/FuncCall/DowngradeArrayIsListRector/Fixture/inside_if.php.inc b/rules-tests/DowngradePhp81/Rector/FuncCall/DowngradeArrayIsListRector/Fixture/inside_if.php.inc index 208f9330..2ae00f23 100644 --- a/rules-tests/DowngradePhp81/Rector/FuncCall/DowngradeArrayIsListRector/Fixture/inside_if.php.inc +++ b/rules-tests/DowngradePhp81/Rector/FuncCall/DowngradeArrayIsListRector/Fixture/inside_if.php.inc @@ -16,7 +16,7 @@ namespace Rector\Tests\DowngradePhp81\Rector\FuncCall\DowngradeArrayIsListRector function insideIf($arguments) { - $arrayIsListFunction = function (array $array) : bool { + $arrayIsListFunction = function (array $array): bool { if (function_exists('array_is_list')) { return array_is_list($array); } diff --git a/rules-tests/DowngradePhp81/Rector/FuncCall/DowngradeArrayIsListRector/Fixture/inside_return.php.inc b/rules-tests/DowngradePhp81/Rector/FuncCall/DowngradeArrayIsListRector/Fixture/inside_return.php.inc index e857dfe2..ad1ec154 100644 --- a/rules-tests/DowngradePhp81/Rector/FuncCall/DowngradeArrayIsListRector/Fixture/inside_return.php.inc +++ b/rules-tests/DowngradePhp81/Rector/FuncCall/DowngradeArrayIsListRector/Fixture/inside_return.php.inc @@ -15,7 +15,7 @@ namespace Rector\Tests\DowngradePhp81\Rector\FuncCall\DowngradeArrayIsListRector function insideReturn($arguments) { - $arrayIsListFunction = function (array $array) : bool { + $arrayIsListFunction = function (array $array): bool { if (function_exists('array_is_list')) { return array_is_list($array); } diff --git a/rules-tests/DowngradePhp81/Rector/FuncCall/DowngradeArrayIsListRector/Fixture/no_scope_parent_assign_from_func_call.php.inc b/rules-tests/DowngradePhp81/Rector/FuncCall/DowngradeArrayIsListRector/Fixture/no_scope_parent_assign_from_func_call.php.inc index 22f3331b..0c8b2657 100644 --- a/rules-tests/DowngradePhp81/Rector/FuncCall/DowngradeArrayIsListRector/Fixture/no_scope_parent_assign_from_func_call.php.inc +++ b/rules-tests/DowngradePhp81/Rector/FuncCall/DowngradeArrayIsListRector/Fixture/no_scope_parent_assign_from_func_call.php.inc @@ -41,7 +41,7 @@ final class Loop } register_shutdown_function(function () { - $arrayIsListFunction = function (array $array) : bool { + $arrayIsListFunction = function (array $array): bool { if (function_exists('array_is_list')) { return array_is_list($array); } diff --git a/tests/Issues/DowngradeArrayIsListArrowFunction/Fixture/fixture.php.inc b/tests/Issues/DowngradeArrayIsListArrowFunction/Fixture/fixture.php.inc index c62bef6d..2488d92a 100644 --- a/tests/Issues/DowngradeArrayIsListArrowFunction/Fixture/fixture.php.inc +++ b/tests/Issues/DowngradeArrayIsListArrowFunction/Fixture/fixture.php.inc @@ -23,7 +23,7 @@ class Fixture { public function run($items) { - $arrayIsListFunction = function (array $array) : bool { + $arrayIsListFunction = function (array $array): bool { if (function_exists('array_is_list')) { return array_is_list($array); } From 767b4d561d028c4a085cad92df12750482693a62 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 19 Nov 2024 23:49:42 +0700 Subject: [PATCH 05/27] fix use Token as array --- .../New_/DowngradeArbitraryExpressionsSupportRector.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rules/DowngradePhp80/Rector/New_/DowngradeArbitraryExpressionsSupportRector.php b/rules/DowngradePhp80/Rector/New_/DowngradeArbitraryExpressionsSupportRector.php index 8432a820..de5e9ca5 100644 --- a/rules/DowngradePhp80/Rector/New_/DowngradeArbitraryExpressionsSupportRector.php +++ b/rules/DowngradePhp80/Rector/New_/DowngradeArbitraryExpressionsSupportRector.php @@ -109,12 +109,12 @@ private function isBetweenParentheses(Node $node): bool $token = $oldTokens[$previousTokenPos] ?? null; --$previousTokenPos; - if (! isset($token[0])) { - return $token === '('; + if ((string) $token === '(') { + return true; } - if (! in_array($token[0], [\T_COMMENT, \T_WHITESPACE], true)) { - return $token === '('; + if (! in_array((string) $token, [\T_COMMENT, \T_WHITESPACE], true)) { + continue; } } From c05b162c773d0e2dbd332a116ad6dc727810925a Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 19 Nov 2024 23:52:44 +0700 Subject: [PATCH 06/27] fix use token as array on FollowedByCommaAnalyzer --- rules/DowngradePhp73/Tokenizer/FollowedByCommaAnalyzer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rules/DowngradePhp73/Tokenizer/FollowedByCommaAnalyzer.php b/rules/DowngradePhp73/Tokenizer/FollowedByCommaAnalyzer.php index dec343d8..ae1b2aba 100644 --- a/rules/DowngradePhp73/Tokenizer/FollowedByCommaAnalyzer.php +++ b/rules/DowngradePhp73/Tokenizer/FollowedByCommaAnalyzer.php @@ -19,13 +19,13 @@ public function isFollowed(File $file, Node $node): bool $currentToken = $oldTokens[$nextTokenPosition]; // only space - if (is_array($currentToken) || StringUtils::isMatch($currentToken, '#\s+#')) { + if (StringUtils::isMatch((string) $currentToken, '#\s+#')) { ++$nextTokenPosition; continue; } // without comma - if (in_array($currentToken, ['(', ')', ';'], true)) { + if (in_array((string) $currentToken, ['(', ')', ';'], true)) { return false; } From 7b530e2de285a382868c2c956b84ec0471b69bc3 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 20 Nov 2024 00:00:30 +0700 Subject: [PATCH 07/27] fix downgrade array spread --- .../ArrayMergeFromArraySpreadFactory.php | 13 ++++++------- .../Array_/DowngradeArraySpreadStringKeyRector.php | 4 +++- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/rules/DowngradePhp81/NodeFactory/ArrayMergeFromArraySpreadFactory.php b/rules/DowngradePhp81/NodeFactory/ArrayMergeFromArraySpreadFactory.php index 15d62355..e304152f 100644 --- a/rules/DowngradePhp81/NodeFactory/ArrayMergeFromArraySpreadFactory.php +++ b/rules/DowngradePhp81/NodeFactory/ArrayMergeFromArraySpreadFactory.php @@ -13,7 +13,6 @@ use PhpParser\Node\Expr\Variable; use PhpParser\Node\Name; use PHPStan\Analyser\MutatingScope; -use PHPStan\Type\ArrayType; use PHPStan\Type\IterableType; use PHPStan\Type\ObjectType; use PHPStan\Type\Type; @@ -85,7 +84,7 @@ private function createArrayMergeFuncCall(array $arrayItems, MutatingScope $muta return $this->createArgFromSpreadArrayItem($mutatingScope, $arrayItem); } - return new Arg($arrayItem); + return new Arg($arrayItem->value); }, $arrayItems); return new FuncCall(new Name('array_merge'), $args); @@ -121,13 +120,13 @@ private function createArgFromSpreadArrayItem(MutatingScope $mutatingScope, Arra } } - $iteratorToArrayFuncCall = new FuncCall(new Name('iterator_to_array'), [new Arg($arrayItem)]); + $iteratorToArrayFuncCall = new FuncCall(new Name('iterator_to_array'), [new Arg($arrayItem->value)]); // If we know it is an array, then print it directly // Otherwise PHPStan throws an error: // "Else branch is unreachable because ternary operator condition is always true." - if ($type instanceof ArrayType) { - return new Arg($arrayItem); + if ($type->isArray()->yes()) { + return new Arg($arrayItem->value); } // If it is iterable, then directly return `iterator_to_array` @@ -136,8 +135,8 @@ private function createArgFromSpreadArrayItem(MutatingScope $mutatingScope, Arra } // Print a ternary, handling either an array or an iterator - $inArrayFuncCall = new FuncCall(new Name('is_array'), [new Arg($arrayItem)]); - return new Arg(new Ternary($inArrayFuncCall, $arrayItem, $iteratorToArrayFuncCall)); + $inArrayFuncCall = new FuncCall(new Name('is_array'), [new Arg($arrayItem->value)]); + return new Arg(new Ternary($inArrayFuncCall, $arrayItem->value, $iteratorToArrayFuncCall)); } /** diff --git a/rules/DowngradePhp81/Rector/Array_/DowngradeArraySpreadStringKeyRector.php b/rules/DowngradePhp81/Rector/Array_/DowngradeArraySpreadStringKeyRector.php index b5ed83cd..4bfc177f 100644 --- a/rules/DowngradePhp81/Rector/Array_/DowngradeArraySpreadStringKeyRector.php +++ b/rules/DowngradePhp81/Rector/Array_/DowngradeArraySpreadStringKeyRector.php @@ -4,6 +4,7 @@ namespace Rector\DowngradePhp81\Rector\Array_; +use PHPStan\Type\Constant\ConstantArrayType; use PhpParser\Node; use PhpParser\Node\ArrayItem; use PhpParser\Node\Expr\Array_; @@ -89,10 +90,11 @@ private function shouldSkipArray(Array_ $array): bool } $type = $this->nodeTypeResolver->getType($item->value); - if (! $type instanceof ArrayType) { + if (! $type->isArray()->yes()) { continue; } + /** @var ArrayType|ConstantArrayType $type */ $keyType = $type->getKeyType(); if ($keyType instanceof IntegerType) { return true; From 47d8b97fb9d430811bc87c89f39b8bce274fd8f0 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Tue, 19 Nov 2024 17:01:12 +0000 Subject: [PATCH 08/27] [ci-review] Rector Rectify --- .../Rector/Array_/DowngradeArraySpreadStringKeyRector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules/DowngradePhp81/Rector/Array_/DowngradeArraySpreadStringKeyRector.php b/rules/DowngradePhp81/Rector/Array_/DowngradeArraySpreadStringKeyRector.php index 4bfc177f..c362f8a2 100644 --- a/rules/DowngradePhp81/Rector/Array_/DowngradeArraySpreadStringKeyRector.php +++ b/rules/DowngradePhp81/Rector/Array_/DowngradeArraySpreadStringKeyRector.php @@ -4,12 +4,12 @@ namespace Rector\DowngradePhp81\Rector\Array_; -use PHPStan\Type\Constant\ConstantArrayType; use PhpParser\Node; use PhpParser\Node\ArrayItem; use PhpParser\Node\Expr\Array_; use PHPStan\Analyser\MutatingScope; use PHPStan\Type\ArrayType; +use PHPStan\Type\Constant\ConstantArrayType; use PHPStan\Type\IntegerType; use Rector\DowngradePhp81\NodeAnalyzer\ArraySpreadAnalyzer; use Rector\DowngradePhp81\NodeFactory\ArrayMergeFromArraySpreadFactory; From 8a822604572b56b0a9b1018d5f7b539714255e47 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 20 Nov 2024 00:04:47 +0700 Subject: [PATCH 09/27] fix Throw_ as Expr on DowngradeThrowExprRector --- .../Rector/Expression/DowngradeThrowExprRector.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/rules/DowngradePhp80/Rector/Expression/DowngradeThrowExprRector.php b/rules/DowngradePhp80/Rector/Expression/DowngradeThrowExprRector.php index 5c957ffc..f848a21c 100644 --- a/rules/DowngradePhp80/Rector/Expression/DowngradeThrowExprRector.php +++ b/rules/DowngradePhp80/Rector/Expression/DowngradeThrowExprRector.php @@ -262,10 +262,9 @@ private function refactorDirectCoalesce(Expression $expression): ?array // add condition if above $throwExpr = $coalesce->right; - $throw = new Stmt\Throw_($throwExpr->expr); $if = new If_(new Identical($coalesce->left, new ConstFetch(new Name('null'))), [ - 'stmts' => [$throw], + 'stmts' => [new Expression($throwExpr)], ]); // replace coalsese with left :) From 30fb2c762c12de29b839b62e7f40ac5a8f29507d Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 20 Nov 2024 00:06:35 +0700 Subject: [PATCH 10/27] fix token as array on DowngradeDereferenceableOperationRector --- .../ArrayDimFetch/DowngradeDereferenceableOperationRector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules/DowngradePhp80/Rector/ArrayDimFetch/DowngradeDereferenceableOperationRector.php b/rules/DowngradePhp80/Rector/ArrayDimFetch/DowngradeDereferenceableOperationRector.php index ebe85b65..6dd11357 100644 --- a/rules/DowngradePhp80/Rector/ArrayDimFetch/DowngradeDereferenceableOperationRector.php +++ b/rules/DowngradePhp80/Rector/ArrayDimFetch/DowngradeDereferenceableOperationRector.php @@ -98,7 +98,7 @@ private function hasParentheses(ArrayDimFetch $arrayDimFetch): bool continue; } - if ($oldTokens[$i] !== ')') { + if ((string) $oldTokens[$i] !== ')') { continue; } From abd18bf33e574d577964e59aff2b32886aa82d0f Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 20 Nov 2024 00:09:35 +0700 Subject: [PATCH 11/27] fix constant type on DowngradeNamedArgumentRector --- .../Reflection/DefaultParameterValueResolver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rules/DowngradePhp80/Reflection/DefaultParameterValueResolver.php b/rules/DowngradePhp80/Reflection/DefaultParameterValueResolver.php index 1a6f6361..bdd06a43 100644 --- a/rules/DowngradePhp80/Reflection/DefaultParameterValueResolver.php +++ b/rules/DowngradePhp80/Reflection/DefaultParameterValueResolver.php @@ -25,14 +25,14 @@ public function resolveFromParameterReflection(ParameterReflection $parameterRef return null; } - if (! $defaultValueType instanceof ConstantType) { + if (! $defaultValueType->isConstantValue()->yes()) { throw new ShouldNotHappenException(); } return $this->resolveValueFromType($defaultValueType); } - private function resolveValueFromType(ConstantType $constantType): ConstFetch | Expr + private function resolveValueFromType(Type $constantType): ConstFetch | Expr { if ($constantType instanceof ConstantBooleanType) { return $this->resolveConstantBooleanType($constantType); From 6a88e43eb0e88195420fe3da85a377d1f5af245f Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 20 Nov 2024 00:11:44 +0700 Subject: [PATCH 12/27] fix ParamTagValueNode usage on DowngradeEnumToConstantListClassRector --- .../Rector/Enum_/DowngradeEnumToConstantListClassRector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules/DowngradePhp80/Rector/Enum_/DowngradeEnumToConstantListClassRector.php b/rules/DowngradePhp80/Rector/Enum_/DowngradeEnumToConstantListClassRector.php index 3e64d172..c6d46994 100644 --- a/rules/DowngradePhp80/Rector/Enum_/DowngradeEnumToConstantListClassRector.php +++ b/rules/DowngradePhp80/Rector/Enum_/DowngradeEnumToConstantListClassRector.php @@ -137,7 +137,7 @@ private function decorateParamDocType( $paramTypeNode = $isNullable ? new NullableTypeNode($constTypeNode) : $constTypeNode; - $paramTagValueNode = new ParamTagValueNode($paramTypeNode, false, $paramName, ''); + $paramTagValueNode = new ParamTagValueNode($paramTypeNode, false, $paramName, '', false); $phpDocInfo->addTagValueNode($paramTagValueNode); $this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($classMethod); From 48c89e27c68c5bbb5383e0daae94c2533a534a91 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 20 Nov 2024 00:13:20 +0700 Subject: [PATCH 13/27] fix throw as expr on ArrowFunctionToAnonymousFunctionRector --- .../ArrowFunctionToAnonymousFunctionRector.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/rules/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector.php b/rules/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector.php index f359ad53..11df03dd 100644 --- a/rules/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector.php +++ b/rules/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector.php @@ -11,6 +11,7 @@ use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\Closure; use PhpParser\Node\Expr\Variable; +use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\Return_; use PhpParser\Node\Stmt\Throw_; use PHPStan\Analyser\Scope; @@ -102,7 +103,7 @@ public function refactor(Node $node): Closure } // downgrade "return throw" - $this->traverseNodesWithCallable($anonymousFunctionFactory, static function (Node $node): ?Throw_ { + $this->traverseNodesWithCallable($anonymousFunctionFactory, static function (Node $node): ?Expression { if (! $node instanceof Return_) { return null; } @@ -111,10 +112,8 @@ public function refactor(Node $node): Closure return null; } - $throw = $node->expr; - // throw expr to throw stmts - return new Throw_($throw->expr); + return new Expression($node->expr); }); $this->appendUsesFromInsertedVariable($node->expr, $anonymousFunctionFactory); From dc7b56e41d3afc6a441977ee9b664d6c51d014d9 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Tue, 19 Nov 2024 17:14:03 +0000 Subject: [PATCH 14/27] [ci-review] Rector Rectify --- .../ArrowFunction/ArrowFunctionToAnonymousFunctionRector.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rules/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector.php b/rules/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector.php index 11df03dd..b45f3fc8 100644 --- a/rules/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector.php +++ b/rules/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector.php @@ -10,10 +10,10 @@ use PhpParser\Node\Expr\ArrowFunction; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\Closure; +use PhpParser\Node\Expr\Throw_; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\Return_; -use PhpParser\Node\Stmt\Throw_; use PHPStan\Analyser\Scope; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\Php72\NodeFactory\AnonymousFunctionFactory; @@ -108,7 +108,7 @@ public function refactor(Node $node): Closure return null; } - if (! $node->expr instanceof Node\Expr\Throw_) { + if (! $node->expr instanceof Throw_) { return null; } From fed18928a2018c932285bfe8dacbe0a4aa586854 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 20 Nov 2024 00:16:25 +0700 Subject: [PATCH 15/27] fix --- .../ConstFetch/DowngradePhp73JsonConstRector.php | 4 ++-- .../ArrowFunctionToAnonymousFunctionRector.php | 1 + .../Expression/DowngradeMatchToSwitchRector.php | 16 ++++++++-------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/rules/DowngradePhp73/Rector/ConstFetch/DowngradePhp73JsonConstRector.php b/rules/DowngradePhp73/Rector/ConstFetch/DowngradePhp73JsonConstRector.php index 1fe795c5..978202c1 100644 --- a/rules/DowngradePhp73/Rector/ConstFetch/DowngradePhp73JsonConstRector.php +++ b/rules/DowngradePhp73/Rector/ConstFetch/DowngradePhp73JsonConstRector.php @@ -4,6 +4,7 @@ namespace Rector\DowngradePhp73\Rector\ConstFetch; +use PhpParser\NodeVisitor; use PhpParser\Node; use PhpParser\Node\Arg; use PhpParser\Node\Expr; @@ -23,7 +24,6 @@ use PhpParser\Node\Stmt\Throw_; use PhpParser\Node\Stmt\TryCatch; use PhpParser\Node\VariadicPlaceholder; -use PhpParser\NodeTraverser; use Rector\DowngradePhp72\NodeManipulator\JsonConstCleaner; use Rector\Enum\JsonConstant; use Rector\NodeAnalyzer\DefineFuncCallAnalyzer; @@ -120,7 +120,7 @@ public function refactor(Node $node): int|null|Expr|If_|array $node->stmts, function (Node $subNode): ?int { if ($subNode instanceof Class_ || $subNode instanceof Function_ || $subNode instanceof Closure) { - return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN; + return NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN; } if (! $subNode instanceof Expression) { diff --git a/rules/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector.php b/rules/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector.php index b45f3fc8..3c663008 100644 --- a/rules/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector.php +++ b/rules/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector.php @@ -4,6 +4,7 @@ namespace Rector\DowngradePhp74\Rector\ArrowFunction; +use PhpParser\Node\Expr\Throw_; use PhpParser\Node; use PhpParser\Node\ClosureUse; use PhpParser\Node\Expr; diff --git a/rules/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector.php b/rules/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector.php index 97bf1523..b4614e42 100644 --- a/rules/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector.php +++ b/rules/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector.php @@ -4,6 +4,7 @@ namespace Rector\DowngradePhp80\Rector\Expression; +use PhpParser\NodeVisitor; use PhpParser\Node; use PhpParser\Node\Arg; use PhpParser\Node\ArrayItem; @@ -25,7 +26,6 @@ use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\Return_; use PhpParser\Node\Stmt\Switch_; -use PhpParser\NodeTraverser; use PHPStan\Analyser\Scope; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\Php72\NodeFactory\AnonymousFunctionFactory; @@ -120,7 +120,7 @@ function (Node $subNode) use ($node, &$match, &$hasChanged, $scope) { $subNode->value = new FuncCall($this->anonymousFunctionFactory->create([], [$switch], null)); $hasChanged = true; - return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN; + return NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN; } if ($subNode instanceof Arg && $subNode->value instanceof ArrowFunction && $subNode->value->expr instanceof Match_) { @@ -129,7 +129,7 @@ function (Node $subNode) use ($node, &$match, &$hasChanged, $scope) { $hasChanged = true; } - return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN; + return NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN; } if ($subNode instanceof Assign && $subNode->expr instanceof ArrowFunction && $subNode->expr->expr instanceof Match_) { @@ -138,7 +138,7 @@ function (Node $subNode) use ($node, &$match, &$hasChanged, $scope) { $hasChanged = true; } - return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN; + return NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN; } if ($subNode instanceof Expression && $subNode->expr instanceof ArrowFunction && $subNode->expr->expr instanceof Match_) { @@ -147,7 +147,7 @@ function (Node $subNode) use ($node, &$match, &$hasChanged, $scope) { $hasChanged = true; } - return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN; + return NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN; } if ($subNode instanceof Return_ && $subNode->expr instanceof ArrowFunction && $subNode->expr->expr instanceof Match_) { @@ -156,7 +156,7 @@ function (Node $subNode) use ($node, &$match, &$hasChanged, $scope) { $hasChanged = true; } - return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN; + return NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN; } if ($subNode instanceof FuncCall && $subNode->name instanceof ArrowFunction && $subNode->name->expr instanceof Match_) { @@ -165,12 +165,12 @@ function (Node $subNode) use ($node, &$match, &$hasChanged, $scope) { $hasChanged = true; } - return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN; + return NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN; } if ($subNode instanceof Match_) { $match = $subNode; - return NodeTraverser::STOP_TRAVERSAL; + return NodeVisitor::STOP_TRAVERSAL; } } ); From 12cebe33d270eff923dab30611dcce61ca107204 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 20 Nov 2024 00:18:23 +0700 Subject: [PATCH 16/27] fix throw --- .../ArrowFunction/ArrowFunctionToAnonymousFunctionRector.php | 1 - 1 file changed, 1 deletion(-) diff --git a/rules/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector.php b/rules/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector.php index 3c663008..b45f3fc8 100644 --- a/rules/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector.php +++ b/rules/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector.php @@ -4,7 +4,6 @@ namespace Rector\DowngradePhp74\Rector\ArrowFunction; -use PhpParser\Node\Expr\Throw_; use PhpParser\Node; use PhpParser\Node\ClosureUse; use PhpParser\Node\Expr; From df892839f965b42f19b5bcd5642be9b0476d653e Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Tue, 19 Nov 2024 17:19:07 +0000 Subject: [PATCH 17/27] [ci-review] Rector Rectify --- .../Rector/ConstFetch/DowngradePhp73JsonConstRector.php | 2 +- .../Rector/Expression/DowngradeMatchToSwitchRector.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rules/DowngradePhp73/Rector/ConstFetch/DowngradePhp73JsonConstRector.php b/rules/DowngradePhp73/Rector/ConstFetch/DowngradePhp73JsonConstRector.php index 978202c1..c8484fe9 100644 --- a/rules/DowngradePhp73/Rector/ConstFetch/DowngradePhp73JsonConstRector.php +++ b/rules/DowngradePhp73/Rector/ConstFetch/DowngradePhp73JsonConstRector.php @@ -4,7 +4,6 @@ namespace Rector\DowngradePhp73\Rector\ConstFetch; -use PhpParser\NodeVisitor; use PhpParser\Node; use PhpParser\Node\Arg; use PhpParser\Node\Expr; @@ -24,6 +23,7 @@ use PhpParser\Node\Stmt\Throw_; use PhpParser\Node\Stmt\TryCatch; use PhpParser\Node\VariadicPlaceholder; +use PhpParser\NodeVisitor; use Rector\DowngradePhp72\NodeManipulator\JsonConstCleaner; use Rector\Enum\JsonConstant; use Rector\NodeAnalyzer\DefineFuncCallAnalyzer; diff --git a/rules/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector.php b/rules/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector.php index b4614e42..205f138a 100644 --- a/rules/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector.php +++ b/rules/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector.php @@ -4,7 +4,6 @@ namespace Rector\DowngradePhp80\Rector\Expression; -use PhpParser\NodeVisitor; use PhpParser\Node; use PhpParser\Node\Arg; use PhpParser\Node\ArrayItem; @@ -26,6 +25,7 @@ use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\Return_; use PhpParser\Node\Stmt\Switch_; +use PhpParser\NodeVisitor; use PHPStan\Analyser\Scope; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\Php72\NodeFactory\AnonymousFunctionFactory; From 8b8d200dd47a58bf1115abafcdafa6de255eed3a Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 20 Nov 2024 00:28:55 +0700 Subject: [PATCH 18/27] fix downgrade json const and fix token as array --- .../Rector/ConstFetch/DowngradePhp73JsonConstRector.php | 6 +++--- .../FollowedByNewlineOnlyMaybeWithSemicolonAnalyzer.php | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/rules/DowngradePhp73/Rector/ConstFetch/DowngradePhp73JsonConstRector.php b/rules/DowngradePhp73/Rector/ConstFetch/DowngradePhp73JsonConstRector.php index c8484fe9..c985a470 100644 --- a/rules/DowngradePhp73/Rector/ConstFetch/DowngradePhp73JsonConstRector.php +++ b/rules/DowngradePhp73/Rector/ConstFetch/DowngradePhp73JsonConstRector.php @@ -14,13 +14,13 @@ use PhpParser\Node\Expr\ConstFetch; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\New_; +use PhpParser\Node\Expr\Throw_; use PhpParser\Node\Name; use PhpParser\Node\Name\FullyQualified as NameFullyQualified; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\Function_; use PhpParser\Node\Stmt\If_; -use PhpParser\Node\Stmt\Throw_; use PhpParser\Node\Stmt\TryCatch; use PhpParser\Node\VariadicPlaceholder; use PhpParser\NodeVisitor; @@ -219,12 +219,12 @@ private function refactorStmt(Expression $Expression): ?array ), [ 'stmts' => [ - new Throw_( + new Expression(new Throw_( new New_( new NameFullyQualified('Exception'), [new Arg(new FuncCall(new Name('json_last_error_msg')))] ) - ), + )), ], ] ); diff --git a/rules/DowngradePhp73/Tokenizer/FollowedByNewlineOnlyMaybeWithSemicolonAnalyzer.php b/rules/DowngradePhp73/Tokenizer/FollowedByNewlineOnlyMaybeWithSemicolonAnalyzer.php index 1072702b..f9ae3ecb 100644 --- a/rules/DowngradePhp73/Tokenizer/FollowedByNewlineOnlyMaybeWithSemicolonAnalyzer.php +++ b/rules/DowngradePhp73/Tokenizer/FollowedByNewlineOnlyMaybeWithSemicolonAnalyzer.php @@ -15,12 +15,12 @@ public function isFollowed(File $file, Node $node): bool $nextTokenPosition = $node->getEndTokenPos() + 1; - if (isset($oldTokens[$nextTokenPosition]) && $oldTokens[$nextTokenPosition] === ';') { + if (isset($oldTokens[$nextTokenPosition]) && (string) $oldTokens[$nextTokenPosition] === ';') { ++$nextTokenPosition; } return ! isset($oldTokens[$nextTokenPosition]) || - isset($oldTokens[$nextTokenPosition][1]) && - \str_starts_with((string) $oldTokens[$nextTokenPosition][1], "\n"); + isset($oldTokens[$nextTokenPosition]) && + \str_starts_with((string) $oldTokens[$nextTokenPosition], "\n"); } } From fbb99599a869b8117e708506809f4084512d03ab Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 20 Nov 2024 00:33:54 +0700 Subject: [PATCH 19/27] fix fixture on DowngradeUnionTypeDeclarationRector --- ...t_change_correct_union_array_docblock_on_param.php.inc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rules-tests/DowngradePhp80/Rector/FunctionLike/DowngradeUnionTypeDeclarationRector/Fixture/do_not_change_correct_union_array_docblock_on_param.php.inc b/rules-tests/DowngradePhp80/Rector/FunctionLike/DowngradeUnionTypeDeclarationRector/Fixture/do_not_change_correct_union_array_docblock_on_param.php.inc index 699be934..83f71870 100644 --- a/rules-tests/DowngradePhp80/Rector/FunctionLike/DowngradeUnionTypeDeclarationRector/Fixture/do_not_change_correct_union_array_docblock_on_param.php.inc +++ b/rules-tests/DowngradePhp80/Rector/FunctionLike/DowngradeUnionTypeDeclarationRector/Fixture/do_not_change_correct_union_array_docblock_on_param.php.inc @@ -7,14 +7,14 @@ use PhpParser\Node\Stmt; final class DoNotChangeCorrectUnionArrayDocblockOnParam { /** - * @param int|string[] + * @param int|string[] $data */ public function run(int|array $data) { } /** - * @param Node|null|Stmt[] + * @param Node|null|Stmt[] $data */ public function run2(Node|null|array $data) { @@ -32,14 +32,14 @@ use PhpParser\Node\Stmt; final class DoNotChangeCorrectUnionArrayDocblockOnParam { /** - * @param int|string[] + * @param int|string[] $data */ public function run($data) { } /** - * @param Node|null|Stmt[] + * @param Node|null|Stmt[] $data */ public function run2($data) { From f1fc7690860acafa9fd323126b89d20833453036 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 20 Nov 2024 00:40:46 +0700 Subject: [PATCH 20/27] fix constant type --- .../Reflection/DefaultParameterValueResolver.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/rules/DowngradePhp80/Reflection/DefaultParameterValueResolver.php b/rules/DowngradePhp80/Reflection/DefaultParameterValueResolver.php index bdd06a43..b02d665a 100644 --- a/rules/DowngradePhp80/Reflection/DefaultParameterValueResolver.php +++ b/rules/DowngradePhp80/Reflection/DefaultParameterValueResolver.php @@ -11,7 +11,6 @@ use PHPStan\Reflection\ParameterReflection; use PHPStan\Type\Constant\ConstantArrayType; use PHPStan\Type\Constant\ConstantBooleanType; -use PHPStan\Type\ConstantType; use PHPStan\Type\Type; use PHPStan\Type\VerbosityLevel; use Rector\Exception\ShouldNotHappenException; @@ -41,7 +40,7 @@ private function resolveValueFromType(Type $constantType): ConstFetch | Expr if ($constantType instanceof ConstantArrayType) { $values = []; foreach ($constantType->getValueTypes() as $valueType) { - if (! $valueType instanceof ConstantType) { + if (! $valueType->isConstantValue()->yes()) { throw new ShouldNotHappenException(); } From bd0b1c250c50ca07c6fb2170745994a52faeeb94 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 20 Nov 2024 00:47:10 +0700 Subject: [PATCH 21/27] fixing phpstan --- phpstan.neon | 3 +++ .../Reflection/DefaultParameterValueResolver.php | 4 ++++ .../NodeFactory/ArrayMergeFromArraySpreadFactory.php | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/phpstan.neon b/phpstan.neon index 155418cc..2e20dea8 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -71,4 +71,7 @@ parameters: - identifier: phpstanApi.instanceofAssumption + - + identifier: phpstanApi.varTagAssumption + - '#Asking about instanceof PHPStan\\.* is not covered by backward compatibility promise#' diff --git a/rules/DowngradePhp80/Reflection/DefaultParameterValueResolver.php b/rules/DowngradePhp80/Reflection/DefaultParameterValueResolver.php index b02d665a..c884d1da 100644 --- a/rules/DowngradePhp80/Reflection/DefaultParameterValueResolver.php +++ b/rules/DowngradePhp80/Reflection/DefaultParameterValueResolver.php @@ -4,6 +4,9 @@ namespace Rector\DowngradePhp80\Reflection; +use PHPStan\Type\Constant\ConstantStringType; +use PHPStan\Type\Constant\ConstantIntegerType; +use PHPStan\Type\NullType; use PhpParser\BuilderHelpers; use PhpParser\Node\Expr; use PhpParser\Node\Expr\ConstFetch; @@ -50,6 +53,7 @@ private function resolveValueFromType(Type $constantType): ConstFetch | Expr return BuilderHelpers::normalizeValue($values); } + /** @var ConstantStringType|ConstantIntegerType|NullType $constantType */ return BuilderHelpers::normalizeValue($constantType->getValue()); } diff --git a/rules/DowngradePhp81/NodeFactory/ArrayMergeFromArraySpreadFactory.php b/rules/DowngradePhp81/NodeFactory/ArrayMergeFromArraySpreadFactory.php index e304152f..992d0d87 100644 --- a/rules/DowngradePhp81/NodeFactory/ArrayMergeFromArraySpreadFactory.php +++ b/rules/DowngradePhp81/NodeFactory/ArrayMergeFromArraySpreadFactory.php @@ -91,7 +91,7 @@ private function createArrayMergeFuncCall(array $arrayItems, MutatingScope $muta } /** - * @param array<(ArrayItem | null)> $items + * @param array $items */ private function createArrayItemFromArray(array $items): ArrayItem { From 5fa0e8dc80b0f82a7026895018454e814177128c Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Tue, 19 Nov 2024 17:47:53 +0000 Subject: [PATCH 22/27] [ci-review] Rector Rectify --- .../Reflection/DefaultParameterValueResolver.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rules/DowngradePhp80/Reflection/DefaultParameterValueResolver.php b/rules/DowngradePhp80/Reflection/DefaultParameterValueResolver.php index c884d1da..a61b349b 100644 --- a/rules/DowngradePhp80/Reflection/DefaultParameterValueResolver.php +++ b/rules/DowngradePhp80/Reflection/DefaultParameterValueResolver.php @@ -4,9 +4,6 @@ namespace Rector\DowngradePhp80\Reflection; -use PHPStan\Type\Constant\ConstantStringType; -use PHPStan\Type\Constant\ConstantIntegerType; -use PHPStan\Type\NullType; use PhpParser\BuilderHelpers; use PhpParser\Node\Expr; use PhpParser\Node\Expr\ConstFetch; @@ -14,6 +11,9 @@ use PHPStan\Reflection\ParameterReflection; use PHPStan\Type\Constant\ConstantArrayType; use PHPStan\Type\Constant\ConstantBooleanType; +use PHPStan\Type\Constant\ConstantIntegerType; +use PHPStan\Type\Constant\ConstantStringType; +use PHPStan\Type\NullType; use PHPStan\Type\Type; use PHPStan\Type\VerbosityLevel; use Rector\Exception\ShouldNotHappenException; From 04f7089750ba141803f306e8169c1f014fecab8b Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 20 Nov 2024 00:48:06 +0700 Subject: [PATCH 23/27] fix phpstan on DowngradeAttributeToAnnotationRector --- .../Rector/Class_/DowngradeAttributeToAnnotationRector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules/DowngradePhp80/Rector/Class_/DowngradeAttributeToAnnotationRector.php b/rules/DowngradePhp80/Rector/Class_/DowngradeAttributeToAnnotationRector.php index 644f520d..757adb3e 100644 --- a/rules/DowngradePhp80/Rector/Class_/DowngradeAttributeToAnnotationRector.php +++ b/rules/DowngradePhp80/Rector/Class_/DowngradeAttributeToAnnotationRector.php @@ -152,7 +152,7 @@ public function refactor(Node $node): ?Node } /** - * @param mixed[] $configuration + * @param DowngradeAttributeToAnnotation[] $configuration */ public function configure(array $configuration): void { From 866dbd49118ac47a5bd47bf4e2c26e19d65447f6 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 20 Nov 2024 00:51:00 +0700 Subject: [PATCH 24/27] fix phpstan --- phpstan.neon | 3 +++ 1 file changed, 3 insertions(+) diff --git a/phpstan.neon b/phpstan.neon index 2e20dea8..4e28e2c9 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -74,4 +74,7 @@ parameters: - identifier: phpstanApi.varTagAssumption + - + identifier: argument.type + - '#Asking about instanceof PHPStan\\.* is not covered by backward compatibility promise#' From 2d70ff9817f67beb75b7ac20693bb7b009996f58 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 20 Nov 2024 01:51:15 +0700 Subject: [PATCH 25/27] fix fixture --- .../Fixture/fixture.php.inc | 6 ++---- .../Fixture/line_ends_with_newline_or_semicolon.php.inc | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/rules-tests/DowngradePhp73/Rector/String_/DowngradeFlexibleHeredocSyntaxRector/Fixture/fixture.php.inc b/rules-tests/DowngradePhp73/Rector/String_/DowngradeFlexibleHeredocSyntaxRector/Fixture/fixture.php.inc index 1ae4609f..b2345389 100644 --- a/rules-tests/DowngradePhp73/Rector/String_/DowngradeFlexibleHeredocSyntaxRector/Fixture/fixture.php.inc +++ b/rules-tests/DowngradePhp73/Rector/String_/DowngradeFlexibleHeredocSyntaxRector/Fixture/fixture.php.inc @@ -42,13 +42,11 @@ SQL; SELECT * FROM `table` WHERE `column` = true; -SQL -); +SQL); $this->setOnClick(<<getHtmlId()}').value = ''; document.getElementById('{$this->getHtmlId()}').onchange(); -JAVASCRIPT -); +JAVASCRIPT); } } diff --git a/rules-tests/DowngradePhp73/Rector/String_/DowngradeFlexibleHeredocSyntaxRector/Fixture/line_ends_with_newline_or_semicolon.php.inc b/rules-tests/DowngradePhp73/Rector/String_/DowngradeFlexibleHeredocSyntaxRector/Fixture/line_ends_with_newline_or_semicolon.php.inc index 041d2de7..b7e558c6 100644 --- a/rules-tests/DowngradePhp73/Rector/String_/DowngradeFlexibleHeredocSyntaxRector/Fixture/line_ends_with_newline_or_semicolon.php.inc +++ b/rules-tests/DowngradePhp73/Rector/String_/DowngradeFlexibleHeredocSyntaxRector/Fixture/line_ends_with_newline_or_semicolon.php.inc @@ -46,13 +46,11 @@ EOS $needsDowngrade1 = sprintf(<< Date: Wed, 20 Nov 2024 03:21:41 +0700 Subject: [PATCH 26/27] handle doc indentation --- .../Rector/String_/DowngradeFlexibleHeredocSyntaxRector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules/DowngradePhp73/Rector/String_/DowngradeFlexibleHeredocSyntaxRector.php b/rules/DowngradePhp73/Rector/String_/DowngradeFlexibleHeredocSyntaxRector.php index 8df470e3..785b4d3d 100644 --- a/rules/DowngradePhp73/Rector/String_/DowngradeFlexibleHeredocSyntaxRector.php +++ b/rules/DowngradePhp73/Rector/String_/DowngradeFlexibleHeredocSyntaxRector.php @@ -80,7 +80,7 @@ public function refactor(Node $node): ?Node return null; } - $node->setAttribute(AttributeKey::DOC_INDENTATION, ''); + $node->setAttribute(AttributeKey::DOC_INDENTATION, '__REMOVED__'); $node->setAttribute(AttributeKey::ORIGINAL_NODE, null); return $node; From 2b4eab909a7481917573e5fa9d4a13e0247e155b Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 20 Nov 2024 17:58:26 +0700 Subject: [PATCH 27/27] require dev phpstan webmozart v2 and fix phsptan message return --- composer.json | 1 + phpstan.neon | 4 ---- .../Rector/ConstFetch/DowngradePhp72JsonConstRector.php | 2 +- .../Rector/ConstFetch/DowngradePhp73JsonConstRector.php | 4 ++-- .../MethodCall/DowngradeReflectionGetTypeRector.php | 2 +- .../DowngradeArrayFilterNullableCallbackRector.php | 2 +- .../MethodCall/DowngradeReflectionGetAttributesRector.php | 2 +- .../New_/DowngradeArbitraryExpressionsSupportRector.php | 8 ++++---- .../DowngradeNullsafeToTernaryOperatorRector.php | 2 +- .../NodeFactory/ArrayMergeFromArraySpreadFactory.php | 3 +-- 10 files changed, 13 insertions(+), 17 deletions(-) diff --git a/composer.json b/composer.json index b712cb8d..4f812e76 100644 --- a/composer.json +++ b/composer.json @@ -9,6 +9,7 @@ "require-dev": { "phpstan/extension-installer": "^1.3", "phpstan/phpstan": "^2.0", + "phpstan/phpstan-webmozart-assert": "^2.0", "phpunit/phpunit": "^10.5", "rector/rector-src": "dev-upgrade-to-php-parser5-and-phpstan-2", "symplify/easy-coding-standard": "^12.3", diff --git a/phpstan.neon b/phpstan.neon index 4e28e2c9..55bbe8f6 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -63,10 +63,6 @@ parameters: # see https://github.com/rectorphp/rector-src/actions/runs/11798721617/job/32865546672?pr=6422#step:5:110 - '#Doing instanceof PHPStan\\Type\\.+ is error\-prone and deprecated#' - # follow parent signature - - - identifier: return.unusedType - # phpstan instanceof - identifier: phpstanApi.instanceofAssumption diff --git a/rules/DowngradePhp72/Rector/ConstFetch/DowngradePhp72JsonConstRector.php b/rules/DowngradePhp72/Rector/ConstFetch/DowngradePhp72JsonConstRector.php index debc526d..ce64c1c9 100644 --- a/rules/DowngradePhp72/Rector/ConstFetch/DowngradePhp72JsonConstRector.php +++ b/rules/DowngradePhp72/Rector/ConstFetch/DowngradePhp72JsonConstRector.php @@ -67,7 +67,7 @@ public function getNodeTypes(): array /** * @param ConstFetch|BitwiseOr|If_ $node */ - public function refactor(Node $node): Expr|If_|null|int + public function refactor(Node $node): Expr|If_|null { if ($node instanceof If_) { return $this->refactorIf($node); diff --git a/rules/DowngradePhp73/Rector/ConstFetch/DowngradePhp73JsonConstRector.php b/rules/DowngradePhp73/Rector/ConstFetch/DowngradePhp73JsonConstRector.php index c985a470..660903ab 100644 --- a/rules/DowngradePhp73/Rector/ConstFetch/DowngradePhp73JsonConstRector.php +++ b/rules/DowngradePhp73/Rector/ConstFetch/DowngradePhp73JsonConstRector.php @@ -102,9 +102,9 @@ public function getNodeTypes(): array /** * @param ConstFetch|BitwiseOr|If_|TryCatch|Expression $node - * @return int|null|Expr|If_|array + * @return null|Expr|If_|array */ - public function refactor(Node $node): int|null|Expr|If_|array + public function refactor(Node $node): null|Expr|If_|array { if ($node instanceof If_) { return $this->refactorIf($node); diff --git a/rules/DowngradePhp74/Rector/MethodCall/DowngradeReflectionGetTypeRector.php b/rules/DowngradePhp74/Rector/MethodCall/DowngradeReflectionGetTypeRector.php index 4add4d57..65dcf3bd 100644 --- a/rules/DowngradePhp74/Rector/MethodCall/DowngradeReflectionGetTypeRector.php +++ b/rules/DowngradePhp74/Rector/MethodCall/DowngradeReflectionGetTypeRector.php @@ -74,7 +74,7 @@ public function getNodeTypes(): array /** * @param MethodCall|Ternary|Instanceof_ $node */ - public function refactor(Node $node): Node|null|int + public function refactor(Node $node): Node|null { if ($node instanceof Instanceof_) { return $this->refactorInstanceof($node); diff --git a/rules/DowngradePhp80/Rector/FuncCall/DowngradeArrayFilterNullableCallbackRector.php b/rules/DowngradePhp80/Rector/FuncCall/DowngradeArrayFilterNullableCallbackRector.php index 08520f11..ac510f59 100644 --- a/rules/DowngradePhp80/Rector/FuncCall/DowngradeArrayFilterNullableCallbackRector.php +++ b/rules/DowngradePhp80/Rector/FuncCall/DowngradeArrayFilterNullableCallbackRector.php @@ -89,7 +89,7 @@ public function getNodeTypes(): array /** * @param FuncCall $node */ - public function refactor(Node $node): FuncCall|Ternary|null + public function refactor(Node $node): FuncCall|null { if (! $this->isName($node, 'array_filter')) { return null; diff --git a/rules/DowngradePhp80/Rector/MethodCall/DowngradeReflectionGetAttributesRector.php b/rules/DowngradePhp80/Rector/MethodCall/DowngradeReflectionGetAttributesRector.php index 8745cda4..5e0ceb8e 100644 --- a/rules/DowngradePhp80/Rector/MethodCall/DowngradeReflectionGetAttributesRector.php +++ b/rules/DowngradePhp80/Rector/MethodCall/DowngradeReflectionGetAttributesRector.php @@ -60,7 +60,7 @@ public function getNodeTypes(): array /** * @param Ternary|MethodCall $node */ - public function refactor(Node $node): Ternary|null|int + public function refactor(Node $node): Ternary|null { if ($node instanceof Ternary) { if ($node->if instanceof Expr diff --git a/rules/DowngradePhp80/Rector/New_/DowngradeArbitraryExpressionsSupportRector.php b/rules/DowngradePhp80/Rector/New_/DowngradeArbitraryExpressionsSupportRector.php index de5e9ca5..aa2d3454 100644 --- a/rules/DowngradePhp80/Rector/New_/DowngradeArbitraryExpressionsSupportRector.php +++ b/rules/DowngradePhp80/Rector/New_/DowngradeArbitraryExpressionsSupportRector.php @@ -70,9 +70,9 @@ public function getNodeTypes(): array /** * @param Expression $node - * @return Node\Stmt[]|null|Expression + * @return Expression[]|null */ - public function refactor(Node $node): array|null|Expression + public function refactor(Node $node): array|null { /** @var Assign[] $assigns */ $assigns = $this->betterNodeFinder->findInstancesOf($node, [Assign::class]); @@ -123,7 +123,7 @@ private function isBetweenParentheses(Node $node): bool /** * @param Assign[] $assigns - * @return Node\Stmt[]|null + * @return Expression[]|null */ private function refactorAssign(array $assigns, Expression $expression): array|null { @@ -167,7 +167,7 @@ private function refactorAssign(array $assigns, Expression $expression): array|n } /** - * @return Node\Stmt[]|null + * @return Expression[]|null */ private function refactorInstanceof(Instanceof_ $instanceof, Expression $expression): ?array { diff --git a/rules/DowngradePhp80/Rector/NullsafeMethodCall/DowngradeNullsafeToTernaryOperatorRector.php b/rules/DowngradePhp80/Rector/NullsafeMethodCall/DowngradeNullsafeToTernaryOperatorRector.php index 24e9e78b..03236ed5 100644 --- a/rules/DowngradePhp80/Rector/NullsafeMethodCall/DowngradeNullsafeToTernaryOperatorRector.php +++ b/rules/DowngradePhp80/Rector/NullsafeMethodCall/DowngradeNullsafeToTernaryOperatorRector.php @@ -61,7 +61,7 @@ public function getNodeTypes(): array /** * @param NullsafeMethodCall|NullsafePropertyFetch $node */ - public function refactor(Node $node): ?Ternary + public function refactor(Node $node): Ternary { $nullsafeVariable = $this->createNullsafeVariable(); diff --git a/rules/DowngradePhp81/NodeFactory/ArrayMergeFromArraySpreadFactory.php b/rules/DowngradePhp81/NodeFactory/ArrayMergeFromArraySpreadFactory.php index 992d0d87..ce10386a 100644 --- a/rules/DowngradePhp81/NodeFactory/ArrayMergeFromArraySpreadFactory.php +++ b/rules/DowngradePhp81/NodeFactory/ArrayMergeFromArraySpreadFactory.php @@ -4,7 +4,6 @@ namespace Rector\DowngradePhp81\NodeFactory; -use PhpParser\Node; use PhpParser\Node\Arg; use PhpParser\Node\ArrayItem; use PhpParser\Node\Expr\Array_; @@ -27,7 +26,7 @@ public function __construct( ) { } - public function createFromArray(Array_ $array, MutatingScope $mutatingScope): ?Node + public function createFromArray(Array_ $array, MutatingScope $mutatingScope): FuncCall { $newArrayItems = $this->disolveArrayItems($array); return $this->createArrayMergeFuncCall($newArrayItems, $mutatingScope);