mirror of
https://github.com/rectorphp/rector.git
synced 2024-07-22 17:30:23 +00:00
cleanup
This commit is contained in:
parent
408f5372dd
commit
4dcdf4c890
@ -15,6 +15,7 @@ use Rector\BetterPhpDocParser\Attributes\Ast\PhpDoc\AttributeAwarePhpDocNode;
|
||||
use Rector\BetterPhpDocParser\Attributes\Ast\PhpDoc\AttributeAwareReturnTagValueNode;
|
||||
use Rector\BetterPhpDocParser\Attributes\Ast\PhpDoc\AttributeAwareVarTagValueNode;
|
||||
use Rector\BetterPhpDocParser\Attributes\Contract\Ast\AttributeAwareNodeInterface;
|
||||
use Rector\Exception\ShouldNotHappenException;
|
||||
use Rector\NodeTypeResolver\StaticTypeMapper;
|
||||
|
||||
/**
|
||||
@ -189,6 +190,8 @@ final class PhpDocInfo
|
||||
|
||||
public function getByType(string $type): ?PhpDocTagValueNode
|
||||
{
|
||||
$this->ensureTypeIsTagValueNode($type, __METHOD__);
|
||||
|
||||
foreach ($this->phpDocNode->children as $phpDocChildNode) {
|
||||
if ($phpDocChildNode instanceof PhpDocTagNode) {
|
||||
if (is_a($phpDocChildNode->value, $type, true)) {
|
||||
@ -213,4 +216,18 @@ final class PhpDocInfo
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function ensureTypeIsTagValueNode(string $type, string $location): void
|
||||
{
|
||||
if (is_a($type, PhpDocTagValueNode::class, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
throw new ShouldNotHappenException(sprintf(
|
||||
'Type "%s" passed to "%s()" method must be child of "%s"',
|
||||
$type,
|
||||
$location,
|
||||
PhpDocTagValueNode::class
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,9 @@
|
||||
|
||||
namespace Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc;
|
||||
|
||||
interface DoctrineRelationTagValueNodeInterface
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
|
||||
|
||||
interface DoctrineRelationTagValueNodeInterface extends PhpDocTagValueNode
|
||||
{
|
||||
public function getTargetEntity(): ?string;
|
||||
|
||||
|
@ -57,7 +57,9 @@ final class PropertyTypeDeclarationRector extends AbstractRector
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($this->docBlockManipulator->hasTag($node, '@var')) {
|
||||
// is already set
|
||||
$currentVarType = $this->docBlockManipulator->getVarType($node);
|
||||
if (! $currentVarType instanceof MixedType) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -165,7 +165,7 @@ CODE_SAMPLE
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! $this->docBlockManipulator->hasTag($property, 'var')) {
|
||||
if (! $this->docBlockManipulator->getVarType()) {
|
||||
$this->docBlockManipulator->changeVarTag($property, $type);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user