Skip to content

Commit

Permalink
[fix] Skip doc-types in ReturnStrictTypeAnalyzer (#2562)
Browse files Browse the repository at this point in the history
* add breaking fixture

* [fix] Skip doc-types in ReturnStrictTypeAnalyzer
  • Loading branch information
TomasVotruba committed Jun 25, 2022
1 parent 24d2250 commit 564c127
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

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

final class SkipFalseReportType
{
public function isBoolean()
{
return $this->fakedTypes();
}

/**
* @return bool
*/
private function fakedTypes()
{
return 100;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use PhpParser\Node\Name;
use PhpParser\Node\NullableType;
use PhpParser\Node\Stmt\Return_;
use PHPStan\Reflection\FunctionVariantWithPhpDocs;
use PHPStan\Type\MixedType;
use Rector\Core\Reflection\ReflectionResolver;
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
Expand Down Expand Up @@ -65,7 +66,13 @@ private function resolveMethodCallReturnNode(MethodCall | StaticCall | FuncCall
}

$parametersAcceptor = $methodReflection->getVariants()[0];
$returnType = $parametersAcceptor->getReturnType();
if ($parametersAcceptor instanceof FunctionVariantWithPhpDocs) {
// native return type is needed, as docblock can be false
$returnType = $parametersAcceptor->getNativeReturnType();
} else {
$returnType = $parametersAcceptor->getReturnType();
}

if ($returnType instanceof MixedType) {
return null;
}
Expand Down

0 comments on commit 564c127

Please sign in to comment.