mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-20 08:05:29 +01:00
add hasByType() method to PhpDocInfo (#2505)
add hasByType() method to PhpDocInfo
This commit is contained in:
commit
7a497d9cd4
@ -107,6 +107,6 @@ PHP
|
||||
return false;
|
||||
}
|
||||
|
||||
return (bool) $phpDocInfo->getByType(EntityTagValueNode::class);
|
||||
return $phpDocInfo->hasByType(EntityTagValueNode::class);
|
||||
}
|
||||
}
|
||||
|
@ -203,6 +203,11 @@ final class PhpDocInfo
|
||||
}
|
||||
}
|
||||
|
||||
public function hasByType(string $type): bool
|
||||
{
|
||||
return (bool) $this->getByType($type);
|
||||
}
|
||||
|
||||
public function getByType(string $type): ?PhpDocTagValueNode
|
||||
{
|
||||
$this->ensureTypeIsTagValueNode($type, __METHOD__);
|
||||
|
@ -146,7 +146,7 @@ final class DoctrineEntityManipulator
|
||||
}
|
||||
|
||||
$phpDocInfo = $this->docBlockManipulator->createPhpDocInfoFromNode($property);
|
||||
if ($phpDocInfo->getByType(DoctrineRelationTagValueNodeInterface::class) === null) {
|
||||
if (! $phpDocInfo->hasByType(DoctrineRelationTagValueNodeInterface::class)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ final class DoctrineDocBlockResolver
|
||||
return false;
|
||||
}
|
||||
|
||||
return (bool) $classPhpDocInfo->getByType(EntityTagValueNode::class);
|
||||
return $classPhpDocInfo->hasByType(EntityTagValueNode::class);
|
||||
}
|
||||
|
||||
if (is_string($class)) {
|
||||
@ -108,7 +108,7 @@ final class DoctrineDocBlockResolver
|
||||
return false;
|
||||
}
|
||||
|
||||
return (bool) $propertyPhpDocInfo->getByType(IdTagValueNode::class);
|
||||
return $propertyPhpDocInfo->hasByType(IdTagValueNode::class);
|
||||
}
|
||||
|
||||
public function getDoctrineRelationTagValueNode(Property $property): ?DoctrineRelationTagValueNodeInterface
|
||||
@ -128,11 +128,11 @@ final class DoctrineDocBlockResolver
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($propertyPhpDocInfo->getByType(ColumnTagValueNode::class) !== null) {
|
||||
if ($propertyPhpDocInfo->hasByType(ColumnTagValueNode::class)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return (bool) $propertyPhpDocInfo->getByType(DoctrineRelationTagValueNodeInterface::class);
|
||||
return $propertyPhpDocInfo->hasByType(DoctrineRelationTagValueNodeInterface::class);
|
||||
}
|
||||
|
||||
public function isInDoctrineEntityClass(Node $node): bool
|
||||
|
@ -114,8 +114,7 @@ final class EntityWithMissingUuidProvider
|
||||
{
|
||||
$propertyPhpDocInfo = $this->phpDocInfoFactory->createFromNode($property);
|
||||
|
||||
$idTagValueNode = $propertyPhpDocInfo->getByType(IdTagValueNode::class);
|
||||
if ($idTagValueNode === null) {
|
||||
if (! $propertyPhpDocInfo->hasByType(IdTagValueNode::class)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,8 @@ final class AddUuidAnnotationsToIdPropertyRector extends AbstractRector
|
||||
|
||||
/** @var PhpDocInfo $phpDocInfo */
|
||||
$phpDocInfo = $this->getPhpDocInfo($node);
|
||||
$this->removeGeneratedValueTag($phpDocInfo);
|
||||
|
||||
$phpDocInfo->removeByType(GeneratedValueTagValueNode::class);
|
||||
$this->changeColumnTypeToUuidBinary($phpDocInfo);
|
||||
$this->changeSerializerTypeToString($phpDocInfo);
|
||||
|
||||
@ -67,16 +68,6 @@ final class AddUuidAnnotationsToIdPropertyRector extends AbstractRector
|
||||
$this->docBlockManipulator->changeVarTag($property, $uuidObjectType);
|
||||
}
|
||||
|
||||
private function removeGeneratedValueTag(PhpDocInfo $phpDocInfo): void
|
||||
{
|
||||
$generatedTagValueNode = $phpDocInfo->getByType(GeneratedValueTagValueNode::class);
|
||||
if ($generatedTagValueNode === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$phpDocInfo->removeTagValueNodeFromNode($generatedTagValueNode);
|
||||
}
|
||||
|
||||
private function changeColumnTypeToUuidBinary(PhpDocInfo $phpDocInfo): void
|
||||
{
|
||||
$columnTagValueNode = $phpDocInfo->getByType(ColumnTagValueNode::class);
|
||||
|
@ -44,7 +44,7 @@ final class RemoveTemporaryUuidColumnPropertyRector extends AbstractRector
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($phpDocInfo->getByType(ColumnTagValueNode::class) === null) {
|
||||
if (! $phpDocInfo->hasByType(ColumnTagValueNode::class)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ final class RemoveTemporaryUuidRelationPropertyRector extends AbstractRector
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($phpDocInfo->getByType(DoctrineRelationTagValueNodeInterface::class) === null) {
|
||||
if (! $phpDocInfo->hasByType(DoctrineRelationTagValueNodeInterface::class)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -95,7 +95,7 @@ PHP
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($classPhpDocInfo->getByType(EntityTagValueNode::class) === null) {
|
||||
if (! $classPhpDocInfo->hasByType(EntityTagValueNode::class)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -128,7 +128,7 @@ PHP
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($propertyPhpDocInfo->getByType(ToManyTagNodeInterface::class) === null) {
|
||||
if (! $propertyPhpDocInfo->hasByType(ToManyTagNodeInterface::class)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -209,12 +209,12 @@ PHP
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($propertyPhpDocInfo->getByType(LocaleTagValueNode::class)) {
|
||||
if ($propertyPhpDocInfo->hasByType(LocaleTagValueNode::class)) {
|
||||
$this->removeNode($property);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! $propertyPhpDocInfo->getByType(TranslatableTagValueNode::class)) {
|
||||
if (! $propertyPhpDocInfo->hasByType(TranslatableTagValueNode::class)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -139,13 +139,12 @@ PHP
|
||||
return null;
|
||||
}
|
||||
|
||||
$treeTagValueNode = $classPhpDocInfo->getByType(TreeTagValueNode::class);
|
||||
if ($treeTagValueNode === null) {
|
||||
if (! $classPhpDocInfo->hasByType(TreeTagValueNode::class)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// we're in a tree entity
|
||||
$classPhpDocInfo->removeTagValueNodeFromNode($treeTagValueNode);
|
||||
$classPhpDocInfo->removeByType(TreeTagValueNode::class);
|
||||
$this->docBlockManipulator->updateNodeWithPhpDocInfo($node, $classPhpDocInfo);
|
||||
|
||||
$node->implements[] = new FullyQualified('Knp\DoctrineBehaviors\Contract\Entity\TreeNodeInterface');
|
||||
@ -191,23 +190,23 @@ PHP
|
||||
|
||||
private function shouldRemoveProperty(PhpDocInfo $phpDocInfo): bool
|
||||
{
|
||||
if ($phpDocInfo->getByType(TreeLeftTagValueNode::class)) {
|
||||
if ($phpDocInfo->hasByType(TreeLeftTagValueNode::class)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($phpDocInfo->getByType(TreeRightTagValueNode::class)) {
|
||||
if ($phpDocInfo->hasByType(TreeRightTagValueNode::class)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($phpDocInfo->getByType(TreeRootTagValueNode::class)) {
|
||||
if ($phpDocInfo->hasByType(TreeRootTagValueNode::class)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($phpDocInfo->getByType(TreeParentTagValueNode::class)) {
|
||||
if ($phpDocInfo->hasByType(TreeParentTagValueNode::class)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($phpDocInfo->getByType(TreeLevelTagValueNode::class)) {
|
||||
if ($phpDocInfo->hasByType(TreeLevelTagValueNode::class)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -334,7 +334,7 @@ PHP
|
||||
return false;
|
||||
}
|
||||
|
||||
return (bool) $phpDocInfo->getByType(SymfonyRouteTagValueNode::class);
|
||||
return $phpDocInfo->hasByType(SymfonyRouteTagValueNode::class);
|
||||
}
|
||||
|
||||
private function resolvePathFromClassAndMethodNodes(Class_ $classNode, ClassMethod $classMethod): string
|
||||
|
@ -125,7 +125,7 @@ final class DocBlockManipulator
|
||||
// advanced check, e.g. for "Namespaced\Annotations\DI"
|
||||
$phpDocInfo = $this->createPhpDocInfoFromNode($node);
|
||||
|
||||
return (bool) $phpDocInfo->getByType($name);
|
||||
return $phpDocInfo->hasByType($name);
|
||||
}
|
||||
|
||||
public function addTag(Node $node, PhpDocChildNode $phpDocChildNode): void
|
||||
@ -323,10 +323,7 @@ final class DocBlockManipulator
|
||||
|
||||
// A. remove class-based tag
|
||||
if (class_exists($tagName)) {
|
||||
$phpDocTagNode = $phpDocInfo->getByType($tagName);
|
||||
if ($phpDocTagNode) {
|
||||
$this->removeTagFromPhpDocNode($phpDocNode, $phpDocTagNode);
|
||||
}
|
||||
$phpDocInfo->removeByType($tagName);
|
||||
}
|
||||
|
||||
// B. remove string-based tags
|
||||
|
@ -119,7 +119,7 @@ PHP
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((bool) $phpDocInfo->getByType(SensioTemplateTagValueNode::class)) {
|
||||
if ($phpDocInfo->hasByType(SensioTemplateTagValueNode::class)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -215,8 +215,7 @@ PHP
|
||||
|
||||
private function removeVarAnnotation(Node $node, PhpDocInfo $phpDocInfo): void
|
||||
{
|
||||
$varTagValueNode = $phpDocInfo->getByType(VarTagValueNode::class);
|
||||
$phpDocInfo->removeTagValueNodeFromNode($varTagValueNode);
|
||||
$phpDocInfo->removeByType(VarTagValueNode::class);
|
||||
|
||||
$this->docBlockManipulator->updateNodeWithPhpDocInfo($node, $phpDocInfo);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user