mirror of
https://github.com/rectorphp/rector.git
synced 2025-03-14 12:29:43 +01:00
remove getReturtType()
This commit is contained in:
parent
452f2e3643
commit
e5b36d999c
@ -175,17 +175,6 @@ final class DocBlockManipulator
|
||||
$this->replaceTagByAnother($phpDocInfo->getPhpDocNode(), $oldAnnotation, $newAnnotation);
|
||||
}
|
||||
|
||||
public function getReturnType(Node $node): Type
|
||||
{
|
||||
/** @var PhpDocInfo|null $phpDocInfo */
|
||||
$phpDocInfo = $node->getAttribute(AttributeKey::PHP_DOC_INFO);
|
||||
if ($phpDocInfo === null) {
|
||||
return new MixedType();
|
||||
}
|
||||
|
||||
return $phpDocInfo->getReturnType();
|
||||
}
|
||||
|
||||
/**
|
||||
* With "name" as key
|
||||
*
|
||||
@ -267,7 +256,10 @@ final class DocBlockManipulator
|
||||
|
||||
public function addReturnTag(Node $node, Type $newType): void
|
||||
{
|
||||
$currentReturnType = $this->getReturnType($node);
|
||||
/** @var PhpDocInfo|null $phpDocInfo */
|
||||
$phpDocInfo = $node->getAttribute(AttributeKey::PHP_DOC_INFO);
|
||||
|
||||
$currentReturnType = $phpDocInfo !== null ? $phpDocInfo->getReturnType() : new MixedType();
|
||||
|
||||
// make sure the tags are not identical, e.g imported class vs FQN class
|
||||
if ($this->typeComparator->areTypesEquals($currentReturnType, $newType)) {
|
||||
|
@ -12,8 +12,8 @@ use PhpParser\Node\Stmt\Return_;
|
||||
use PhpParser\NodeTraverser;
|
||||
use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\Type;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\NodeTypeResolver\PhpDoc\NodeAnalyzer\DocBlockManipulator;
|
||||
use Rector\PhpParser\Node\Manipulator\PropertyFetchManipulator;
|
||||
use Rector\TypeDeclaration\Contract\TypeInferer\ParamTypeInfererInterface;
|
||||
use Rector\TypeDeclaration\TypeInferer\AbstractTypeInferer;
|
||||
@ -25,17 +25,9 @@ final class GetterNodeParamTypeInferer extends AbstractTypeInferer implements Pa
|
||||
*/
|
||||
private $propertyFetchManipulator;
|
||||
|
||||
/**
|
||||
* @var DocBlockManipulator
|
||||
*/
|
||||
private $docBlockManipulator;
|
||||
|
||||
public function __construct(
|
||||
PropertyFetchManipulator $propertyFetchManipulator,
|
||||
DocBlockManipulator $docBlockManipulator
|
||||
) {
|
||||
public function __construct(PropertyFetchManipulator $propertyFetchManipulator)
|
||||
{
|
||||
$this->propertyFetchManipulator = $propertyFetchManipulator;
|
||||
$this->docBlockManipulator = $docBlockManipulator;
|
||||
}
|
||||
|
||||
public function inferParam(Param $param): Type
|
||||
@ -80,7 +72,13 @@ final class GetterNodeParamTypeInferer extends AbstractTypeInferer implements Pa
|
||||
return null;
|
||||
}
|
||||
|
||||
$methodReturnType = $this->docBlockManipulator->getReturnType($methodNode);
|
||||
/** @var PhpDocInfo|null $phpDocInfo */
|
||||
$phpDocInfo = $methodNode->getAttribute(AttributeKey::PHP_DOC_INFO);
|
||||
if ($phpDocInfo === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$methodReturnType = $phpDocInfo->getReturnType();
|
||||
if ($methodReturnType instanceof MixedType) {
|
||||
return null;
|
||||
}
|
||||
|
@ -8,29 +8,27 @@ use PhpParser\Node\Expr\Closure;
|
||||
use PhpParser\Node\FunctionLike;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\Type;
|
||||
use Rector\NodeTypeResolver\PhpDoc\NodeAnalyzer\DocBlockManipulator;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\TypeDeclaration\Contract\TypeInferer\ReturnTypeInfererInterface;
|
||||
use Rector\TypeDeclaration\TypeInferer\AbstractTypeInferer;
|
||||
|
||||
final class ReturnTagReturnTypeInferer extends AbstractTypeInferer implements ReturnTypeInfererInterface
|
||||
{
|
||||
/**
|
||||
* @var DocBlockManipulator
|
||||
*/
|
||||
private $docBlockManipulator;
|
||||
|
||||
public function __construct(DocBlockManipulator $docBlockManipulator)
|
||||
{
|
||||
$this->docBlockManipulator = $docBlockManipulator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMethod|Closure|Function_ $functionLike
|
||||
*/
|
||||
public function inferFunctionLike(FunctionLike $functionLike): Type
|
||||
{
|
||||
return $this->docBlockManipulator->getReturnType($functionLike);
|
||||
/** @var PhpDocInfo|null $phpDocInfo */
|
||||
$phpDocInfo = $functionLike->getAttribute(AttributeKey::PHP_DOC_INFO);
|
||||
if ($phpDocInfo === null) {
|
||||
return new MixedType();
|
||||
}
|
||||
|
||||
return $phpDocInfo->getReturnType();
|
||||
}
|
||||
|
||||
public function getPriority(): int
|
||||
|
Loading…
x
Reference in New Issue
Block a user