Fix PHPStan @return class-string<T>.

This commit is contained in:
Dorian Villet 2020-01-08 22:40:52 +01:00
parent 9ae98079ff
commit 44278b4957
2 changed files with 20 additions and 0 deletions

View File

@ -10,6 +10,7 @@ use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_;
use PHPStan\Type\ArrayType;
use PHPStan\Type\Generic\GenericObjectType;
use PHPStan\Type\IntersectionType;
use PHPStan\Type\IterableType;
use PHPStan\Type\MixedType;
@ -208,6 +209,11 @@ PHP
return true;
}
// is class-string<T> type? → skip
if ($returnType instanceof GenericObjectType && $returnType->getClassName() === 'class-string') {
return true;
}
// prevent overriding self with itself
if ($this->print($node->returnType) === 'self') {
$className = $node->getAttribute(AttributeKey::CLASS_NAME);

View File

@ -0,0 +1,14 @@
<?php
namespace Rector\TypeDeclaration\Tests\Rector\ClassMethod\ReturnTypeDeclarationRector\Fixture;
/**
* @template T
*/
abstract class TestClassStringType
{
/**
* @return class-string<T>
*/
abstract protected function getClassStringForT(): string;
}