diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictNewArrayRector/Fixture/new_array_replace.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictNewArrayRector/Fixture/new_array_replace.php.inc new file mode 100644 index 00000000000..83f9f1df9d1 --- /dev/null +++ b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictNewArrayRector/Fixture/new_array_replace.php.inc @@ -0,0 +1,56 @@ +getFilePaths('/' . $identifier . '_' . $size . '.jpg/'); + } else { + $imagePaths = $this->getFilePaths('/' . $identifier . '.jpg/'); + } + + return $imagePaths; + } + + private function getFilePaths(): array + { + return []; + } +} + +?> +----- +getFilePaths('/' . $identifier . '_' . $size . '.jpg/'); + } else { + $imagePaths = $this->getFilePaths('/' . $identifier . '.jpg/'); + } + + return $imagePaths; + } + + private function getFilePaths(): array + { + return []; + } +} + +?> diff --git a/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictNewArrayRector.php b/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictNewArrayRector.php index e01dafe504e..8c4196e0082 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictNewArrayRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictNewArrayRector.php @@ -192,7 +192,12 @@ private function isVariableOverriddenWithNonArray( continue; } - if (! $assign->expr instanceof Array_) { + if ($assign->expr instanceof Array_) { + continue; + } + + $nativeType = $this->nodeTypeResolver->getNativeType($assign->expr); + if (! $nativeType->isArray()->yes()) { return true; } }