From 293b3563bccfb7174e6afb9093e98d392a801aef Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 14 May 2024 20:37:44 +0700 Subject: [PATCH 1/3] [TypeDeclaration] Skip possible array on StrictStringParamConcatRector --- .../Fixture/skip_possible_array.php.inc | 13 +++++++++++++ .../StrictStringParamConcatRector.php | 18 ++++++++++++------ 2 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/StrictStringParamConcatRector/Fixture/skip_possible_array.php.inc diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/StrictStringParamConcatRector/Fixture/skip_possible_array.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/StrictStringParamConcatRector/Fixture/skip_possible_array.php.inc new file mode 100644 index 00000000000..d77736a6b58 --- /dev/null +++ b/rules-tests/TypeDeclaration/Rector/ClassMethod/StrictStringParamConcatRector/Fixture/skip_possible_array.php.inc @@ -0,0 +1,13 @@ +nodeTypeResolver->getNativeType($variableConcattedFromParam); + if (! $nativeType instanceof MixedType) { + continue; + } - if ($nativeType instanceof MixedType && $nativeType->getSubtractedType() instanceof Type && TypeCombinator::containsNull( - $nativeType->getSubtractedType() - )) { - $param->type = new NullableType(new Identifier('string')); - } else { + $subtractedType = $nativeType->getSubtractedType(); + if (! $subtractedType instanceof Type) { $param->type = new Identifier('string'); + $hasChanged = true; + + continue; } - $hasChanged = true; + if ($nativeType instanceof MixedType && TypeCombinator::containsNull($subtractedType)) { + $param->type = new NullableType(new Identifier('string')); + $hasChanged = true; + } } if ($hasChanged) { From b7167f1790b6ff46e21e8d11dde878d6d29f13ab Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Tue, 14 May 2024 13:39:25 +0000 Subject: [PATCH 2/3] [ci-review] Rector Rectify --- .../Rector/ClassMethod/StrictStringParamConcatRector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules/TypeDeclaration/Rector/ClassMethod/StrictStringParamConcatRector.php b/rules/TypeDeclaration/Rector/ClassMethod/StrictStringParamConcatRector.php index 96d0425e63a..5a9794b127b 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/StrictStringParamConcatRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/StrictStringParamConcatRector.php @@ -113,7 +113,7 @@ public function refactor(Node $node): ?Node continue; } - if ($nativeType instanceof MixedType && TypeCombinator::containsNull($subtractedType)) { + if (TypeCombinator::containsNull($subtractedType)) { $param->type = new NullableType(new Identifier('string')); $hasChanged = true; } From 152ff6c4d985d58a9b1bb388773ee4cc8841e3c8 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 14 May 2024 20:44:02 +0700 Subject: [PATCH 3/3] more test --- .../Fixture/skip_possible_array2.php.inc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/StrictStringParamConcatRector/Fixture/skip_possible_array2.php.inc diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/StrictStringParamConcatRector/Fixture/skip_possible_array2.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/StrictStringParamConcatRector/Fixture/skip_possible_array2.php.inc new file mode 100644 index 00000000000..de261efb24b --- /dev/null +++ b/rules-tests/TypeDeclaration/Rector/ClassMethod/StrictStringParamConcatRector/Fixture/skip_possible_array2.php.inc @@ -0,0 +1,15 @@ +