From 1593e367c96ed0153fcbdb1336874ff2a5e0c857 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 20 Nov 2024 18:10:43 +0700 Subject: [PATCH] Use rector-src#dev-upgrade-to-php-parser5-and-phpstan-2 (#235) * Use rector-src#dev-upgrade-to-php-parser5-and-phpstan-2 * update to php-parser 5 nodes * cs fix * fix print return * fix use Token as array * fix use token as array on FollowedByCommaAnalyzer * fix downgrade array spread * [ci-review] Rector Rectify * fix Throw_ as Expr on DowngradeThrowExprRector * fix token as array on DowngradeDereferenceableOperationRector * fix constant type on DowngradeNamedArgumentRector * fix ParamTagValueNode usage on DowngradeEnumToConstantListClassRector * fix throw as expr on ArrowFunctionToAnonymousFunctionRector * [ci-review] Rector Rectify * fix * fix throw * [ci-review] Rector Rectify * fix downgrade json const and fix token as array * fix fixture on DowngradeUnionTypeDeclarationRector * fix constant type * fixing phpstan * [ci-review] Rector Rectify * fix phpstan on DowngradeAttributeToAnnotationRector * fix phpstan * fix fixture * handle doc indentation * require dev phpstan webmozart v2 and fix phsptan message return --------- Co-authored-by: GitHub Action --- composer.json | 11 +++--- phpstan.neon | 35 ++++++++++++++----- .../Fixture/fixture.php.inc | 6 ++-- ...ine_ends_with_newline_or_semicolon.php.inc | 6 ++-- .../arrow_function_inside_call_like.php.inc | 4 +-- .../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 +- .../in_arrow_function_as_invokable.php.inc | 2 +- .../in_arrow_function_in_expression.php.inc | 2 +- .../in_arrow_function_in_return.php.inc | 2 +- ...rect_union_array_docblock_on_param.php.inc | 8 ++--- .../Fixture/fixture.php.inc | 2 +- .../Fixture/inside_if.php.inc | 2 +- .../Fixture/inside_return.php.inc | 2 +- ...scope_parent_assign_from_func_call.php.inc | 2 +- .../NodeManipulator/JsonConstCleaner.php | 10 +++--- .../PhpDoc/NativeParamToPhpDocDecorator.php | 3 +- .../DowngradePhp72JsonConstRector.php | 2 +- ...gradePregUnmatchedAsNullConstantRector.php | 4 +-- .../DowngradePhp73JsonConstRector.php | 19 ++++------ ...SetCookieOptionsArrayToArgumentsRector.php | 2 +- ...DowngradeListReferenceAssignmentRector.php | 16 ++++----- .../DowngradeFlexibleHeredocSyntaxRector.php | 8 ++--- .../Tokenizer/FollowedByCommaAnalyzer.php | 4 +-- ...yNewlineOnlyMaybeWithSemicolonAnalyzer.php | 6 ++-- .../Array_/DowngradeArraySpreadRector.php | 2 +- ...ArrowFunctionToAnonymousFunctionRector.php | 13 ++++--- ...wngradeContravariantArgumentTypeRector.php | 4 +-- ...DowngradeNumericLiteralSeparatorRector.php | 14 ++++---- .../DowngradeReflectionGetTypeRector.php | 2 +- .../NodeAnalyzer/UnnamedArgumentResolver.php | 4 +-- ...owngradeDereferenceableOperationRector.php | 6 ++-- ...radeAbstractPrivateMethodInTraitRector.php | 4 +-- ...owngradeTrailingCommasInParamUseRector.php | 2 +- .../DowngradeAttributeToAnnotationRector.php | 2 +- .../DowngradePropertyPromotionRector.php | 4 +-- ...DowngradeEnumToConstantListClassRector.php | 2 +- .../DowngradeMatchToSwitchRector.php | 18 +++++----- .../Expression/DowngradeThrowExprRector.php | 3 +- ...gradeArrayFilterNullableCallbackRector.php | 6 ++-- .../FuncCall/DowngradeStrEndsWithRector.php | 6 ++-- .../FuncCall/DowngradeStrStartsWithRector.php | 6 ++-- ...eflectionClassGetConstantsFilterRector.php | 2 +- ...DowngradeReflectionGetAttributesRector.php | 2 +- ...gradeArbitraryExpressionsSupportRector.php | 16 ++++----- ...wngradeNullsafeToTernaryOperatorRector.php | 2 +- .../DowngradeUnionTypeTypedPropertyRector.php | 2 +- .../StaticCall/DowngradePhpTokenRector.php | 6 ++-- .../DefaultParameterValueResolver.php | 11 +++--- .../NodeAnalyzer/ArraySpreadAnalyzer.php | 2 +- .../ArrayMergeFromArraySpreadFactory.php | 20 +++++------ .../DowngradeArraySpreadStringKeyRector.php | 6 ++-- ...owngradeFirstClassCallableSyntaxRector.php | 2 +- .../LNumber/DowngradeOctalNumberRector.php | 8 ++--- .../PhpDocFromTypeDeclarationDecorator.php | 5 +-- .../Fixture/fixture.php.inc | 2 +- 59 files changed, 181 insertions(+), 171 deletions(-) diff --git a/composer.json b/composer.json index 3236c8e5..4f812e76 100644 --- a/composer.json +++ b/composer.json @@ -8,14 +8,11 @@ }, "require-dev": { "phpstan/extension-installer": "^1.3", - "phpstan/phpstan": "^1.10", - "phpstan/phpstan-webmozart-assert": "^1.2", + "phpstan/phpstan": "^2.0", + "phpstan/phpstan-webmozart-assert": "^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 +30,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..55bbe8f6 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,18 @@ 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#' + + # phpstan instanceof + - + identifier: phpstanApi.instanceofAssumption + + - + identifier: phpstanApi.varTagAssumption + + - + identifier: argument.type + + - '#Asking about instanceof PHPStan\\.* is not covered by backward compatibility promise#' 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(<< $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/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) { 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/rules/DowngradePhp72/NodeManipulator/JsonConstCleaner.php b/rules/DowngradePhp72/NodeManipulator/JsonConstCleaner.php index ead1f9c8..7fadc85e 100644 --- a/rules/DowngradePhp72/NodeManipulator/JsonConstCleaner.php +++ b/rules/DowngradePhp72/NodeManipulator/JsonConstCleaner.php @@ -8,7 +8,7 @@ use PhpParser\Node\Expr; use PhpParser\Node\Expr\BinaryOp\BitwiseOr; use PhpParser\Node\Expr\ConstFetch; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; 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..a59ece69 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/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/DowngradePhp72/Rector/FuncCall/DowngradePregUnmatchedAsNullConstantRector.php b/rules/DowngradePhp72/Rector/FuncCall/DowngradePregUnmatchedAsNullConstantRector.php index 36f6b999..5bb3dc84 100644 --- a/rules/DowngradePhp72/Rector/FuncCall/DowngradePregUnmatchedAsNullConstantRector.php +++ b/rules/DowngradePhp72/Rector/FuncCall/DowngradePregUnmatchedAsNullConstantRector.php @@ -14,7 +14,7 @@ use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Param; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; 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..660903ab 100644 --- a/rules/DowngradePhp73/Rector/ConstFetch/DowngradePhp73JsonConstRector.php +++ b/rules/DowngradePhp73/Rector/ConstFetch/DowngradePhp73JsonConstRector.php @@ -14,16 +14,16 @@ 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\NodeTraverser; +use PhpParser\NodeVisitor; use Rector\DowngradePhp72\NodeManipulator\JsonConstCleaner; use Rector\Enum\JsonConstant; use Rector\NodeAnalyzer\DefineFuncCallAnalyzer; @@ -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); @@ -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) { @@ -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')))] ) - ), + )), ], ] ); @@ -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..a7b26e43 100644 --- a/rules/DowngradePhp73/Rector/FuncCall/SetCookieOptionsArrayToArgumentsRector.php +++ b/rules/DowngradePhp73/Rector/FuncCall/SetCookieOptionsArrayToArgumentsRector.php @@ -7,8 +7,8 @@ use PhpParser\BuilderHelpers; use PhpParser\Node; use PhpParser\Node\Arg; +use PhpParser\Node\ArrayItem; 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..8b6ccf2f 100644 --- a/rules/DowngradePhp73/Rector/List_/DowngradeListReferenceAssignmentRector.php +++ b/rules/DowngradePhp73/Rector/List_/DowngradeListReferenceAssignmentRector.php @@ -6,14 +6,14 @@ use PhpParser\BuilderHelpers; use PhpParser\Node; +use PhpParser\Node\ArrayItem; 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\Int_; 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..785b4d3d 100644 --- a/rules/DowngradePhp73/Rector/String_/DowngradeFlexibleHeredocSyntaxRector.php +++ b/rules/DowngradePhp73/Rector/String_/DowngradeFlexibleHeredocSyntaxRector.php @@ -5,7 +5,7 @@ namespace Rector\DowngradePhp73\Rector\String_; use PhpParser\Node; -use PhpParser\Node\Scalar\Encapsed; +use PhpParser\Node\Scalar\InterpolatedString; 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 { @@ -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; 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; } diff --git a/rules/DowngradePhp73/Tokenizer/FollowedByNewlineOnlyMaybeWithSemicolonAnalyzer.php b/rules/DowngradePhp73/Tokenizer/FollowedByNewlineOnlyMaybeWithSemicolonAnalyzer.php index c1993f05..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($oldTokens[$nextTokenPosition][1], "\n"); + isset($oldTokens[$nextTokenPosition]) && + \str_starts_with((string) $oldTokens[$nextTokenPosition], "\n"); } } diff --git a/rules/DowngradePhp74/Rector/Array_/DowngradeArraySpreadRector.php b/rules/DowngradePhp74/Rector/Array_/DowngradeArraySpreadRector.php index 2e08c378..a4814419 100644 --- a/rules/DowngradePhp74/Rector/Array_/DowngradeArraySpreadRector.php +++ b/rules/DowngradePhp74/Rector/Array_/DowngradeArraySpreadRector.php @@ -5,8 +5,8 @@ namespace Rector\DowngradePhp74\Rector\Array_; use PhpParser\Node; +use PhpParser\Node\ArrayItem; 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..b45f3fc8 100644 --- a/rules/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector.php +++ b/rules/DowngradePhp74/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector.php @@ -5,14 +5,15 @@ namespace Rector\DowngradePhp74\Rector\ArrowFunction; use PhpParser\Node; +use PhpParser\Node\ClosureUse; 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\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; @@ -102,19 +103,17 @@ 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; } - if (! $node->expr instanceof Node\Expr\Throw_) { + if (! $node->expr instanceof Throw_) { 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); diff --git a/rules/DowngradePhp74/Rector/ClassMethod/DowngradeContravariantArgumentTypeRector.php b/rules/DowngradePhp74/Rector/ClassMethod/DowngradeContravariantArgumentTypeRector.php index 8e7755d6..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 === 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..e288b7bd 100644 --- a/rules/DowngradePhp74/Rector/LNumber/DowngradeNumericLiteralSeparatorRector.php +++ b/rules/DowngradePhp74/Rector/LNumber/DowngradeNumericLiteralSeparatorRector.php @@ -5,8 +5,8 @@ namespace Rector\DowngradePhp74\Rector\LNumber; use PhpParser\Node; -use PhpParser\Node\Scalar\DNumber; -use PhpParser\Node\Scalar\LNumber; +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; @@ -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/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/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..6dd11357 100644 --- a/rules/DowngradePhp80/Rector/ArrayDimFetch/DowngradeDereferenceableOperationRector.php +++ b/rules/DowngradePhp80/Rector/ArrayDimFetch/DowngradeDereferenceableOperationRector.php @@ -7,7 +7,7 @@ use PhpParser\Node; use PhpParser\Node\Expr; use PhpParser\Node\Expr\ArrayDimFetch; -use PhpParser\Node\Scalar\Encapsed; +use PhpParser\Node\Scalar\InterpolatedString; 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); } @@ -98,7 +98,7 @@ private function hasParentheses(ArrayDimFetch $arrayDimFetch): bool continue; } - if ($oldTokens[$i] !== ')') { + if ((string) $oldTokens[$i] !== ')') { continue; } 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..503e36c7 100644 --- a/rules/DowngradePhp80/Rector/ClassMethod/DowngradeTrailingCommasInParamUseRector.php +++ b/rules/DowngradePhp80/Rector/ClassMethod/DowngradeTrailingCommasInParamUseRector.php @@ -5,8 +5,8 @@ namespace Rector\DowngradePhp80\Rector\ClassMethod; use PhpParser\Node; +use PhpParser\Node\ClosureUse; 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_/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 { diff --git a/rules/DowngradePhp80/Rector/Class_/DowngradePropertyPromotionRector.php b/rules/DowngradePhp80/Rector/Class_/DowngradePropertyPromotionRector.php index 23f98993..c4013099 100644 --- a/rules/DowngradePhp80/Rector/Class_/DowngradePropertyPromotionRector.php +++ b/rules/DowngradePhp80/Rector/Class_/DowngradePropertyPromotionRector.php @@ -9,11 +9,11 @@ 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; 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/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); diff --git a/rules/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector.php b/rules/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector.php index 9fe7b01e..205f138a 100644 --- a/rules/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector.php +++ b/rules/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector.php @@ -6,7 +6,7 @@ use PhpParser\Node; use PhpParser\Node\Arg; -use PhpParser\Node\Expr\ArrayItem; +use PhpParser\Node\ArrayItem; use PhpParser\Node\Expr\ArrowFunction; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\CallLike; @@ -25,7 +25,7 @@ use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\Return_; use PhpParser\Node\Stmt\Switch_; -use PhpParser\NodeTraverser; +use PhpParser\NodeVisitor; 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; } } ); 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 :) diff --git a/rules/DowngradePhp80/Rector/FuncCall/DowngradeArrayFilterNullableCallbackRector.php b/rules/DowngradePhp80/Rector/FuncCall/DowngradeArrayFilterNullableCallbackRector.php index b015bbd1..ac510f59 100644 --- a/rules/DowngradePhp80/Rector/FuncCall/DowngradeArrayFilterNullableCallbackRector.php +++ b/rules/DowngradePhp80/Rector/FuncCall/DowngradeArrayFilterNullableCallbackRector.php @@ -20,7 +20,7 @@ use PhpParser\Node\Identifier; use PhpParser\Node\Name; use PhpParser\Node\Param; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; use PhpParser\Node\Scalar\String_; use PHPStan\Type\ArrayType; use PHPStan\Type\ClosureType; @@ -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; @@ -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..40cdad18 100644 --- a/rules/DowngradePhp80/Rector/FuncCall/DowngradeStrEndsWithRector.php +++ b/rules/DowngradePhp80/Rector/FuncCall/DowngradeStrEndsWithRector.php @@ -13,7 +13,7 @@ use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\UnaryMinus; use PhpParser\Node\Name; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; 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..6dbd2e19 100644 --- a/rules/DowngradePhp80/Rector/FuncCall/DowngradeStrStartsWithRector.php +++ b/rules/DowngradePhp80/Rector/FuncCall/DowngradeStrStartsWithRector.php @@ -11,7 +11,7 @@ use PhpParser\Node\Expr\BooleanNot; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Name; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; 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..ebb09f5e 100644 --- a/rules/DowngradePhp80/Rector/MethodCall/DowngradeReflectionClassGetConstantsFilterRector.php +++ b/rules/DowngradePhp80/Rector/MethodCall/DowngradeReflectionClassGetConstantsFilterRector.php @@ -5,13 +5,13 @@ namespace Rector\DowngradePhp80\Rector\MethodCall; use PhpParser\Node; +use PhpParser\Node\ClosureUse; use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\ArrayDimFetch; use PhpParser\Node\Expr\Assign; 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/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 8432a820..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]); @@ -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; } } @@ -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/DowngradePhp80/Rector/Property/DowngradeUnionTypeTypedPropertyRector.php b/rules/DowngradePhp80/Rector/Property/DowngradeUnionTypeTypedPropertyRector.php index b5a08cbe..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 === 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..512f11fb 100644 --- a/rules/DowngradePhp80/Rector/StaticCall/DowngradePhpTokenRector.php +++ b/rules/DowngradePhp80/Rector/StaticCall/DowngradePhpTokenRector.php @@ -13,7 +13,7 @@ use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Expr\Ternary; use PhpParser\Node\Name; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; 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/DowngradePhp80/Reflection/DefaultParameterValueResolver.php b/rules/DowngradePhp80/Reflection/DefaultParameterValueResolver.php index 1a6f6361..a61b349b 100644 --- a/rules/DowngradePhp80/Reflection/DefaultParameterValueResolver.php +++ b/rules/DowngradePhp80/Reflection/DefaultParameterValueResolver.php @@ -11,7 +11,9 @@ use PHPStan\Reflection\ParameterReflection; use PHPStan\Type\Constant\ConstantArrayType; use PHPStan\Type\Constant\ConstantBooleanType; -use PHPStan\Type\ConstantType; +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; @@ -25,14 +27,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); @@ -41,7 +43,7 @@ private function resolveValueFromType(ConstantType $constantType): ConstFetch | if ($constantType instanceof ConstantArrayType) { $values = []; foreach ($constantType->getValueTypes() as $valueType) { - if (! $valueType instanceof ConstantType) { + if (! $valueType->isConstantValue()->yes()) { throw new ShouldNotHappenException(); } @@ -51,6 +53,7 @@ private function resolveValueFromType(ConstantType $constantType): ConstFetch | return BuilderHelpers::normalizeValue($values); } + /** @var ConstantStringType|ConstantIntegerType|NullType $constantType */ return BuilderHelpers::normalizeValue($constantType->getValue()); } 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..ce10386a 100644 --- a/rules/DowngradePhp81/NodeFactory/ArrayMergeFromArraySpreadFactory.php +++ b/rules/DowngradePhp81/NodeFactory/ArrayMergeFromArraySpreadFactory.php @@ -4,16 +4,14 @@ namespace Rector\DowngradePhp81\NodeFactory; -use PhpParser\Node; use PhpParser\Node\Arg; +use PhpParser\Node\ArrayItem; 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; use PhpParser\Node\Name; use PHPStan\Analyser\MutatingScope; -use PHPStan\Type\ArrayType; use PHPStan\Type\IterableType; use PHPStan\Type\ObjectType; use PHPStan\Type\Type; @@ -28,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); @@ -85,14 +83,14 @@ 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); } /** - * @param array $items + * @param array $items */ private function createArrayItemFromArray(array $items): ArrayItem { @@ -121,13 +119,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 +134,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 f6c590c9..c362f8a2 100644 --- a/rules/DowngradePhp81/Rector/Array_/DowngradeArraySpreadStringKeyRector.php +++ b/rules/DowngradePhp81/Rector/Array_/DowngradeArraySpreadStringKeyRector.php @@ -5,10 +5,11 @@ namespace Rector\DowngradePhp81\Rector\Array_; use PhpParser\Node; +use PhpParser\Node\ArrayItem; use PhpParser\Node\Expr\Array_; -use PhpParser\Node\Expr\ArrayItem; 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; @@ -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; diff --git a/rules/DowngradePhp81/Rector/FuncCall/DowngradeFirstClassCallableSyntaxRector.php b/rules/DowngradePhp81/Rector/FuncCall/DowngradeFirstClassCallableSyntaxRector.php index 76bc0dbd..e33471e5 100644 --- a/rules/DowngradePhp81/Rector/FuncCall/DowngradeFirstClassCallableSyntaxRector.php +++ b/rules/DowngradePhp81/Rector/FuncCall/DowngradeFirstClassCallableSyntaxRector.php @@ -6,9 +6,9 @@ use PhpParser\Node; use PhpParser\Node\Arg; +use PhpParser\Node\ArrayItem; 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..7b3ddfbb 100644 --- a/rules/DowngradePhp81/Rector/LNumber/DowngradeOctalNumberRector.php +++ b/rules/DowngradePhp81/Rector/LNumber/DowngradeOctalNumberRector.php @@ -5,7 +5,7 @@ namespace Rector\DowngradePhp81\Rector\LNumber; use PhpParser\Node; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; 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..d88576fd 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; } 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); }