Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -13,18 +14,57 @@ 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);
}

public function getShortName(): string
{
return '@ORM\GeneratedValue';
}

private function isEmpty(string $annotationContent): bool
{
if ($annotationContent === '') {
return true;
}

return $annotationContent === '()';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}