From aa7e3f5893c4dc91e1135255e02910467924fb2f Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 1 Oct 2024 20:47:53 +0700 Subject: [PATCH 1/2] [TypeDeclaration] Add NativeMethodReflection support on ReturnStrictTypeAnalyzer --- .../TypeDeclaration/TypeAnalyzer/ReturnStrictTypeAnalyzer.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rules/TypeDeclaration/TypeAnalyzer/ReturnStrictTypeAnalyzer.php b/rules/TypeDeclaration/TypeAnalyzer/ReturnStrictTypeAnalyzer.php index 37e912c64c..a46be2bb2b 100644 --- a/rules/TypeDeclaration/TypeAnalyzer/ReturnStrictTypeAnalyzer.php +++ b/rules/TypeDeclaration/TypeAnalyzer/ReturnStrictTypeAnalyzer.php @@ -22,6 +22,7 @@ use PHPStan\Analyser\Scope; use PHPStan\Reflection\ClassReflection; use PHPStan\Reflection\Native\NativeFunctionReflection; +use PHPStan\Reflection\Native\NativeMethodReflection; use PHPStan\Reflection\ParametersAcceptorWithPhpDocs; use PHPStan\Type\MixedType; use PHPStan\Type\StaticType; @@ -122,7 +123,7 @@ public function resolveMethodCallReturnType(MethodCall | StaticCall | FuncCall $ $scope ); - if ($methodReflection instanceof NativeFunctionReflection) { + if ($methodReflection instanceof NativeFunctionReflection || $methodReflection instanceof NativeMethodReflection) { $returnType = $parametersAcceptorWithPhpDocs->getReturnType(); } elseif ($parametersAcceptorWithPhpDocs instanceof ParametersAcceptorWithPhpDocs) { // native return type is needed, as docblock can be false From f44bb9875f8a0b0fa7c4cfc4e51b3e0ae4cd0071 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 1 Oct 2024 20:47:57 +0700 Subject: [PATCH 2/2] [TypeDeclaration] Add NativeMethodReflection support on ReturnStrictTypeAnalyzer --- .../datetime_format_return.php.inc | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/FixturePhp80/datetime_format_return.php.inc diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/FixturePhp80/datetime_format_return.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/FixturePhp80/datetime_format_return.php.inc new file mode 100644 index 0000000000..97d4274bdf --- /dev/null +++ b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/FixturePhp80/datetime_format_return.php.inc @@ -0,0 +1,31 @@ +format('Y-m-d'); + } +} + +?> +----- +format('Y-m-d'); + } +} + +?>