From 8c04f656b32d8d95a5139e59cbfbc508647dd3b1 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 5 Aug 2023 23:26:30 +0700 Subject: [PATCH] [TypeDeclaration] Skip public method on AddMethodCallBasedStrictParamTypeRector (#4659) * [TypeDeclaration] Skip public method on AddMethodCallBasedStrictParamTypeRector * rename * [ci-review] Rector Rectify * [ci-review] Rector Rectify --------- Co-authored-by: GitHub Action --- .../Fixture/skip_public_method.php.inc | 26 +++++++++++++++++++ ...ddMethodCallBasedStrictParamTypeRector.php | 5 +++- 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/AddMethodCallBasedStrictParamTypeRector/Fixture/skip_public_method.php.inc diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/AddMethodCallBasedStrictParamTypeRector/Fixture/skip_public_method.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/AddMethodCallBasedStrictParamTypeRector/Fixture/skip_public_method.php.inc new file mode 100644 index 00000000000..613637e0388 --- /dev/null +++ b/rules-tests/TypeDeclaration/Rector/ClassMethod/AddMethodCallBasedStrictParamTypeRector/Fixture/skip_public_method.php.inc @@ -0,0 +1,26 @@ +toArray(true); + } + + public function __toString() + { + return implode(', ', $this->toArray()); + } + + final public function toArray($cols = false) + { + if ((! is_bool($cols)) && (! is_array($cols))) { + throw new Exception('Invalid value cols'); + } + } + +} diff --git a/rules/TypeDeclaration/Rector/ClassMethod/AddMethodCallBasedStrictParamTypeRector.php b/rules/TypeDeclaration/Rector/ClassMethod/AddMethodCallBasedStrictParamTypeRector.php index 528cae1e569..f97c4638375 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/AddMethodCallBasedStrictParamTypeRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/AddMethodCallBasedStrictParamTypeRector.php @@ -100,11 +100,14 @@ public function refactor(Node $node): ?Node && $node->implements === [] ) || $method->isPrivate(); - if (! $isPrivate) { continue; } + if ($method->isPublic()) { + continue; + } + $methodCalls = $this->localMethodCallFinder->match($node, $method); $classMethodParameterTypes = $this->callTypesResolver->resolveStrictTypesFromCalls($methodCalls);