mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-18 05:48:21 +01:00
decouple php doc ast node to factories
This commit is contained in:
parent
ab10145d77
commit
598f228c6d
@ -55,7 +55,6 @@
|
||||
"Rector\\ConsoleDiffer\\": "packages/ConsoleDiffer/src",
|
||||
"Rector\\DeadCode\\": "packages/DeadCode/src",
|
||||
"Rector\\Doctrine\\": "packages/Doctrine/src",
|
||||
"Rector\\DoctrinePhpDocParser\\": "packages/DoctrinePhpDocParser/src",
|
||||
"Rector\\ElasticSearchDSL\\": "packages/ElasticSearchDSL/src",
|
||||
"Rector\\FileSystemRector\\": "packages/FileSystemRector/src",
|
||||
"Rector\\Guzzle\\": "packages/Guzzle/src",
|
||||
@ -112,7 +111,6 @@
|
||||
"Rector\\CodingStyle\\Tests\\": "packages/CodingStyle/tests",
|
||||
"Rector\\DeadCode\\Tests\\": "packages/DeadCode/tests",
|
||||
"Rector\\Doctrine\\Tests\\": "packages/Doctrine/tests",
|
||||
"Rector\\DoctrinePhpDocParser\\Tests\\": "packages/DoctrinePhpDocParser/tests",
|
||||
"Rector\\ElasticSearchDSL\\Tests\\": "packages/ElasticSearchDSL/tests",
|
||||
"Rector\\Guzzle\\Tests\\": "packages/Guzzle/tests",
|
||||
"Rector\\Laravel\\Tests\\": "packages/Laravel/tests",
|
||||
|
3
ecs.yaml
3
ecs.yaml
@ -116,7 +116,6 @@ parameters:
|
||||
|
||||
Symplify\CodingStandard\Sniffs\CleanCode\CognitiveComplexitySniff:
|
||||
- 'packages/Doctrine/src/Rector/ClassMethod/AddMethodCallBasedParamTypeRector.php'
|
||||
- 'packages/DoctrinePhpDocParser/src/PhpDocParser/OrmTagParser.php'
|
||||
- 'packages/TypeDeclaration/src/TypeInferer/ReturnTypeInferer/ReturnedNodesReturnTypeInferer.php'
|
||||
- 'packages/NodeTypeResolver/src/NodeTypeResolver.php'
|
||||
- 'packages/NodeTypeResolver/src/PerNodeTypeResolver/VariableTypeResolver.php'
|
||||
@ -124,7 +123,7 @@ parameters:
|
||||
- 'packages/SOLID/src/Analyzer/ClassConstantFetchAnalyzer.php'
|
||||
# tough logic
|
||||
- 'packages/PHPUnit/src/Rector/Class_/ArrayArgumentInTestToDataProviderRector.php'
|
||||
- 'packages/DoctrinePhpDocParser/src/Ast/PhpDoc/*/*TagValueNode.php'
|
||||
- 'packages/BetterPhpDocParser/src/Ast/PhpDoc/*/*TagValueNode.php'
|
||||
- 'packages/NodeTypeResolver/src/PhpDoc/NodeAnalyzer/FqnNamePhpDocNodeDecorator.php'
|
||||
- 'packages/NodeTypeResolver/src/PHPStan/Type/StaticTypeAnalyzer.php'
|
||||
- 'src/NodeContainer/ParsedNodesByType.php'
|
||||
|
@ -5,7 +5,7 @@ namespace Rector\Architecture\Rector\Class_;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use Rector\Architecture\Tests\Rector\Class_\RemoveRepositoryFromEntityAnnotationRector\RemoveRepositoryFromEntityAnnotationRectorTest;
|
||||
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\Class_\EntityTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Class_\EntityTagValueNode;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Rector\RectorDefinition\CodeSample;
|
||||
use Rector\RectorDefinition\RectorDefinition;
|
||||
|
@ -6,7 +6,7 @@ use Nette\Utils\Strings;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use Rector\Autodiscovery\FileMover\FileMover;
|
||||
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\Class_\EntityTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Class_\EntityTagValueNode;
|
||||
use Rector\FileSystemRector\Rector\AbstractFileSystemRector;
|
||||
use Rector\RectorDefinition\CodeSample;
|
||||
use Rector\RectorDefinition\RectorDefinition;
|
||||
|
@ -5,7 +5,7 @@ services:
|
||||
|
||||
Rector\BetterPhpDocParser\:
|
||||
resource: '../src'
|
||||
exclude: '../src/{HttpKernel,ValueObject/*,*/*Info.php,*Info.php,Attributes/Ast/PhpDoc/*,Ast/PhpDoc/*}'
|
||||
exclude: '../src/{HttpKernel,ValueObject/*,*/*Info.php,*Info.php,Attributes/Ast/PhpDoc/*,Ast/PhpDoc/*,PhpDocNode/*}'
|
||||
|
||||
PHPStan\PhpDocParser\Lexer\Lexer: ~
|
||||
PHPStan\PhpDocParser\Parser\TypeParser: ~
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\DoctrinePhpDocParser\AnnotationReader;
|
||||
namespace Rector\BetterPhpDocParser\AnnotationReader;
|
||||
|
||||
use Doctrine\Common\Annotations\AnnotationReader;
|
||||
use Doctrine\Common\Annotations\AnnotationRegistry;
|
||||
@ -17,10 +17,22 @@ final class AnnotationReaderFactory
|
||||
// don't forget to add it to "stubs/Doctrine/Empty" directory, because the class needs to exists
|
||||
// and run "composer dump-autoload", because the directory is loaded by classmap
|
||||
$annotationReader::addGlobalIgnoredName('ORM\GeneratedValue');
|
||||
$annotationReader::addGlobalIgnoredName('GeneratedValue');
|
||||
|
||||
$annotationReader::addGlobalIgnoredName('ORM\InheritanceType');
|
||||
$annotationReader::addGlobalIgnoredName('InheritanceType');
|
||||
|
||||
$annotationReader::addGlobalIgnoredName('ORM\OrderBy');
|
||||
$annotationReader::addGlobalIgnoredName('OrderBy');
|
||||
|
||||
$annotationReader::addGlobalIgnoredName('ORM\DiscriminatorMap');
|
||||
$annotationReader::addGlobalIgnoredName('DiscriminatorMap');
|
||||
|
||||
$annotationReader::addGlobalIgnoredName('ORM\UniqueEntity');
|
||||
$annotationReader::addGlobalIgnoredName('UniqueEntity');
|
||||
|
||||
$annotationReader::addGlobalIgnoredName('Gedmo\SoftDeleteable');
|
||||
$annotationReader::addGlobalIgnoredName('SoftDeleteable');
|
||||
|
||||
// warning: nested tags must be parse-able, e.g. @ORM\Table must include @ORM\UniqueConstraint!
|
||||
|
@ -1,13 +1,13 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\DoctrinePhpDocParser\AnnotationReader;
|
||||
namespace Rector\BetterPhpDocParser\AnnotationReader;
|
||||
|
||||
use Doctrine\Common\Annotations\AnnotationException;
|
||||
use Doctrine\Common\Annotations\AnnotationReader;
|
||||
use Doctrine\ORM\Mapping\Annotation;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use Rector\Exception\ShouldNotHappenException;
|
||||
use Rector\NodeTypeResolver\ClassExistenceStaticHelper;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\PhpParser\Node\Resolver\NameResolver;
|
||||
@ -51,20 +51,19 @@ final class NodeAnnotationReader
|
||||
|
||||
$reflectionMethod = new ReflectionMethod($className, $methodName);
|
||||
|
||||
return $this->annotationReader->getMethodAnnotation($reflectionMethod, $annotationClassName);
|
||||
try {
|
||||
return $this->annotationReader->getMethodAnnotation($reflectionMethod, $annotationClassName);
|
||||
} catch (AnnotationException $annotationException) {
|
||||
// unable to laod
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function readClassAnnotation(Class_ $class, string $annotationClassName): Annotation
|
||||
public function readClassAnnotation(Class_ $class, string $annotationClassName): ?Annotation
|
||||
{
|
||||
$classReflection = $this->createClassReflectionFromNode($class);
|
||||
|
||||
/** @var Annotation|null $classAnnotation */
|
||||
$classAnnotation = $this->annotationReader->getClassAnnotation($classReflection, $annotationClassName);
|
||||
if ($classAnnotation === null) {
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
|
||||
return $classAnnotation;
|
||||
return $this->annotationReader->getClassAnnotation($classReflection, $annotationClassName);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -80,7 +79,7 @@ final class NodeAnnotationReader
|
||||
/** @var Annotation|null $propertyAnnotation */
|
||||
$propertyAnnotation = $this->annotationReader->getPropertyAnnotation($propertyReflection, $annotationClassName);
|
||||
if ($propertyAnnotation === null) {
|
||||
throw new ShouldNotHappenException();
|
||||
return null;
|
||||
}
|
||||
|
||||
return $propertyAnnotation;
|
||||
@ -91,15 +90,12 @@ final class NodeAnnotationReader
|
||||
/** @var string $propertyName */
|
||||
$propertyName = $this->nameResolver->getName($property);
|
||||
|
||||
/** @var string $className */
|
||||
/** @var string|null $className */
|
||||
$className = $property->getAttribute(AttributeKey::CLASS_NAME);
|
||||
|
||||
if ($className === null || ! ClassExistenceStaticHelper::doesClassLikeExist($className)) {
|
||||
throw new ShouldNotHappenException(sprintf(
|
||||
'Class "%s" for property "%s" was not found.',
|
||||
(string) $className,
|
||||
$propertyName
|
||||
));
|
||||
// probably fresh node
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
@ -1,6 +1,6 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc;
|
||||
namespace Rector\BetterPhpDocParser\Contract\Doctrine;
|
||||
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc;
|
||||
namespace Rector\BetterPhpDocParser\Contract\Doctrine;
|
||||
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc;
|
||||
namespace Rector\BetterPhpDocParser\Contract\Doctrine;
|
||||
|
||||
interface InversedByNodeInterface
|
||||
{
|
@ -1,6 +1,6 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc;
|
||||
namespace Rector\BetterPhpDocParser\Contract\Doctrine;
|
||||
|
||||
interface MappedByNodeInterface
|
||||
{
|
@ -0,0 +1,8 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\BetterPhpDocParser\Contract\Doctrine;
|
||||
|
||||
interface OriginalTagAwareInterface
|
||||
{
|
||||
public function getOriginalTag(): ?string;
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc;
|
||||
namespace Rector\BetterPhpDocParser\Contract\Doctrine;
|
||||
|
||||
interface ToManyTagNodeInterface extends DoctrineRelationTagValueNodeInterface
|
||||
{
|
@ -1,6 +1,6 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc;
|
||||
namespace Rector\BetterPhpDocParser\Contract\Doctrine;
|
||||
|
||||
interface ToOneTagNodeInterface extends DoctrineRelationTagValueNodeInterface
|
||||
{
|
@ -0,0 +1,14 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\BetterPhpDocParser\Contract;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
|
||||
use PHPStan\PhpDocParser\Parser\TokenIterator;
|
||||
|
||||
interface PhpDocNodeFactoryInterface
|
||||
{
|
||||
public function getName(): string;
|
||||
|
||||
public function createFromNodeAndTokens(Node $node, TokenIterator $tokenIterator): ?PhpDocTagValueNode;
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\BetterPhpDocParser\Contract;
|
||||
|
||||
use PHPStan\PhpDocParser\Parser\PhpDocParser;
|
||||
|
||||
interface PhpDocParserAwareInterface
|
||||
{
|
||||
public function setPhpDocParser(PhpDocParser $phpDocParser): void;
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\BetterPhpDocParser\Extension;
|
||||
|
||||
use Nette\Utils\Strings;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
|
||||
use PHPStan\PhpDocParser\Parser\TokenIterator;
|
||||
use Rector\BetterPhpDocParser\Contract\PhpDocParserExtensionInterface;
|
||||
use Rector\BetterPhpDocParser\PhpDocParser\InjectPhpDocParser;
|
||||
|
||||
final class JMSPhpDocParserExtension implements PhpDocParserExtensionInterface
|
||||
{
|
||||
/**
|
||||
* @var InjectPhpDocParser
|
||||
*/
|
||||
private $injectPhpDocParser;
|
||||
|
||||
public function __construct(InjectPhpDocParser $injectPhpDocParser)
|
||||
{
|
||||
$this->injectPhpDocParser = $injectPhpDocParser;
|
||||
}
|
||||
|
||||
public function matchTag(string $tag): bool
|
||||
{
|
||||
if ($tag === '@Inject') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return (bool) Strings::match($tag, '#^@DI\\\\(\w+)$#');
|
||||
}
|
||||
|
||||
public function parse(TokenIterator $tokenIterator, string $tag): ?PhpDocTagValueNode
|
||||
{
|
||||
return $this->injectPhpDocParser->parse($tokenIterator, $tag);
|
||||
}
|
||||
}
|
@ -9,8 +9,8 @@ use PHPStan\PhpDocParser\Parser\TokenIterator;
|
||||
use Rector\BetterPhpDocParser\Attributes\Ast\PhpDoc\AttributeAwarePhpDocNode;
|
||||
use Rector\BetterPhpDocParser\Attributes\Attribute\Attribute;
|
||||
use Rector\BetterPhpDocParser\Attributes\Contract\Ast\AttributeAwareNodeInterface;
|
||||
use Rector\BetterPhpDocParser\PhpDocParser\OrmTagParser;
|
||||
use Rector\Configuration\CurrentNodeProvider;
|
||||
use Rector\DoctrinePhpDocParser\PhpDocParser\OrmTagParser;
|
||||
use Rector\Exception\ShouldNotHappenException;
|
||||
use Rector\NodeTypeResolver\StaticTypeMapper;
|
||||
|
||||
|
@ -1,10 +1,11 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\DoctrinePhpDocParser\Ast\PhpDoc\Class_;
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Class_;
|
||||
|
||||
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\AbstractDoctrineTagValueNode;
|
||||
use Rector\BetterPhpDocParser\Contract\Doctrine\OriginalTagAwareInterface;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\AbstractDoctrineTagValueNode;
|
||||
|
||||
abstract class AbstractIndexTagValueNode extends AbstractDoctrineTagValueNode
|
||||
abstract class AbstractIndexTagValueNode extends AbstractDoctrineTagValueNode implements OriginalTagAwareInterface
|
||||
{
|
||||
/**
|
||||
* @var string|null
|
||||
@ -26,6 +27,11 @@ abstract class AbstractIndexTagValueNode extends AbstractDoctrineTagValueNode
|
||||
*/
|
||||
private $options;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $originalTag;
|
||||
|
||||
/**
|
||||
* @param mixed[]|null $columns
|
||||
* @param mixed[]|null $flags
|
||||
@ -36,7 +42,8 @@ abstract class AbstractIndexTagValueNode extends AbstractDoctrineTagValueNode
|
||||
?array $columns,
|
||||
?array $flags,
|
||||
?array $options,
|
||||
?string $originalContent = null
|
||||
?string $originalContent = null,
|
||||
?string $originalTag = null
|
||||
) {
|
||||
$this->name = $name;
|
||||
$this->flags = $flags;
|
||||
@ -46,6 +53,7 @@ abstract class AbstractIndexTagValueNode extends AbstractDoctrineTagValueNode
|
||||
if ($originalContent !== null) {
|
||||
$this->resolveOriginalContentSpacingAndOrder($originalContent);
|
||||
}
|
||||
$this->originalTag = $originalTag;
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
@ -70,4 +78,9 @@ abstract class AbstractIndexTagValueNode extends AbstractDoctrineTagValueNode
|
||||
|
||||
return $this->printContentItems($contentItems);
|
||||
}
|
||||
|
||||
public function getOriginalTag(): ?string
|
||||
{
|
||||
return $this->originalTag;
|
||||
}
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\DoctrinePhpDocParser\Ast\PhpDoc\Class_;
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Class_;
|
||||
|
||||
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\AbstractDoctrineTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\AbstractDoctrineTagValueNode;
|
||||
|
||||
final class EntityTagValueNode extends AbstractDoctrineTagValueNode
|
||||
{
|
@ -1,6 +1,6 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\DoctrinePhpDocParser\Ast\PhpDoc\Class_;
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Class_;
|
||||
|
||||
final class IndexTagValueNode extends AbstractIndexTagValueNode
|
||||
{
|
@ -1,8 +1,8 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\DoctrinePhpDocParser\Ast\PhpDoc\Class_;
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Class_;
|
||||
|
||||
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\AbstractDoctrineTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\AbstractDoctrineTagValueNode;
|
||||
|
||||
final class InheritanceTypeTagValueNode extends AbstractDoctrineTagValueNode
|
||||
{
|
@ -1,8 +1,8 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\DoctrinePhpDocParser\Ast\PhpDoc\Class_;
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Class_;
|
||||
|
||||
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\AbstractDoctrineTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\AbstractDoctrineTagValueNode;
|
||||
|
||||
final class TableTagValueNode extends AbstractDoctrineTagValueNode
|
||||
{
|
@ -1,6 +1,6 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\DoctrinePhpDocParser\Ast\PhpDoc\Class_;
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Class_;
|
||||
|
||||
final class UniqueConstraintTagValueNode extends AbstractIndexTagValueNode
|
||||
{
|
@ -1,8 +1,8 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\DoctrinePhpDocParser\Ast\PhpDoc\Property_;
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Property_;
|
||||
|
||||
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\AbstractDoctrineTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\AbstractDoctrineTagValueNode;
|
||||
|
||||
final class ColumnTagValueNode extends AbstractDoctrineTagValueNode
|
||||
{
|
@ -1,8 +1,8 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\DoctrinePhpDocParser\Ast\PhpDoc\Property_;
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Property_;
|
||||
|
||||
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\AbstractDoctrineTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\AbstractDoctrineTagValueNode;
|
||||
|
||||
final class CustomIdGeneratorTagValueNode extends AbstractDoctrineTagValueNode
|
||||
{
|
@ -1,8 +1,8 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\DoctrinePhpDocParser\Ast\PhpDoc\Property_;
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Property_;
|
||||
|
||||
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\AbstractDoctrineTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\AbstractDoctrineTagValueNode;
|
||||
|
||||
final class GeneratedValueTagValueNode extends AbstractDoctrineTagValueNode
|
||||
{
|
@ -1,8 +1,8 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\DoctrinePhpDocParser\Ast\PhpDoc\Property_;
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Property_;
|
||||
|
||||
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\AbstractDoctrineTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\AbstractDoctrineTagValueNode;
|
||||
|
||||
final class IdTagValueNode extends AbstractDoctrineTagValueNode
|
||||
{
|
@ -1,8 +1,8 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\DoctrinePhpDocParser\Ast\PhpDoc\Property_;
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Property_;
|
||||
|
||||
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\AbstractDoctrineTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\AbstractDoctrineTagValueNode;
|
||||
|
||||
final class JoinColumnTagValueNode extends AbstractDoctrineTagValueNode
|
||||
{
|
@ -1,8 +1,8 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\DoctrinePhpDocParser\Ast\PhpDoc\Property_;
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Property_;
|
||||
|
||||
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\AbstractDoctrineTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\AbstractDoctrineTagValueNode;
|
||||
|
||||
final class JoinTableTagValueNode extends AbstractDoctrineTagValueNode
|
||||
{
|
@ -1,11 +1,11 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\DoctrinePhpDocParser\Ast\PhpDoc\Property_;
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Property_;
|
||||
|
||||
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\AbstractDoctrineTagValueNode;
|
||||
use Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc\InversedByNodeInterface;
|
||||
use Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc\MappedByNodeInterface;
|
||||
use Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc\ToManyTagNodeInterface;
|
||||
use Rector\BetterPhpDocParser\Contract\Doctrine\InversedByNodeInterface;
|
||||
use Rector\BetterPhpDocParser\Contract\Doctrine\MappedByNodeInterface;
|
||||
use Rector\BetterPhpDocParser\Contract\Doctrine\ToManyTagNodeInterface;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\AbstractDoctrineTagValueNode;
|
||||
|
||||
final class ManyToManyTagValueNode extends AbstractDoctrineTagValueNode implements ToManyTagNodeInterface, MappedByNodeInterface, InversedByNodeInterface
|
||||
{
|
@ -1,10 +1,10 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\DoctrinePhpDocParser\Ast\PhpDoc\Property_;
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Property_;
|
||||
|
||||
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\AbstractDoctrineTagValueNode;
|
||||
use Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc\InversedByNodeInterface;
|
||||
use Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc\ToOneTagNodeInterface;
|
||||
use Rector\BetterPhpDocParser\Contract\Doctrine\InversedByNodeInterface;
|
||||
use Rector\BetterPhpDocParser\Contract\Doctrine\ToOneTagNodeInterface;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\AbstractDoctrineTagValueNode;
|
||||
|
||||
final class ManyToOneTagValueNode extends AbstractDoctrineTagValueNode implements ToOneTagNodeInterface, InversedByNodeInterface
|
||||
{
|
@ -1,10 +1,10 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\DoctrinePhpDocParser\Ast\PhpDoc\Property_;
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Property_;
|
||||
|
||||
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\AbstractDoctrineTagValueNode;
|
||||
use Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc\MappedByNodeInterface;
|
||||
use Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc\ToManyTagNodeInterface;
|
||||
use Rector\BetterPhpDocParser\Contract\Doctrine\MappedByNodeInterface;
|
||||
use Rector\BetterPhpDocParser\Contract\Doctrine\ToManyTagNodeInterface;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\AbstractDoctrineTagValueNode;
|
||||
|
||||
final class OneToManyTagValueNode extends AbstractDoctrineTagValueNode implements ToManyTagNodeInterface, MappedByNodeInterface
|
||||
{
|
@ -1,11 +1,11 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\DoctrinePhpDocParser\Ast\PhpDoc\Property_;
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Property_;
|
||||
|
||||
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\AbstractDoctrineTagValueNode;
|
||||
use Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc\InversedByNodeInterface;
|
||||
use Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc\MappedByNodeInterface;
|
||||
use Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc\ToOneTagNodeInterface;
|
||||
use Rector\BetterPhpDocParser\Contract\Doctrine\InversedByNodeInterface;
|
||||
use Rector\BetterPhpDocParser\Contract\Doctrine\MappedByNodeInterface;
|
||||
use Rector\BetterPhpDocParser\Contract\Doctrine\ToOneTagNodeInterface;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\AbstractDoctrineTagValueNode;
|
||||
|
||||
final class OneToOneTagValueNode extends AbstractDoctrineTagValueNode implements ToOneTagNodeInterface, MappedByNodeInterface, InversedByNodeInterface
|
||||
{
|
@ -1,6 +1,6 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\BetterPhpDocParser\Ast\PhpDoc\JMS;
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNode\JMS;
|
||||
|
||||
use JMS\DiExtraBundle\Annotation\Inject;
|
||||
use Rector\BetterPhpDocParser\PhpDocParser\Ast\PhpDoc\AbstractTagValueNode;
|
@ -1,6 +1,6 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\Symfony\PhpDocParser\Ast\PhpDoc;
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNode\JMS;
|
||||
|
||||
use JMS\Serializer\Annotation\Type;
|
||||
use Nette\Utils\Strings;
|
@ -1,6 +1,6 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\BetterPhpDocParser\Ast\PhpDoc\PHPDI;
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNode\PHPDI;
|
||||
|
||||
use DI\Annotation\Inject;
|
||||
use Rector\BetterPhpDocParser\PhpDocParser\Ast\PhpDoc\AbstractTagValueNode;
|
@ -1,11 +1,11 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\NetteToSymfony\PhpDocParser\Ast\PhpDoc;
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNode\Sensio;
|
||||
|
||||
use Rector\BetterPhpDocParser\PhpDocParser\Ast\PhpDoc\AbstractTagValueNode;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
|
||||
|
||||
final class SymfonyMethodTagValueNode extends AbstractTagValueNode
|
||||
final class SensioMethodTagValueNode extends AbstractTagValueNode
|
||||
{
|
||||
/**
|
||||
* @var string
|
@ -1,15 +1,12 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\Sensio\PhpDocParser\Ast\PhpDoc;
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNode\Sensio;
|
||||
|
||||
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
|
||||
use Rector\BetterPhpDocParser\PhpDocParser\Ast\PhpDoc\AbstractTagValueNode;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
|
||||
|
||||
final class TemplateTagValueNode extends AbstractTagValueNode
|
||||
final class SensioTemplateTagValueNode extends AbstractTagValueNode
|
||||
{
|
||||
use AttributeTrait;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
@ -1,6 +1,6 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\NetteToSymfony\PhpDocParser\Ast\PhpDoc;
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNode\Symfony;
|
||||
|
||||
use Rector\BetterPhpDocParser\PhpDocParser\Ast\PhpDoc\AbstractTagValueNode;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
@ -1,7 +1,8 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\Symfony\PhpDocParser\Ast\PhpDoc;
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNode\Symfony\Validator\Constraints;
|
||||
|
||||
use Rector\Symfony\PhpDocParser\Ast\PhpDoc\AbstractConstraintTagValueNode;
|
||||
use Symfony\Component\Validator\Constraints\Choice;
|
||||
|
||||
final class AssertChoiceTagValueNode extends AbstractConstraintTagValueNode
|
@ -1,7 +1,8 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\Symfony\PhpDocParser\Ast\PhpDoc;
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNode\Symfony\Validator\Constraints;
|
||||
|
||||
use Rector\Symfony\PhpDocParser\Ast\PhpDoc\AbstractConstraintTagValueNode;
|
||||
use Symfony\Component\Validator\Constraints\Type;
|
||||
|
||||
final class AssertTypeTagValueNode extends AbstractConstraintTagValueNode
|
@ -0,0 +1,54 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNodeFactory;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PHPStan\PhpDocParser\Parser\TokenIterator;
|
||||
use Rector\BetterPhpDocParser\AnnotationReader\NodeAnnotationReader;
|
||||
use Rector\BetterPhpDocParser\Contract\PhpDocNodeFactoryInterface;
|
||||
use Rector\BetterPhpDocParser\PhpDocParser\AnnotationContentResolver;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
|
||||
abstract class AbstractPhpDocNodeFactory implements PhpDocNodeFactoryInterface
|
||||
{
|
||||
/**
|
||||
* @var NodeAnnotationReader
|
||||
*/
|
||||
protected $nodeAnnotationReader;
|
||||
|
||||
/**
|
||||
* @var AnnotationContentResolver
|
||||
*/
|
||||
private $annotationContentResolver;
|
||||
|
||||
/**
|
||||
* @required
|
||||
*/
|
||||
public function autowireAbstractPhpDocNodeFactory(
|
||||
NodeAnnotationReader $nodeAnnotationReader,
|
||||
AnnotationContentResolver $annotationContentResolver
|
||||
): void {
|
||||
$this->nodeAnnotationReader = $nodeAnnotationReader;
|
||||
$this->annotationContentResolver = $annotationContentResolver;
|
||||
}
|
||||
|
||||
protected function resolveContentFromTokenIterator(TokenIterator $tokenIterator): string
|
||||
{
|
||||
return $this->annotationContentResolver->resolveFromTokenIterator($tokenIterator);
|
||||
}
|
||||
|
||||
protected function resolveFqnTargetEntity(string $targetEntity, Node $node): string
|
||||
{
|
||||
if (class_exists($targetEntity)) {
|
||||
return $targetEntity;
|
||||
}
|
||||
|
||||
$namespacedTargetEntity = $node->getAttribute(AttributeKey::NAMESPACE_NAME) . '\\' . $targetEntity;
|
||||
if (class_exists($namespacedTargetEntity)) {
|
||||
return $namespacedTargetEntity;
|
||||
}
|
||||
|
||||
// probably tested class
|
||||
return $targetEntity;
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNodeFactory\Doctrine\Class_;
|
||||
|
||||
use Doctrine\ORM\Mapping\Entity;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
|
||||
use PHPStan\PhpDocParser\Parser\TokenIterator;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Class_\EntityTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNodeFactory\AbstractPhpDocNodeFactory;
|
||||
use Rector\Exception\ShouldNotHappenException;
|
||||
|
||||
final class EntityPhpDocNodeFactory extends AbstractPhpDocNodeFactory
|
||||
{
|
||||
public function getName(): string
|
||||
{
|
||||
return EntityTagValueNode::SHORT_NAME;
|
||||
}
|
||||
|
||||
public function createFromNodeAndTokens(Node $node, TokenIterator $tokenIterator): ?PhpDocTagValueNode
|
||||
{
|
||||
if (! $node instanceof Class_) {
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
|
||||
/** @var Entity|null $entity */
|
||||
$entity = $this->nodeAnnotationReader->readClassAnnotation($node, Entity::class);
|
||||
if ($entity === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$annotationContent = $this->resolveContentFromTokenIterator($tokenIterator);
|
||||
|
||||
return new EntityTagValueNode($entity->repositoryClass, $entity->readOnly, $annotationContent);
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNodeFactory\Doctrine\Class_;
|
||||
|
||||
use Doctrine\ORM\Mapping\Index;
|
||||
use Nette\Utils\Strings;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Class_\IndexTagValueNode;
|
||||
|
||||
final class IndexPhpDocNodeFactory
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const INDEX_PATTERN = '#@ORM\\\\Index\((?<singleIndex>.*?)\),?#si';
|
||||
|
||||
/**
|
||||
* @param mixed[]|null $indexes
|
||||
* @return IndexTagValueNode[]
|
||||
*/
|
||||
public function createIndexTagValueNodes(?array $indexes, string $annotationContent): array
|
||||
{
|
||||
if ($indexes === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$indexContents = Strings::matchAll($annotationContent, self::INDEX_PATTERN);
|
||||
|
||||
$indexTagValueNodes = [];
|
||||
foreach ($indexes as $key => $index) {
|
||||
$indexTagValueNodes[] = $this->createFromAnnotationAndContent(
|
||||
$index,
|
||||
$indexContents[$key]['singleIndex']
|
||||
);
|
||||
}
|
||||
|
||||
return $indexTagValueNodes;
|
||||
}
|
||||
|
||||
private function createFromAnnotationAndContent(Index $index, string $annotationContent): IndexTagValueNode
|
||||
{
|
||||
// doctrine/orm compatibility between different versions
|
||||
$flags = property_exists($index, 'flags') ? $index->flags : [];
|
||||
|
||||
return new IndexTagValueNode($index->name, $index->columns, $flags, $index->options, $annotationContent);
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNodeFactory\Doctrine\Class_;
|
||||
|
||||
use Doctrine\ORM\Mapping\InheritanceType;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
|
||||
use PHPStan\PhpDocParser\Parser\TokenIterator;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Class_\InheritanceTypeTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNodeFactory\AbstractPhpDocNodeFactory;
|
||||
use Rector\Exception\ShouldNotHappenException;
|
||||
|
||||
final class InheritanceTypePhpDocNodeFactory extends AbstractPhpDocNodeFactory
|
||||
{
|
||||
public function getName(): string
|
||||
{
|
||||
return InheritanceTypeTagValueNode::SHORT_NAME;
|
||||
}
|
||||
|
||||
public function createFromNodeAndTokens(Node $node, TokenIterator $tokenIterator): ?PhpDocTagValueNode
|
||||
{
|
||||
if (! $node instanceof Class_) {
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
|
||||
/** @var InheritanceType|null $inheritanceType */
|
||||
$inheritanceType = $this->nodeAnnotationReader->readClassAnnotation($node, InheritanceType::class);
|
||||
if ($inheritanceType === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new InheritanceTypeTagValueNode($inheritanceType->value);
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNodeFactory\Doctrine\Class_;
|
||||
|
||||
use Doctrine\ORM\Mapping\Table;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
|
||||
use PHPStan\PhpDocParser\Parser\TokenIterator;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Class_\TableTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNodeFactory\AbstractPhpDocNodeFactory;
|
||||
use Rector\Exception\ShouldNotHappenException;
|
||||
|
||||
final class TablePhpDocNodeFactory extends AbstractPhpDocNodeFactory
|
||||
{
|
||||
/**
|
||||
* @var IndexPhpDocNodeFactory
|
||||
*/
|
||||
private $indexPhpDocNodeFactory;
|
||||
|
||||
/**
|
||||
* @var UniqueConstraintPhpDocNodeFactory
|
||||
*/
|
||||
private $uniqueConstraintPhpDocNodeFactory;
|
||||
|
||||
public function __construct(
|
||||
IndexPhpDocNodeFactory $indexPhpDocNodeFactory,
|
||||
UniqueConstraintPhpDocNodeFactory $uniqueConstraintPhpDocNodeFactory
|
||||
) {
|
||||
$this->indexPhpDocNodeFactory = $indexPhpDocNodeFactory;
|
||||
$this->uniqueConstraintPhpDocNodeFactory = $uniqueConstraintPhpDocNodeFactory;
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return TableTagValueNode::SHORT_NAME;
|
||||
}
|
||||
|
||||
public function createFromNodeAndTokens(Node $node, TokenIterator $tokenIterator): ?PhpDocTagValueNode
|
||||
{
|
||||
if (! $node instanceof Class_) {
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
|
||||
/** @var Table|null $table */
|
||||
$table = $this->nodeAnnotationReader->readClassAnnotation($node, Table::class);
|
||||
if ($table === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$annotationContent = $this->resolveContentFromTokenIterator($tokenIterator);
|
||||
|
||||
$indexTagValueNodes = $this->indexPhpDocNodeFactory->createIndexTagValueNodes(
|
||||
$table->indexes,
|
||||
$annotationContent
|
||||
);
|
||||
|
||||
$uniqueConstraintTagValueNodes = $this->uniqueConstraintPhpDocNodeFactory->createUniqueConstraintTagValueNodes(
|
||||
$table->uniqueConstraints,
|
||||
$annotationContent
|
||||
);
|
||||
|
||||
return new TableTagValueNode(
|
||||
$table->name,
|
||||
$table->schema,
|
||||
$indexTagValueNodes,
|
||||
$uniqueConstraintTagValueNodes,
|
||||
$table->options,
|
||||
$annotationContent
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNodeFactory\Doctrine\Class_;
|
||||
|
||||
use Doctrine\ORM\Mapping\UniqueConstraint;
|
||||
use Nette\Utils\Strings;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Class_\UniqueConstraintTagValueNode;
|
||||
|
||||
final class UniqueConstraintPhpDocNodeFactory
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const UNIQUE_CONSTRAINT_PATTERN = '#@ORM\\\\UniqueConstraint\((?<singleUniqueConstraint>.*?)\),?#si';
|
||||
|
||||
/**
|
||||
* @return UniqueConstraintTagValueNode[]
|
||||
*/
|
||||
public function createUniqueConstraintTagValueNodes(?array $uniqueConstraints, string $annotationContent): array
|
||||
{
|
||||
if ($uniqueConstraints === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$uniqueConstraintContents = Strings::matchAll($annotationContent, self::UNIQUE_CONSTRAINT_PATTERN);
|
||||
|
||||
$uniqueConstraintTagValueNodes = [];
|
||||
foreach ($uniqueConstraints as $key => $uniqueConstraint) {
|
||||
$uniqueConstraintTagValueNodes[] = $this->createIndexOrUniqueConstantTagValueNode(
|
||||
$uniqueConstraint,
|
||||
$uniqueConstraintContents[$key]['singleUniqueConstraint']
|
||||
);
|
||||
}
|
||||
|
||||
return $uniqueConstraintTagValueNodes;
|
||||
}
|
||||
|
||||
private function createIndexOrUniqueConstantTagValueNode(
|
||||
UniqueConstraint $uniqueConstraint,
|
||||
string $annotationContent
|
||||
): UniqueConstraintTagValueNode {
|
||||
// doctrine/orm compatibility between different versions
|
||||
$flags = property_exists($uniqueConstraint, 'flags') ? $uniqueConstraint->flags : [];
|
||||
|
||||
return new UniqueConstraintTagValueNode(
|
||||
$uniqueConstraint->name,
|
||||
$uniqueConstraint->columns,
|
||||
$flags,
|
||||
$uniqueConstraint->options,
|
||||
$annotationContent
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNodeFactory\Doctrine\Property_;
|
||||
|
||||
use Doctrine\ORM\Mapping\Column;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
|
||||
use PHPStan\PhpDocParser\Parser\TokenIterator;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Property_\ColumnTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNodeFactory\AbstractPhpDocNodeFactory;
|
||||
use Rector\Exception\ShouldNotHappenException;
|
||||
|
||||
final class ColumnPhpDocNodeFactory extends AbstractPhpDocNodeFactory
|
||||
{
|
||||
public function getName(): string
|
||||
{
|
||||
return ColumnTagValueNode::SHORT_NAME;
|
||||
}
|
||||
|
||||
public function createFromNodeAndTokens(Node $node, TokenIterator $tokenIterator): ?PhpDocTagValueNode
|
||||
{
|
||||
if (! $node instanceof Property) {
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
|
||||
/** @var Column|null $column */
|
||||
$column = $this->nodeAnnotationReader->readPropertyAnnotation($node, Column::class);
|
||||
if ($column === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$annotationContent = $this->resolveContentFromTokenIterator($tokenIterator);
|
||||
|
||||
return new ColumnTagValueNode(
|
||||
$column->name,
|
||||
$column->type,
|
||||
$column->length,
|
||||
$column->precision,
|
||||
$column->scale,
|
||||
$column->unique,
|
||||
$column->nullable,
|
||||
$column->options,
|
||||
$column->columnDefinition,
|
||||
$annotationContent
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNodeFactory\Doctrine\Property_;
|
||||
|
||||
use Doctrine\ORM\Mapping\CustomIdGenerator;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
|
||||
use PHPStan\PhpDocParser\Parser\TokenIterator;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Property_\CustomIdGeneratorTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNodeFactory\AbstractPhpDocNodeFactory;
|
||||
use Rector\Exception\ShouldNotHappenException;
|
||||
|
||||
final class CustomIdGeneratorPhpDocNodeFactory extends AbstractPhpDocNodeFactory
|
||||
{
|
||||
public function getName(): string
|
||||
{
|
||||
return CustomIdGeneratorTagValueNode::SHORT_NAME;
|
||||
}
|
||||
|
||||
public function createFromNodeAndTokens(Node $node, TokenIterator $tokenIterator): ?PhpDocTagValueNode
|
||||
{
|
||||
if (! $node instanceof Property) {
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
|
||||
$annotationContent = $this->resolveContentFromTokenIterator($tokenIterator);
|
||||
|
||||
/** @var CustomIdGenerator|null $customIdGenerator */
|
||||
$customIdGenerator = $this->nodeAnnotationReader->readPropertyAnnotation($node, CustomIdGenerator::class);
|
||||
if ($customIdGenerator === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new CustomIdGeneratorTagValueNode($customIdGenerator->class, $annotationContent);
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNodeFactory\Doctrine\Property_;
|
||||
|
||||
use Doctrine\ORM\Mapping\GeneratedValue;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
|
||||
use PHPStan\PhpDocParser\Parser\TokenIterator;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Property_\GeneratedValueTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNodeFactory\AbstractPhpDocNodeFactory;
|
||||
use Rector\Exception\ShouldNotHappenException;
|
||||
|
||||
final class GeneratedValuePhpDocNodeFactory extends AbstractPhpDocNodeFactory
|
||||
{
|
||||
public function getName(): string
|
||||
{
|
||||
return GeneratedValueTagValueNode::SHORT_NAME;
|
||||
}
|
||||
|
||||
public function createFromNodeAndTokens(Node $node, TokenIterator $tokenIterator): ?PhpDocTagValueNode
|
||||
{
|
||||
if (! $node instanceof Property) {
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
|
||||
/** @var GeneratedValue|null $generatedValue */
|
||||
$generatedValue = $this->nodeAnnotationReader->readPropertyAnnotation($node, GeneratedValue::class);
|
||||
if ($generatedValue === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new GeneratedValueTagValueNode($generatedValue->strategy);
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNodeFactory\Doctrine\Property_;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
|
||||
use PHPStan\PhpDocParser\Parser\TokenIterator;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Property_\IdTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNodeFactory\AbstractPhpDocNodeFactory;
|
||||
|
||||
final class IdPhpDocNodeFactory extends AbstractPhpDocNodeFactory
|
||||
{
|
||||
public function getName(): string
|
||||
{
|
||||
return IdTagValueNode::SHORT_NAME;
|
||||
}
|
||||
|
||||
public function createFromNodeAndTokens(Node $node, TokenIterator $tokenIterator): ?PhpDocTagValueNode
|
||||
{
|
||||
return new IdTagValueNode();
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNodeFactory\Doctrine\Property_;
|
||||
|
||||
use Doctrine\ORM\Mapping\JoinColumn;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
|
||||
use PHPStan\PhpDocParser\Parser\TokenIterator;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Property_\JoinColumnTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNodeFactory\AbstractPhpDocNodeFactory;
|
||||
use Rector\Exception\ShouldNotHappenException;
|
||||
|
||||
final class JoinColumnPhpDocNodeFactory extends AbstractPhpDocNodeFactory
|
||||
{
|
||||
public function getName(): string
|
||||
{
|
||||
return JoinColumnTagValueNode::SHORT_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return JoinColumnTagValueNode|null
|
||||
*/
|
||||
public function createFromNodeAndTokens(Node $node, TokenIterator $tokenIterator): ?PhpDocTagValueNode
|
||||
{
|
||||
if (! $node instanceof Property) {
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
|
||||
/** @var JoinColumn|null $joinColumn */
|
||||
$joinColumn = $this->nodeAnnotationReader->readPropertyAnnotation($node, JoinColumn::class);
|
||||
if ($joinColumn === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$annotationContent = $this->resolveContentFromTokenIterator($tokenIterator);
|
||||
|
||||
return $this->createFromAnnotationAndAnnotationContent($joinColumn, $annotationContent);
|
||||
}
|
||||
|
||||
public function createFromAnnotationAndAnnotationContent(
|
||||
JoinColumn $joinColumn,
|
||||
string $annotationContent
|
||||
): JoinColumnTagValueNode {
|
||||
return new JoinColumnTagValueNode(
|
||||
$joinColumn->name,
|
||||
$joinColumn->referencedColumnName,
|
||||
$joinColumn->unique,
|
||||
$joinColumn->nullable,
|
||||
$joinColumn->onDelete,
|
||||
$joinColumn->columnDefinition,
|
||||
$joinColumn->fieldName,
|
||||
$annotationContent
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,102 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNodeFactory\Doctrine\Property_;
|
||||
|
||||
use Doctrine\ORM\Mapping\JoinTable;
|
||||
use Nette\Utils\Strings;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
|
||||
use PHPStan\PhpDocParser\Parser\TokenIterator;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Property_\JoinColumnTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Property_\JoinTableTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNodeFactory\AbstractPhpDocNodeFactory;
|
||||
use Rector\Exception\ShouldNotHappenException;
|
||||
|
||||
final class JoinTablePhpDocNodeFactory extends AbstractPhpDocNodeFactory
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const JOIN_COLUMN_PATTERN = '#@ORM\\\\JoinColumn\((?<singleJoinColumn>.*?)\),?#si';
|
||||
|
||||
/**
|
||||
* @var JoinColumnPhpDocNodeFactory
|
||||
*/
|
||||
private $joinColumnPhpDocNodeFactory;
|
||||
|
||||
public function __construct(JoinColumnPhpDocNodeFactory $joinColumnPhpDocNodeFactory)
|
||||
{
|
||||
$this->joinColumnPhpDocNodeFactory = $joinColumnPhpDocNodeFactory;
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return JoinTableTagValueNode::SHORT_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return JoinTableTagValueNode|null
|
||||
*/
|
||||
public function createFromNodeAndTokens(Node $node, TokenIterator $tokenIterator): ?PhpDocTagValueNode
|
||||
{
|
||||
if (! $node instanceof Property) {
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
|
||||
/** @var JoinTable|null $joinTable */
|
||||
$joinTable = $this->nodeAnnotationReader->readPropertyAnnotation($node, JoinTable::class);
|
||||
if ($joinTable === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$annotationContent = $this->resolveContentFromTokenIterator($tokenIterator);
|
||||
|
||||
$joinColumnValuesTags = $this->createJoinColumnTagValues($annotationContent, $joinTable, 'joinColumns');
|
||||
$inverseJoinColumnValuesTags = $this->createJoinColumnTagValues(
|
||||
$annotationContent,
|
||||
$joinTable,
|
||||
'inverseJoinColumns'
|
||||
);
|
||||
|
||||
return new JoinTableTagValueNode(
|
||||
$joinTable->name,
|
||||
$joinTable->schema,
|
||||
$joinColumnValuesTags,
|
||||
$inverseJoinColumnValuesTags,
|
||||
$annotationContent
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return JoinColumnTagValueNode[]
|
||||
*/
|
||||
private function createJoinColumnTagValues(string $annotationContent, JoinTable $joinTable, string $type): array
|
||||
{
|
||||
$joinColumnContents = $this->matchJoinColumnContents($annotationContent, $type);
|
||||
$joinColumnValuesTags = [];
|
||||
|
||||
foreach ($joinTable->joinColumns as $key => $joinColumn) {
|
||||
$currentJoinColumnContent = $joinColumnContents[$key]['singleJoinColumn'];
|
||||
$joinColumnValuesTags[] = $this->joinColumnPhpDocNodeFactory->createFromAnnotationAndAnnotationContent(
|
||||
$joinColumn,
|
||||
$currentJoinColumnContent
|
||||
);
|
||||
}
|
||||
|
||||
return $joinColumnValuesTags;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[][]
|
||||
*/
|
||||
private function matchJoinColumnContents(string $annotationContent, string $type): array
|
||||
{
|
||||
$match = Strings::match($annotationContent, '#' . $type . '=\{(?<content>.*?)\}#sm');
|
||||
if (! isset($match['content'])) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Strings::matchAll($match['content'], self::JOIN_COLUMN_PATTERN);
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNodeFactory\Doctrine\Property_;
|
||||
|
||||
use Doctrine\ORM\Mapping\ManyToMany;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
|
||||
use PHPStan\PhpDocParser\Parser\TokenIterator;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Property_\ManyToManyTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNodeFactory\AbstractPhpDocNodeFactory;
|
||||
use Rector\Exception\ShouldNotHappenException;
|
||||
|
||||
final class ManyToManyPhpDocNodeFactory extends AbstractPhpDocNodeFactory
|
||||
{
|
||||
public function getName(): string
|
||||
{
|
||||
return ManyToManyTagValueNode::SHORT_NAME;
|
||||
}
|
||||
|
||||
public function createFromNodeAndTokens(Node $node, TokenIterator $tokenIterator): ?PhpDocTagValueNode
|
||||
{
|
||||
if (! $node instanceof Property) {
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
|
||||
$annotationContent = $this->resolveContentFromTokenIterator($tokenIterator);
|
||||
|
||||
/** @var ManyToMany|null $manyToMany */
|
||||
$manyToMany = $this->nodeAnnotationReader->readPropertyAnnotation($node, ManyToMany::class);
|
||||
if ($manyToMany === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new ManyToManyTagValueNode(
|
||||
$manyToMany->targetEntity,
|
||||
$manyToMany->mappedBy,
|
||||
$manyToMany->inversedBy,
|
||||
$manyToMany->cascade,
|
||||
$manyToMany->fetch,
|
||||
$manyToMany->orphanRemoval,
|
||||
$manyToMany->indexBy,
|
||||
$annotationContent,
|
||||
$this->resolveFqnTargetEntity($manyToMany->targetEntity, $node)
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNodeFactory\Doctrine\Property_;
|
||||
|
||||
use Doctrine\ORM\Mapping\ManyToOne;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
|
||||
use PHPStan\PhpDocParser\Parser\TokenIterator;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Property_\ManyToOneTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNodeFactory\AbstractPhpDocNodeFactory;
|
||||
use Rector\Exception\ShouldNotHappenException;
|
||||
|
||||
final class ManyToOnePhpDocNodeFactory extends AbstractPhpDocNodeFactory
|
||||
{
|
||||
public function getName(): string
|
||||
{
|
||||
return ManyToOneTagValueNode::SHORT_NAME;
|
||||
}
|
||||
|
||||
public function createFromNodeAndTokens(Node $node, TokenIterator $tokenIterator): ?PhpDocTagValueNode
|
||||
{
|
||||
if (! $node instanceof Property) {
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
|
||||
$annotationContent = $this->resolveContentFromTokenIterator($tokenIterator);
|
||||
|
||||
/** @var ManyToOne|null $manyToOne */
|
||||
$manyToOne = $this->nodeAnnotationReader->readPropertyAnnotation($node, ManyToOne::class);
|
||||
if ($manyToOne === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new ManyToOneTagValueNode(
|
||||
$manyToOne->targetEntity,
|
||||
$manyToOne->cascade,
|
||||
$manyToOne->fetch,
|
||||
$manyToOne->inversedBy,
|
||||
$annotationContent,
|
||||
$this->resolveFqnTargetEntity($manyToOne->targetEntity, $node)
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNodeFactory\Doctrine\Property_;
|
||||
|
||||
use Doctrine\ORM\Mapping\OneToMany;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
|
||||
use PHPStan\PhpDocParser\Parser\TokenIterator;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Property_\OneToManyTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNodeFactory\AbstractPhpDocNodeFactory;
|
||||
use Rector\Exception\ShouldNotHappenException;
|
||||
|
||||
final class OneToManyPhpDocNodeFactory extends AbstractPhpDocNodeFactory
|
||||
{
|
||||
public function getName(): string
|
||||
{
|
||||
return OneToManyTagValueNode::SHORT_NAME;
|
||||
}
|
||||
|
||||
public function createFromNodeAndTokens(Node $node, TokenIterator $tokenIterator): ?PhpDocTagValueNode
|
||||
{
|
||||
if (! $node instanceof Property) {
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
|
||||
$annotationContent = $this->resolveContentFromTokenIterator($tokenIterator);
|
||||
|
||||
/** @var OneToMany|null $oneToMany */
|
||||
$oneToMany = $this->nodeAnnotationReader->readPropertyAnnotation($node, OneToMany::class);
|
||||
if ($oneToMany === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new OneToManyTagValueNode(
|
||||
$oneToMany->mappedBy,
|
||||
$oneToMany->targetEntity,
|
||||
$oneToMany->cascade,
|
||||
$oneToMany->fetch,
|
||||
$oneToMany->orphanRemoval,
|
||||
$oneToMany->indexBy,
|
||||
$annotationContent,
|
||||
$this->resolveFqnTargetEntity($oneToMany->targetEntity, $node)
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNodeFactory\Doctrine\Property_;
|
||||
|
||||
use Doctrine\ORM\Mapping\OneToOne;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
|
||||
use PHPStan\PhpDocParser\Parser\TokenIterator;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Property_\OneToOneTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNodeFactory\AbstractPhpDocNodeFactory;
|
||||
use Rector\Exception\ShouldNotHappenException;
|
||||
|
||||
final class OneToOnePhpDocNodeFactory extends AbstractPhpDocNodeFactory
|
||||
{
|
||||
public function getName(): string
|
||||
{
|
||||
return OneToOneTagValueNode::SHORT_NAME;
|
||||
}
|
||||
|
||||
public function createFromNodeAndTokens(Node $node, TokenIterator $tokenIterator): ?PhpDocTagValueNode
|
||||
{
|
||||
if (! $node instanceof Property) {
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
|
||||
/** @var OneToOne|null $oneToOne */
|
||||
$oneToOne = $this->nodeAnnotationReader->readPropertyAnnotation($node, OneToOne::class);
|
||||
if ($oneToOne === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$annotationContent = $this->resolveContentFromTokenIterator($tokenIterator);
|
||||
|
||||
return new OneToOneTagValueNode(
|
||||
$oneToOne->targetEntity,
|
||||
$oneToOne->mappedBy,
|
||||
$oneToOne->inversedBy,
|
||||
$oneToOne->cascade,
|
||||
$oneToOne->fetch,
|
||||
$oneToOne->orphanRemoval,
|
||||
$annotationContent,
|
||||
$this->resolveFqnTargetEntity($oneToOne->targetEntity, $node)
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNodeFactory\JMS;
|
||||
|
||||
use JMS\DiExtraBundle\Annotation\Inject;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
|
||||
use PHPStan\PhpDocParser\Parser\TokenIterator;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\JMS\JMSInjectTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNodeFactory\AbstractPhpDocNodeFactory;
|
||||
use Rector\PhpParser\Node\Resolver\NameResolver;
|
||||
|
||||
final class JMSInjectPhpDocNodeFactory extends AbstractPhpDocNodeFactory
|
||||
{
|
||||
/**
|
||||
* @var NameResolver
|
||||
*/
|
||||
private $nameResolver;
|
||||
|
||||
public function __construct(NameResolver $nameResolver)
|
||||
{
|
||||
$this->nameResolver = $nameResolver;
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return JMSInjectTagValueNode::SHORT_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return JMSInjectTagValueNode|null
|
||||
*/
|
||||
public function createFromNodeAndTokens(Node $node, TokenIterator $tokenIterator): ?PhpDocTagValueNode
|
||||
{
|
||||
if (! $node instanceof Property) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @var Inject|null $inject */
|
||||
$inject = $this->nodeAnnotationReader->readPropertyAnnotation($node, JMSInjectTagValueNode::CLASS_NAME);
|
||||
if ($inject === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($inject->value === null) {
|
||||
$serviceName = $this->nameResolver->getName($node);
|
||||
} else {
|
||||
$serviceName = $inject->value;
|
||||
}
|
||||
|
||||
// needed for proper doc block formatting
|
||||
$this->resolveContentFromTokenIterator($tokenIterator);
|
||||
|
||||
return new JMSInjectTagValueNode($serviceName, $inject->required, $inject->strict);
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNodeFactory\JMS;
|
||||
|
||||
use JMS\Serializer\Annotation\Type;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
|
||||
use PHPStan\PhpDocParser\Parser\TokenIterator;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\JMS\SerializerTypeTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNodeFactory\AbstractPhpDocNodeFactory;
|
||||
use Rector\Exception\ShouldNotHappenException;
|
||||
|
||||
final class SerializerTypePhpDocNodeFactory extends AbstractPhpDocNodeFactory
|
||||
{
|
||||
public function getName(): string
|
||||
{
|
||||
return SerializerTypeTagValueNode::SHORT_NAME;
|
||||
}
|
||||
|
||||
public function createFromNodeAndTokens(Node $node, TokenIterator $tokenIterator): ?PhpDocTagValueNode
|
||||
{
|
||||
if (! $node instanceof Property) {
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
|
||||
/** @var Type|null $type */
|
||||
$type = $this->nodeAnnotationReader->readPropertyAnnotation($node, SerializerTypeTagValueNode::CLASS_NAME);
|
||||
if ($type === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$annotationContent = $this->resolveContentFromTokenIterator($tokenIterator);
|
||||
return new SerializerTypeTagValueNode($type->name, $annotationContent);
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNodeFactory\PHPDI;
|
||||
|
||||
use DI\Annotation\Inject;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
|
||||
use PHPStan\PhpDocParser\Parser\TokenIterator;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\PHPDI\PHPDIInjectTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNodeFactory\AbstractPhpDocNodeFactory;
|
||||
|
||||
final class PHPDIInjectPhpDocNodeFactory extends AbstractPhpDocNodeFactory
|
||||
{
|
||||
public function getName(): string
|
||||
{
|
||||
return PHPDIInjectTagValueNode::SHORT_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PHPDIInjectTagValueNode|null
|
||||
*/
|
||||
public function createFromNodeAndTokens(Node $node, TokenIterator $tokenIterator): ?PhpDocTagValueNode
|
||||
{
|
||||
if (! $node instanceof Property) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @var Inject|null $inject */
|
||||
$inject = $this->nodeAnnotationReader->readPropertyAnnotation($node, PHPDIInjectTagValueNode::CLASS_NAME);
|
||||
if ($inject === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// needed for proper doc block formatting
|
||||
$this->resolveContentFromTokenIterator($tokenIterator);
|
||||
|
||||
return new PHPDIInjectTagValueNode($inject->getName());
|
||||
}
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNodeFactory;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\InvalidTagValueNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
|
||||
use PHPStan\PhpDocParser\Lexer\Lexer;
|
||||
use PHPStan\PhpDocParser\Parser\ParserException;
|
||||
use PHPStan\PhpDocParser\Parser\PhpDocParser;
|
||||
use PHPStan\PhpDocParser\Parser\TokenIterator;
|
||||
use Rector\BetterPhpDocParser\Attributes\Ast\PhpDoc\AttributeAwareParamTagValueNode;
|
||||
use Rector\BetterPhpDocParser\Contract\PhpDocNodeFactoryInterface;
|
||||
use Rector\BetterPhpDocParser\Contract\PhpDocParserAwareInterface;
|
||||
use Symplify\PackageBuilder\Reflection\PrivatesAccessor;
|
||||
use Symplify\PackageBuilder\Reflection\PrivatesCaller;
|
||||
|
||||
final class ParamPhpDocNodeFactory implements PhpDocNodeFactoryInterface, PhpDocParserAwareInterface
|
||||
{
|
||||
/**
|
||||
* @var PrivatesAccessor
|
||||
*/
|
||||
private $privatesAccessor;
|
||||
|
||||
/**
|
||||
* @var PrivatesCaller
|
||||
*/
|
||||
private $privatesCaller;
|
||||
|
||||
/**
|
||||
* @var PhpDocParser
|
||||
*/
|
||||
private $phpDocParser;
|
||||
|
||||
public function __construct(PrivatesAccessor $privatesAccessor, PrivatesCaller $privatesCaller)
|
||||
{
|
||||
$this->privatesAccessor = $privatesAccessor;
|
||||
$this->privatesCaller = $privatesCaller;
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return '@param';
|
||||
}
|
||||
|
||||
public function createFromNodeAndTokens(Node $node, TokenIterator $tokenIterator): ?PhpDocTagValueNode
|
||||
{
|
||||
try {
|
||||
$tokenIterator->pushSavePoint();
|
||||
$tagValue = $this->parseParamTagValue($tokenIterator);
|
||||
$tokenIterator->dropSavePoint();
|
||||
|
||||
return $tagValue;
|
||||
} catch (ParserException $parserException) {
|
||||
$tokenIterator->rollback();
|
||||
$description = $this->privatesCaller->callPrivateMethod(
|
||||
$this->phpDocParser,
|
||||
'parseOptionalDescription',
|
||||
$tokenIterator
|
||||
);
|
||||
|
||||
return new InvalidTagValueNode($description, $parserException);
|
||||
}
|
||||
}
|
||||
|
||||
public function setPhpDocParser(PhpDocParser $phpDocParser): void
|
||||
{
|
||||
$this->phpDocParser = $phpDocParser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override of parent private method to allow reference: https://github.com/rectorphp/rector/pull/1735
|
||||
*/
|
||||
private function parseParamTagValue(TokenIterator $tokenIterator): ParamTagValueNode
|
||||
{
|
||||
$typeParser = $this->privatesAccessor->getPrivateProperty($this->phpDocParser, 'typeParser');
|
||||
|
||||
$type = $typeParser->parse($tokenIterator);
|
||||
|
||||
$isVariadic = $tokenIterator->tryConsumeTokenType(Lexer::TOKEN_VARIADIC);
|
||||
|
||||
// extra value over parent
|
||||
$isReference = $tokenIterator->tryConsumeTokenType(Lexer::TOKEN_REFERENCE);
|
||||
|
||||
$parameterName = $this->privatesCaller->callPrivateMethod(
|
||||
$this->phpDocParser,
|
||||
'parseRequiredVariableName',
|
||||
$tokenIterator
|
||||
);
|
||||
$description = $this->privatesCaller->callPrivateMethod(
|
||||
$this->phpDocParser,
|
||||
'parseOptionalDescription',
|
||||
$tokenIterator
|
||||
);
|
||||
|
||||
return new AttributeAwareParamTagValueNode($type, $isVariadic, $parameterName, $description, $isReference);
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNodeFactory\Sensio;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
|
||||
use PHPStan\PhpDocParser\Parser\TokenIterator;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Sensio\SensioMethodTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNodeFactory\AbstractPhpDocNodeFactory;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
|
||||
|
||||
final class SensioMethodPhpDocNodeFactory extends AbstractPhpDocNodeFactory
|
||||
{
|
||||
public function getName(): string
|
||||
{
|
||||
return SensioMethodTagValueNode::SHORT_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SensioMethodTagValueNode|null
|
||||
*/
|
||||
public function createFromNodeAndTokens(Node $node, TokenIterator $tokenIterator): ?PhpDocTagValueNode
|
||||
{
|
||||
if (! $node instanceof ClassMethod) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @var Method|null $method */
|
||||
$method = $this->nodeAnnotationReader->readMethodAnnotation($node, SensioMethodTagValueNode::CLASS_NAME);
|
||||
if ($method === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// to skip tokens for this node
|
||||
$this->resolveContentFromTokenIterator($tokenIterator);
|
||||
|
||||
return new SensioMethodTagValueNode($method->getMethods());
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNodeFactory\Sensio;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
|
||||
use PHPStan\PhpDocParser\Parser\TokenIterator;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Sensio\SensioTemplateTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNodeFactory\AbstractPhpDocNodeFactory;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
|
||||
|
||||
final class SensioTemplatePhpDocNodeFactory extends AbstractPhpDocNodeFactory
|
||||
{
|
||||
public function getName(): string
|
||||
{
|
||||
return SensioTemplateTagValueNode::SHORT_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SensioTemplateTagValueNode|null
|
||||
*/
|
||||
public function createFromNodeAndTokens(Node $node, TokenIterator $tokenIterator): ?PhpDocTagValueNode
|
||||
{
|
||||
if (! $node instanceof ClassMethod) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @var Template|null $template */
|
||||
$template = $this->nodeAnnotationReader->readMethodAnnotation($node, SensioTemplateTagValueNode::CLASS_NAME);
|
||||
if ($template === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new SensioTemplateTagValueNode(
|
||||
$template->getTemplate(),
|
||||
$template->getOwner(),
|
||||
$template->getVars()
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNodeFactory\Symfony;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
|
||||
use PHPStan\PhpDocParser\Parser\TokenIterator;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Symfony\SymfonyRouteTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNodeFactory\AbstractPhpDocNodeFactory;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
final class SymfonyRoutePhpDocNodeFactory extends AbstractPhpDocNodeFactory
|
||||
{
|
||||
public function getName(): string
|
||||
{
|
||||
return SymfonyRouteTagValueNode::SHORT_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SymfonyRouteTagValueNode|null
|
||||
*/
|
||||
public function createFromNodeAndTokens(Node $node, TokenIterator $tokenIterator): ?PhpDocTagValueNode
|
||||
{
|
||||
if (! $node instanceof ClassMethod) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @var Route|null $route */
|
||||
$route = $this->nodeAnnotationReader->readMethodAnnotation($node, SymfonyRouteTagValueNode::CLASS_NAME);
|
||||
if ($route === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$annotationContent = $this->resolveContentFromTokenIterator($tokenIterator);
|
||||
|
||||
return new SymfonyRouteTagValueNode(
|
||||
$route->getPath(),
|
||||
$route->getName(),
|
||||
$route->getMethods(),
|
||||
$annotationContent
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNodeFactory\Symfony\Validator\Constraints;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
|
||||
use PHPStan\PhpDocParser\Parser\TokenIterator;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Symfony\Validator\Constraints\AssertChoiceTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNodeFactory\AbstractPhpDocNodeFactory;
|
||||
use Symfony\Component\Validator\Constraints\Choice;
|
||||
|
||||
final class AssertChoicePhpDocNodeFactory extends AbstractPhpDocNodeFactory
|
||||
{
|
||||
public function getName(): string
|
||||
{
|
||||
return AssertChoiceTagValueNode::SHORT_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return AssertChoiceTagValueNode|null
|
||||
*/
|
||||
public function createFromNodeAndTokens(Node $node, TokenIterator $tokenIterator): ?PhpDocTagValueNode
|
||||
{
|
||||
if (! $node instanceof Property) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @var Choice|null $choice */
|
||||
$choice = $this->nodeAnnotationReader->readPropertyAnnotation($node, AssertChoiceTagValueNode::CLASS_NAME);
|
||||
if ($choice === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$annotationContent = $this->resolveContentFromTokenIterator($tokenIterator);
|
||||
|
||||
return new AssertChoiceTagValueNode($choice->callback, $choice->strict, $annotationContent);
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\BetterPhpDocParser\PhpDocNodeFactory\Symfony\Validator\Constraints;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
|
||||
use PHPStan\PhpDocParser\Parser\TokenIterator;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Symfony\Validator\Constraints\AssertTypeTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNodeFactory\AbstractPhpDocNodeFactory;
|
||||
use Symfony\Component\Validator\Constraints\Type;
|
||||
|
||||
final class AssertTypePhpDocNodeFactory extends AbstractPhpDocNodeFactory
|
||||
{
|
||||
public function getName(): string
|
||||
{
|
||||
return AssertTypeTagValueNode::SHORT_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return AssertTypeTagValueNode|null
|
||||
*/
|
||||
public function createFromNodeAndTokens(Node $node, TokenIterator $tokenIterator): ?PhpDocTagValueNode
|
||||
{
|
||||
if (! $node instanceof Property) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @var Type|null $type */
|
||||
$type = $this->nodeAnnotationReader->readPropertyAnnotation($node, AssertTypeTagValueNode::CLASS_NAME);
|
||||
if ($type === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new AssertTypeTagValueNode($type->type);
|
||||
}
|
||||
}
|
@ -3,48 +3,20 @@
|
||||
namespace Rector\BetterPhpDocParser\PhpDocParser;
|
||||
|
||||
use Nette\Utils\Strings;
|
||||
use PhpParser\Node;
|
||||
use PHPStan\PhpDocParser\Lexer\Lexer;
|
||||
use PHPStan\PhpDocParser\Parser\TokenIterator;
|
||||
use Rector\Configuration\CurrentNodeProvider;
|
||||
use Rector\DoctrinePhpDocParser\AnnotationReader\NodeAnnotationReader;
|
||||
|
||||
abstract class AbstractPhpDocParser
|
||||
final class AnnotationContentResolver
|
||||
{
|
||||
/**
|
||||
* @var NodeAnnotationReader
|
||||
*/
|
||||
protected $nodeAnnotationReader;
|
||||
|
||||
/**
|
||||
* @var CurrentNodeProvider
|
||||
*/
|
||||
private $currentNodeProvider;
|
||||
|
||||
/**
|
||||
* @required
|
||||
*/
|
||||
public function autowireAbstractPhpDocParser(
|
||||
CurrentNodeProvider $currentNodeProvider,
|
||||
NodeAnnotationReader $nodeAnnotationReader
|
||||
): void {
|
||||
$this->currentNodeProvider = $currentNodeProvider;
|
||||
$this->nodeAnnotationReader = $nodeAnnotationReader;
|
||||
}
|
||||
|
||||
protected function getCurrentPhpNode(): Node
|
||||
{
|
||||
return $this->currentNodeProvider->getNode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Skip all tokens for this annotation, so next annotation can work with tokens after this one
|
||||
* Inspired at @see \PHPStan\PhpDocParser\Parser\PhpDocParser::parseText()
|
||||
*/
|
||||
protected function resolveAnnotationContent(TokenIterator $tokenIterator): string
|
||||
public function resolveFromTokenIterator(TokenIterator $tokenIterator): string
|
||||
{
|
||||
$annotationContent = '';
|
||||
$unclosedOpenedBracketCount = 0;
|
||||
|
||||
while (true) {
|
||||
if ($tokenIterator->currentTokenType() === Lexer::TOKEN_OPEN_PARENTHESES) {
|
||||
++$unclosedOpenedBracketCount;
|
@ -7,7 +7,7 @@ use Nette\Utils\Strings;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
|
||||
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
|
||||
use Rector\BetterPhpDocParser\Attributes\Contract\Ast\AttributeAwareNodeInterface;
|
||||
use Rector\DoctrinePhpDocParser\Array_\ArrayItemStaticHelper;
|
||||
use Rector\BetterPhpDocParser\Utils\ArrayItemStaticHelper;
|
||||
|
||||
abstract class AbstractTagValueNode implements AttributeAwareNodeInterface, PhpDocTagValueNode
|
||||
{
|
||||
|
@ -4,8 +4,6 @@ namespace Rector\BetterPhpDocParser\PhpDocParser;
|
||||
|
||||
use Nette\Utils\Strings;
|
||||
use PHPStan\PhpDocParser\Ast\Node;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\InvalidTagValueNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
|
||||
@ -16,15 +14,21 @@ use PHPStan\PhpDocParser\Parser\PhpDocParser;
|
||||
use PHPStan\PhpDocParser\Parser\TokenIterator;
|
||||
use PHPStan\PhpDocParser\Parser\TypeParser;
|
||||
use Rector\BetterPhpDocParser\Attributes\Ast\AttributeAwareNodeFactory;
|
||||
use Rector\BetterPhpDocParser\Attributes\Ast\PhpDoc\AttributeAwareParamTagValueNode;
|
||||
use Rector\BetterPhpDocParser\Attributes\Ast\PhpDoc\AttributeAwarePhpDocNode;
|
||||
use Rector\BetterPhpDocParser\Attributes\Attribute\Attribute;
|
||||
use Rector\BetterPhpDocParser\Contract\PhpDocNodeFactoryInterface;
|
||||
use Rector\BetterPhpDocParser\Contract\PhpDocParserAwareInterface;
|
||||
use Rector\BetterPhpDocParser\Contract\PhpDocParserExtensionInterface;
|
||||
use Rector\BetterPhpDocParser\Printer\MultilineSpaceFormatPreserver;
|
||||
use Rector\BetterPhpDocParser\ValueObject\StartEndInfo;
|
||||
use Rector\Configuration\CurrentNodeProvider;
|
||||
use Symplify\PackageBuilder\Reflection\PrivatesAccessor;
|
||||
use Symplify\PackageBuilder\Reflection\PrivatesCaller;
|
||||
|
||||
/**
|
||||
* @see \Rector\BetterPhpDocParser\Tests\PhpDocParser\OrmTagParser\Class_\BetterPhpDocParserTest
|
||||
* @see \Rector\BetterPhpDocParser\Tests\PhpDocParser\OrmTagParser\Property_\OrmTagParserPropertyTest
|
||||
*/
|
||||
final class BetterPhpDocParser extends PhpDocParser
|
||||
{
|
||||
/**
|
||||
@ -57,14 +61,27 @@ final class BetterPhpDocParser extends PhpDocParser
|
||||
*/
|
||||
private $phpDocParserExtensions = [];
|
||||
|
||||
/**
|
||||
* @var PhpDocNodeFactoryInterface[]
|
||||
*/
|
||||
private $phpDocNodeFactories = [];
|
||||
|
||||
/**
|
||||
* @var CurrentNodeProvider
|
||||
*/
|
||||
private $currentNodeProvider;
|
||||
|
||||
/**
|
||||
* @param PhpDocParserExtensionInterface[] $phpDocParserExtensions
|
||||
* @param PhpDocNodeFactoryInterface[] $phpDocNodeFactories
|
||||
*/
|
||||
public function __construct(
|
||||
TypeParser $typeParser,
|
||||
ConstExprParser $constExprParser,
|
||||
AttributeAwareNodeFactory $attributeAwareNodeFactory,
|
||||
MultilineSpaceFormatPreserver $multilineSpaceFormatPreserver,
|
||||
CurrentNodeProvider $currentNodeProvider,
|
||||
array $phpDocNodeFactories = [],
|
||||
array $phpDocParserExtensions = []
|
||||
) {
|
||||
parent::__construct($typeParser, $constExprParser);
|
||||
@ -74,6 +91,8 @@ final class BetterPhpDocParser extends PhpDocParser
|
||||
$this->attributeAwareNodeFactory = $attributeAwareNodeFactory;
|
||||
$this->multilineSpaceFormatPreserver = $multilineSpaceFormatPreserver;
|
||||
$this->phpDocParserExtensions = $phpDocParserExtensions;
|
||||
$this->phpDocNodeFactories = $phpDocNodeFactories;
|
||||
$this->currentNodeProvider = $currentNodeProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -104,7 +123,8 @@ final class BetterPhpDocParser extends PhpDocParser
|
||||
}
|
||||
|
||||
if (! $this->isComment) {
|
||||
$tokenIterator->consumeTokenType(Lexer::TOKEN_CLOSE_PHPDOC);
|
||||
// might be in the middle of annotations
|
||||
$tokenIterator->tryConsumeTokenType(Lexer::TOKEN_CLOSE_PHPDOC);
|
||||
}
|
||||
|
||||
$phpDocNode = new PhpDocNode(array_values($children));
|
||||
@ -118,9 +138,10 @@ final class BetterPhpDocParser extends PhpDocParser
|
||||
|
||||
$tokenIterator->next();
|
||||
|
||||
// @todo somehow decouple to tag pre-processor
|
||||
if (Strings::match($tag, '#@(ORM|Assert|Serializer|DI|Inject)$#')) {
|
||||
if ($tag !== '@Inject') {
|
||||
// join tags like "@ORM\Column" etc.
|
||||
if ($tokenIterator->currentTokenType() === Lexer::TOKEN_IDENTIFIER) {
|
||||
// is not e.g "@var "
|
||||
if (! Strings::match($tag, '#^@[a-z]#')) { // probably a class tag
|
||||
$tag .= $tokenIterator->currentTokenValue();
|
||||
$tokenIterator->next();
|
||||
}
|
||||
@ -151,9 +172,21 @@ final class BetterPhpDocParser extends PhpDocParser
|
||||
}
|
||||
|
||||
// needed for reference support in params, see https://github.com/rectorphp/rector/issues/1734
|
||||
if ($tag === '@param') {
|
||||
$tagValueNode = $this->customParseParamTagValueNode($tokenIterator);
|
||||
} else {
|
||||
$tagValueNode = null;
|
||||
foreach ($this->phpDocNodeFactories as $phpDocNodeFactory) {
|
||||
// to prevent circular reference of this service
|
||||
if ($phpDocNodeFactory instanceof PhpDocParserAwareInterface) {
|
||||
$phpDocNodeFactory->setPhpDocParser($this);
|
||||
}
|
||||
|
||||
if ($phpDocNodeFactory->getName() === $tag) {
|
||||
$currentNode = $this->currentNodeProvider->getNode();
|
||||
$tagValueNode = $phpDocNodeFactory->createFromNodeAndTokens($currentNode, $tokenIterator);
|
||||
}
|
||||
}
|
||||
|
||||
// fallback to orignal parser
|
||||
if ($tagValueNode === null) {
|
||||
$tagValueNode = parent::parseTagValue($tokenIterator, $tag);
|
||||
}
|
||||
|
||||
@ -198,16 +231,16 @@ final class BetterPhpDocParser extends PhpDocParser
|
||||
|
||||
foreach ($originalTokens as $originalToken) {
|
||||
// skip opening
|
||||
if (Strings::match($originalToken[0], '#/\*\*#')) {
|
||||
if ($originalToken[1] === Lexer::TOKEN_OPEN_PHPDOC) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// skip closing
|
||||
if (Strings::match($originalToken[0], '#\*\/#')) {
|
||||
if ($originalToken[1] === Lexer::TOKEN_CLOSE_PHPDOC) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Strings::match($originalToken[0], '#^\s+\*#')) {
|
||||
if ($originalToken[1] === Lexer::TOKEN_PHPDOC_EOL) {
|
||||
$originalToken[0] = PHP_EOL;
|
||||
}
|
||||
|
||||
@ -216,44 +249,4 @@ final class BetterPhpDocParser extends PhpDocParser
|
||||
|
||||
return trim($originalContent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override of parent private method to allow reference: https://github.com/rectorphp/rector/pull/1735
|
||||
*/
|
||||
private function parseParamTagValue(TokenIterator $tokenIterator): ParamTagValueNode
|
||||
{
|
||||
$typeParser = $this->privatesAccessor->getPrivateProperty($this, 'typeParser');
|
||||
|
||||
$type = $typeParser->parse($tokenIterator);
|
||||
|
||||
$isVariadic = $tokenIterator->tryConsumeTokenType(Lexer::TOKEN_VARIADIC);
|
||||
|
||||
// extra value over parent
|
||||
$isReference = $tokenIterator->tryConsumeTokenType(Lexer::TOKEN_REFERENCE);
|
||||
|
||||
$parameterName = $this->privatesCaller->callPrivateMethod($this, 'parseRequiredVariableName', $tokenIterator);
|
||||
$description = $this->privatesCaller->callPrivateMethod($this, 'parseOptionalDescription', $tokenIterator);
|
||||
|
||||
return new AttributeAwareParamTagValueNode($type, $isVariadic, $parameterName, $description, $isReference);
|
||||
}
|
||||
|
||||
private function customParseParamTagValueNode(TokenIterator $tokenIterator): PhpDocTagValueNode
|
||||
{
|
||||
try {
|
||||
$tokenIterator->pushSavePoint();
|
||||
$tagValue = $this->parseParamTagValue($tokenIterator);
|
||||
$tokenIterator->dropSavePoint();
|
||||
|
||||
return $tagValue;
|
||||
} catch (ParserException $parserException) {
|
||||
$tokenIterator->rollback();
|
||||
$description = $this->privatesCaller->callPrivateMethod(
|
||||
$this,
|
||||
'parseOptionalDescription',
|
||||
$tokenIterator
|
||||
);
|
||||
|
||||
return new InvalidTagValueNode($description, $parserException);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,66 +0,0 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\BetterPhpDocParser\PhpDocParser;
|
||||
|
||||
use DI\Annotation\Inject as PHPDIInjectAlias;
|
||||
use JMS\DiExtraBundle\Annotation\Inject;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
|
||||
use PHPStan\PhpDocParser\Parser\TokenIterator;
|
||||
use Rector\BetterPhpDocParser\Ast\PhpDoc\JMS\JMSInjectTagValueNode;
|
||||
use Rector\BetterPhpDocParser\Ast\PhpDoc\PHPDI\PHPDIInjectTagValueNode;
|
||||
use Rector\PhpParser\Node\Resolver\NameResolver;
|
||||
|
||||
final class InjectPhpDocParser extends AbstractPhpDocParser
|
||||
{
|
||||
/**
|
||||
* @var NameResolver
|
||||
*/
|
||||
private $nameResolver;
|
||||
|
||||
public function __construct(NameResolver $nameResolver)
|
||||
{
|
||||
$this->nameResolver = $nameResolver;
|
||||
}
|
||||
|
||||
public function parse(TokenIterator $tokenIterator, string $tag): ?PhpDocTagValueNode
|
||||
{
|
||||
/** @var Class_|Property $currentPhpNode */
|
||||
$currentPhpNode = $this->getCurrentPhpNode();
|
||||
|
||||
// needed for proper doc block formatting
|
||||
$this->resolveAnnotationContent($tokenIterator);
|
||||
|
||||
// Property tags
|
||||
if ($currentPhpNode instanceof Property) {
|
||||
if ($tag === '@DI\Inject') {
|
||||
/** @var Inject $inject */
|
||||
$inject = $this->nodeAnnotationReader->readPropertyAnnotation(
|
||||
$currentPhpNode,
|
||||
JMSInjectTagValueNode::CLASS_NAME
|
||||
);
|
||||
|
||||
if ($inject->value === null) {
|
||||
$serviceName = $this->nameResolver->getName($currentPhpNode);
|
||||
} else {
|
||||
$serviceName = $inject->value;
|
||||
}
|
||||
|
||||
return new JMSInjectTagValueNode($serviceName, $inject->required, $inject->strict);
|
||||
}
|
||||
|
||||
if ($tag === '@Inject') {
|
||||
/** @var PHPDIInjectAlias $inject */
|
||||
$inject = $this->nodeAnnotationReader->readPropertyAnnotation(
|
||||
$currentPhpNode,
|
||||
PHPDIInjectTagValueNode::CLASS_NAME
|
||||
);
|
||||
|
||||
return new PHPDIInjectTagValueNode($inject->getName());
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@ -6,8 +6,8 @@ use Nette\Utils\Arrays;
|
||||
use Nette\Utils\Strings;
|
||||
use PHPStan\PhpDocParser\Ast\Node;
|
||||
use PHPStan\PhpDocParser\Lexer\Lexer;
|
||||
use Rector\BetterPhpDocParser\Contract\Doctrine\DoctrineTagNodeInterface;
|
||||
use Rector\BetterPhpDocParser\ValueObject\StartEndInfo;
|
||||
use Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc\DoctrineTagNodeInterface;
|
||||
|
||||
final class OriginalSpacingRestorer
|
||||
{
|
||||
|
@ -6,7 +6,9 @@ use Iterator;
|
||||
use Nette\Utils\FileSystem;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter\Source\Doctrine\CaseSensitive;
|
||||
use Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter\Source\Doctrine\IndexInTable;
|
||||
use Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter\Source\Doctrine\Short;
|
||||
|
||||
final class DoctrineTest extends AbstractPhpDocInfoPrinterTest
|
||||
{
|
||||
@ -31,5 +33,9 @@ final class DoctrineTest extends AbstractPhpDocInfoPrinterTest
|
||||
public function provideDataForTestClass(): Iterator
|
||||
{
|
||||
yield [__DIR__ . '/Source/Doctrine/index_in_table.txt', new Class_(IndexInTable::class)];
|
||||
|
||||
$this->markTestSkipped('wip');
|
||||
yield [__DIR__ . '/Source/Doctrine/case_sensitive.txt', new Class_(CaseSensitive::class)];
|
||||
yield [__DIR__ . '/Source/Doctrine/short.txt', new Class_(Short::class)];
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter\Source\Doctrine;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Table(
|
||||
* name="Content_Status", indexes={
|
||||
* @Orm\Index(name="value_idx", columns={"value"}),
|
||||
* @Orm\Index(name="dateFrom_idx", columns={"dateFrom"}),
|
||||
* @Orm\Index(name="dateTo_idx", columns={"dateTo"}),
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
final class CaseSensitive
|
||||
{
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter\Source\Doctrine;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Doctrine\ORM\Mapping\UniqueConstraint;
|
||||
|
||||
/**
|
||||
* @ORM\Table(
|
||||
* uniqueConstraints={
|
||||
* @UniqueConstraint(name="content_status_unique", columns={"content_id", "site_id", "lang"})
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
final class Short
|
||||
{
|
||||
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* @ORM\Table(
|
||||
* name="Content_Status", indexes={
|
||||
* @Orm\Index(name="value_idx", columns={"value"}),
|
||||
* @Orm\Index(name="dateFrom_idx", columns={"dateFrom"}),
|
||||
* @Orm\Index(name="dateTo_idx", columns={"dateTo"}),
|
||||
* }
|
||||
* )
|
@ -0,0 +1,6 @@
|
||||
/**
|
||||
* @ORM\Table(
|
||||
* uniqueConstraints={
|
||||
* @UniqueConstraint(name="content_status_unique", columns={"content_id", "site_id", "lang"})
|
||||
* }
|
||||
* )
|
@ -1,6 +1,6 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\DoctrinePhpDocParser\Tests\PhpDocParser\OrmTagParser;
|
||||
namespace Rector\BetterPhpDocParser\Tests\PhpDocParser\OrmTagParser;
|
||||
|
||||
use PhpParser\Node;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
|
@ -1,14 +1,11 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\DoctrinePhpDocParser\Tests\PhpDocParser\OrmTagParser\Class_;
|
||||
namespace Rector\BetterPhpDocParser\Tests\PhpDocParser\OrmTagParser\Class_;
|
||||
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use Rector\DoctrinePhpDocParser\Tests\PhpDocParser\OrmTagParser\AbstractOrmTagParserTest;
|
||||
use Rector\BetterPhpDocParser\Tests\PhpDocParser\OrmTagParser\AbstractOrmTagParserTest;
|
||||
|
||||
/**
|
||||
* @see \Rector\DoctrinePhpDocParser\PhpDocParser\OrmTagParser
|
||||
*/
|
||||
final class OrmTagParserClassTest extends AbstractOrmTagParserTest
|
||||
final class DoctrinePhpDocParserTest extends AbstractOrmTagParserTest
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
@ -0,0 +1,16 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\BetterPhpDocParser\Tests\PhpDocParser\OrmTagParser\Class_\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity(readOnly=true, repositoryClass="Rector\BetterPhpDocParser\Tests\PhpDocParser\OrmTagParser\Class_\Source\ExistingRepositoryClass")
|
||||
* @ORM\Entity
|
||||
* @ORM\Entity()
|
||||
* @ORM\Table(name="answer")
|
||||
*/
|
||||
final class SomeEntity
|
||||
{
|
||||
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
/**
|
||||
* @ORM\Entity(readOnly=true, repositoryClass="Rector\BetterPhpDocParser\Tests\PhpDocParser\OrmTagParser\Class_\Source\ExistingRepositoryClass")
|
||||
* @ORM\Entity
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="answer")
|
||||
*/
|
@ -0,0 +1,8 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\BetterPhpDocParser\Tests\PhpDocParser\OrmTagParser\Class_\Source;
|
||||
|
||||
final class ExistingRepositoryClass
|
||||
{
|
||||
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\DoctrinePhpDocParser\Tests\PhpDocParser\OrmTagParser\Property_\Fixture;
|
||||
namespace Rector\BetterPhpDocParser\Tests\PhpDocParser\OrmTagParser\Property_\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\DoctrinePhpDocParser\Tests\PhpDocParser\OrmTagParser\Property_\Fixture;
|
||||
namespace Rector\BetterPhpDocParser\Tests\PhpDocParser\OrmTagParser\Property_\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\DoctrinePhpDocParser\Tests\PhpDocParser\OrmTagParser\Property_\Fixture;
|
||||
namespace Rector\BetterPhpDocParser\Tests\PhpDocParser\OrmTagParser\Property_\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
@ -1,13 +1,10 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\DoctrinePhpDocParser\Tests\PhpDocParser\OrmTagParser\Property_;
|
||||
namespace Rector\BetterPhpDocParser\Tests\PhpDocParser\OrmTagParser\Property_;
|
||||
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use Rector\DoctrinePhpDocParser\Tests\PhpDocParser\OrmTagParser\AbstractOrmTagParserTest;
|
||||
use Rector\BetterPhpDocParser\Tests\PhpDocParser\OrmTagParser\AbstractOrmTagParserTest;
|
||||
|
||||
/**
|
||||
* @see \Rector\DoctrinePhpDocParser\PhpDocParser\OrmTagParser
|
||||
*/
|
||||
final class OrmTagParserPropertyTest extends AbstractOrmTagParserTest
|
||||
{
|
||||
/**
|
@ -5,7 +5,6 @@ namespace Rector\CodingStyle\Rector\ClassMethod;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use Rector\Exception\ShouldNotHappenException;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Rector\RectorDefinition\CodeSample;
|
||||
|
@ -8,12 +8,12 @@ use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use Rector\BetterPhpDocParser\Contract\Doctrine\DoctrineRelationTagValueNodeInterface;
|
||||
use Rector\BetterPhpDocParser\Contract\Doctrine\InversedByNodeInterface;
|
||||
use Rector\BetterPhpDocParser\Contract\Doctrine\MappedByNodeInterface;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Class_\EntityTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Class_\InheritanceTypeTagValueNode;
|
||||
use Rector\Doctrine\PhpDocParser\DoctrineDocBlockResolver;
|
||||
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\Class_\EntityTagValueNode;
|
||||
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\Class_\InheritanceTypeTagValueNode;
|
||||
use Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc\DoctrineRelationTagValueNodeInterface;
|
||||
use Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc\InversedByNodeInterface;
|
||||
use Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc\MappedByNodeInterface;
|
||||
use Rector\NodeTypeResolver\NodeTypeResolver;
|
||||
use Rector\NodeTypeResolver\PhpDoc\NodeAnalyzer\DocBlockManipulator;
|
||||
use Rector\PhpParser\Node\Resolver\NameResolver;
|
||||
|
@ -5,8 +5,8 @@ namespace Rector\Doctrine\AbstractRector;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use Rector\BetterPhpDocParser\Contract\Doctrine\DoctrineRelationTagValueNodeInterface;
|
||||
use Rector\Doctrine\PhpDocParser\DoctrineDocBlockResolver;
|
||||
use Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc\DoctrineRelationTagValueNodeInterface;
|
||||
|
||||
trait DoctrineTrait
|
||||
{
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
namespace Rector\Doctrine\Collector;
|
||||
|
||||
use Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc\DoctrineRelationTagValueNodeInterface;
|
||||
use Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc\ToManyTagNodeInterface;
|
||||
use Rector\BetterPhpDocParser\Contract\Doctrine\DoctrineRelationTagValueNodeInterface;
|
||||
use Rector\BetterPhpDocParser\Contract\Doctrine\ToManyTagNodeInterface;
|
||||
|
||||
final class UuidMigrationDataCollector
|
||||
{
|
||||
|
@ -7,13 +7,13 @@ use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
|
||||
use Rector\BetterPhpDocParser\Attributes\Ast\PhpDoc\SpacelessPhpDocTagNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Property_\ColumnTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Property_\GeneratedValueTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Property_\IdTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Property_\JoinColumnTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Property_\JoinTableTagValueNode;
|
||||
use Rector\Doctrine\Uuid\JoinTableNameResolver;
|
||||
use Rector\Doctrine\ValueObject\DoctrineClass;
|
||||
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\Property_\ColumnTagValueNode;
|
||||
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\Property_\GeneratedValueTagValueNode;
|
||||
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\Property_\IdTagValueNode;
|
||||
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\Property_\JoinColumnTagValueNode;
|
||||
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\Property_\JoinTableTagValueNode;
|
||||
|
||||
final class PhpDocTagNodeFactory
|
||||
{
|
||||
|
@ -7,11 +7,11 @@ use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassLike;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use Rector\BetterPhpDocParser\Contract\Doctrine\DoctrineRelationTagValueNodeInterface;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
||||
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\Class_\EntityTagValueNode;
|
||||
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\Property_\ColumnTagValueNode;
|
||||
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\Property_\IdTagValueNode;
|
||||
use Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc\DoctrineRelationTagValueNodeInterface;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Class_\EntityTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Property_\ColumnTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Property_\IdTagValueNode;
|
||||
use Rector\Exception\ShouldNotHappenException;
|
||||
use Rector\NodeContainer\ParsedNodesByType;
|
||||
use Rector\NodeTypeResolver\ClassExistenceStaticHelper;
|
||||
|
@ -6,9 +6,9 @@ use Nette\Utils\Strings;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Property_\ColumnTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Property_\IdTagValueNode;
|
||||
use Rector\Doctrine\PhpDocParser\DoctrineDocBlockResolver;
|
||||
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\Property_\ColumnTagValueNode;
|
||||
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\Property_\IdTagValueNode;
|
||||
use Rector\NodeContainer\ParsedNodesByType;
|
||||
use Rector\PhpParser\Node\Manipulator\ClassManipulator;
|
||||
use Rector\PhpParser\Node\Resolver\NameResolver;
|
||||
|
@ -9,14 +9,14 @@ use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PhpParser\Node\Stmt\PropertyProperty;
|
||||
use PhpParser\Node\VarLikeIdentifier;
|
||||
use Rector\BetterPhpDocParser\Contract\Doctrine\DoctrineRelationTagValueNodeInterface;
|
||||
use Rector\BetterPhpDocParser\Contract\Doctrine\ToManyTagNodeInterface;
|
||||
use Rector\BetterPhpDocParser\Contract\Doctrine\ToOneTagNodeInterface;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Property_\JoinColumnTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Property_\OneToOneTagValueNode;
|
||||
use Rector\Doctrine\Collector\UuidMigrationDataCollector;
|
||||
use Rector\Doctrine\PhpDocParser\Ast\PhpDoc\PhpDocTagNodeFactory;
|
||||
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\Property_\JoinColumnTagValueNode;
|
||||
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\Property_\OneToOneTagValueNode;
|
||||
use Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc\DoctrineRelationTagValueNodeInterface;
|
||||
use Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc\ToManyTagNodeInterface;
|
||||
use Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc\ToOneTagNodeInterface;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Rector\RectorDefinition\RectorDefinition;
|
||||
|
@ -5,13 +5,13 @@ namespace Rector\Doctrine\Rector\Property;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Property_\ColumnTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Property_\GeneratedValueTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\JMS\SerializerTypeTagValueNode;
|
||||
use Rector\Doctrine\ValueObject\DoctrineClass;
|
||||
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\Property_\ColumnTagValueNode;
|
||||
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\Property_\GeneratedValueTagValueNode;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Rector\RectorDefinition\RectorDefinition;
|
||||
use Rector\Symfony\PhpDocParser\Ast\PhpDoc\SerializerTypeTagValueNode;
|
||||
|
||||
/**
|
||||
* @sponsor Thanks https://spaceflow.io/ for sponsoring this rule - visit them on https://github.com/SpaceFlow-app
|
||||
|
@ -4,7 +4,7 @@ namespace Rector\Doctrine\Rector\Property;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\Property_\ColumnTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Property_\ColumnTagValueNode;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Rector\RectorDefinition\RectorDefinition;
|
||||
|
||||
|
@ -4,7 +4,7 @@ namespace Rector\Doctrine\Rector\Property;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc\DoctrineRelationTagValueNodeInterface;
|
||||
use Rector\BetterPhpDocParser\Contract\Doctrine\DoctrineRelationTagValueNodeInterface;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Rector\RectorDefinition\RectorDefinition;
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user