Skip to content

Commit

Permalink
[TypeDeclaration] Add NativeMethodReflection support on ReturnStrictT…
Browse files Browse the repository at this point in the history
…ypeAnalyzer (#6344)

* [TypeDeclaration] Add NativeMethodReflection support on ReturnStrictTypeAnalyzer

* [TypeDeclaration] Add NativeMethodReflection support on ReturnStrictTypeAnalyzer
  • Loading branch information
samsonasik authored Oct 1, 2024
1 parent d17d3e8 commit 0c9edeb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedCallRector\Fixture;

use DateTime;

final class DateTimeFormatReturn
{
function aa(DateTime $dateTime)
{
return $dateTime->format('Y-m-d');
}
}

?>
-----
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedCallRector\Fixture;

use DateTime;

final class DateTimeFormatReturn
{
function aa(DateTime $dateTime): string
{
return $dateTime->format('Y-m-d');
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0c9edeb

Please sign in to comment.