Skip to content

Commit

Permalink
extract DoctrineClass enum
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Aug 15, 2024
1 parent ea1077c commit bf7589e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
13 changes: 13 additions & 0 deletions rules/CodeQuality/Enum/DoctrineClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Rector\Doctrine\CodeQuality\Enum;

final readonly class DoctrineClass
{
/**
* @var string
*/
public const COLLECTION = 'Doctrine\Common\Collections\Collection';
}
10 changes: 3 additions & 7 deletions rules/CodeQuality/SetterCollectionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use PHPStan\Type\UnionType;
use Rector\Doctrine\CodeQuality\Enum\DoctrineClass;
use Rector\Doctrine\TypeAnalyzer\CollectionTypeFactory;
use Rector\Doctrine\TypeAnalyzer\CollectionVarTagValueNodeResolver;
use Rector\NodeManipulator\AssignManipulator;
Expand All @@ -24,11 +25,6 @@

final readonly class SetterCollectionResolver
{
/**
* @var string
*/
private const COLLECTION_CLASS = 'Doctrine\Common\Collections\Collection';

public function __construct(
private AssignManipulator $assignManipulator,
private ReflectionResolver $reflectionResolver,
Expand Down Expand Up @@ -98,10 +94,10 @@ public function resolveAssignedGenericCollectionType(Class_ $class, ClassMethod

private function isCollectionType(Type $type): bool
{
if ($type instanceof ShortenedObjectType && $type->getFullyQualifiedName() === self::COLLECTION_CLASS) {
if ($type instanceof ShortenedObjectType && $type->getFullyQualifiedName() === DoctrineClass::COLLECTION) {
return true;
}

return $type instanceof ObjectType && $type->getClassName() === self::COLLECTION_CLASS;
return $type instanceof ObjectType && $type->getClassName() === DoctrineClass::COLLECTION;
}
}
8 changes: 2 additions & 6 deletions src/NodeManipulator/ToManyRelationPropertyTypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Rector\BetterPhpDocParser\PhpDoc\StringNode;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Doctrine\CodeQuality\Enum\CollectionMapping;
use Rector\Doctrine\CodeQuality\Enum\DoctrineClass;
use Rector\Doctrine\CodeQuality\Enum\EntityMappingKey;
use Rector\Doctrine\CodeQuality\Enum\OdmMappingKey;
use Rector\Doctrine\NodeAnalyzer\AttributeFinder;
Expand All @@ -23,11 +24,6 @@

final readonly class ToManyRelationPropertyTypeResolver
{
/**
* @var string
*/
private const COLLECTION_TYPE = 'Doctrine\Common\Collections\Collection';

public function __construct(
private PhpDocInfoFactory $phpDocInfoFactory,
private ShortClassExpander $shortClassExpander,
Expand Down Expand Up @@ -90,7 +86,7 @@ private function resolveTypeFromTargetEntity(Expr|string $targetEntity, Property
}

if (! is_string($targetEntity)) {
return new FullyQualifiedObjectType(self::COLLECTION_TYPE);
return new FullyQualifiedObjectType(DoctrineClass::COLLECTION);
}

$entityFullyQualifiedClass = $this->shortClassExpander->resolveFqnTargetEntity($targetEntity, $property);
Expand Down

0 comments on commit bf7589e

Please sign in to comment.