diff --git a/packages/better-php-doc-parser/src/PhpDocNode/Doctrine/Property_/GeneratedValueTagValueNode.php b/packages/better-php-doc-parser/src/PhpDocNode/Doctrine/Property_/GeneratedValueTagValueNode.php index a115d719eedd..7c3d0f923644 100644 --- a/packages/better-php-doc-parser/src/PhpDocNode/Doctrine/Property_/GeneratedValueTagValueNode.php +++ b/packages/better-php-doc-parser/src/PhpDocNode/Doctrine/Property_/GeneratedValueTagValueNode.php @@ -4,6 +4,7 @@ namespace Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Property_; +use Nette\Utils\Strings; use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\AbstractDoctrineTagValueNode; final class GeneratedValueTagValueNode extends AbstractDoctrineTagValueNode @@ -13,13 +14,43 @@ final class GeneratedValueTagValueNode extends AbstractDoctrineTagValueNode */ private $strategy; - public function __construct(string $strategy) + /** + * @var bool + */ + private $isEmpty = false; + + /** + * @var bool + */ + private $hasBrackets = true; + + /** + * @var bool + */ + private $isStrategyExplicit = true; + + public function __construct(string $strategy, ?string $annotationContent = null) { $this->strategy = $strategy; + + if ($annotationContent) { + $this->isStrategyExplicit = (bool) Strings::contains($annotationContent, 'strategy='); + + $this->isEmpty = $this->isEmpty($annotationContent); + $this->hasBrackets = $annotationContent === '()'; + } } public function __toString(): string { + if ($this->isEmpty) { + return $this->hasBrackets ? '()' : ''; + } + + if (! $this->isStrategyExplicit) { + return $this->strategy; + } + return sprintf('(strategy="%s")', $this->strategy); } @@ -27,4 +58,13 @@ public function getShortName(): string { return '@ORM\GeneratedValue'; } + + private function isEmpty(string $annotationContent): bool + { + if ($annotationContent === '') { + return true; + } + + return $annotationContent === '()'; + } } diff --git a/packages/better-php-doc-parser/src/PhpDocNodeFactory/Doctrine/Property_/GeneratedValuePhpDocNodeFactory.php b/packages/better-php-doc-parser/src/PhpDocNodeFactory/Doctrine/Property_/GeneratedValuePhpDocNodeFactory.php index 43a7a14c52b2..c0c5a0dc732d 100644 --- a/packages/better-php-doc-parser/src/PhpDocNodeFactory/Doctrine/Property_/GeneratedValuePhpDocNodeFactory.php +++ b/packages/better-php-doc-parser/src/PhpDocNodeFactory/Doctrine/Property_/GeneratedValuePhpDocNodeFactory.php @@ -33,8 +33,8 @@ public function createFromNodeAndTokens(Node $node, TokenIterator $tokenIterator } // skip tokens for this annotation - $this->resolveContentFromTokenIterator($tokenIterator); + $annotationContent = $this->resolveContentFromTokenIterator($tokenIterator); - return new GeneratedValueTagValueNode($generatedValue->strategy); + return new GeneratedValueTagValueNode($generatedValue->strategy, $annotationContent); } }