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 @@ -9,5 +9,5 @@ interface PhpDocParserExtensionInterface
{
public function matchTag(string $tag): bool;

public function parse(TokenIterator $tokenIterator, string $tag): PhpDocTagValueNode;
public function parse(TokenIterator $tokenIterator, string $tag): ?PhpDocTagValueNode;
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,20 @@ public function parseTag(TokenIterator $tokenIterator): PhpDocTagNode

public function parseTagValue(TokenIterator $tokenIterator, string $tag): PhpDocTagValueNode
{
$tokenIteratorBackup = clone $tokenIterator;

foreach ($this->phpDocParserExtensions as $phpDocParserExtension) {
if (! $phpDocParserExtension->matchTag($tag)) {
continue;
}

return $phpDocParserExtension->parse($tokenIterator, $tag);
$phpDocTagValueNode = $phpDocParserExtension->parse($tokenIterator, $tag);
if ($phpDocTagValueNode !== null) {
return $phpDocTagValueNode;
}
// return back
$tokenIterator = $tokenIteratorBackup;
break;
}

// needed for reference support in params, see https://github.com/rectorphp/rector/issues/1734
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Rector\DoctrinePhpDocParser\Array_\ArrayItemStaticHelper;
use Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc\DoctrineTagNodeInterface;

abstract class AbstractDoctrineTagValueNode implements PhpDocTagValueNode, AttributeAwareNodeInterface, DoctrineTagNodeInterface
abstract class AbstractDoctrineTagValueNode implements AttributeAwareNodeInterface, DoctrineTagNodeInterface
{
use AttributeTrait;

Expand All @@ -20,15 +20,15 @@ abstract class AbstractDoctrineTagValueNode implements PhpDocTagValueNode, Attri
protected $orderedVisibleItems = [];

/**
* @param mixed[] $cascade
* @param mixed[] $item
*/
protected function printCascadeItem(array $cascade): string
protected function printArrayItem(array $item, string $key): string
{
$json = Json::encode($cascade);
$json = Json::encode($item);
$json = Strings::replace($json, '#,#', ', ');
$json = Strings::replace($json, '#\[(.*?)\]#', '{$1}');

return sprintf('cascade=%s', $json);
return sprintf('%s=%s', $key, $json);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ public function __toString(): string
$contentItems = [];

$contentItems['repositoryClass'] = sprintf('repositoryClass="%s"', $this->repositoryClass);

// default value
$contentItems['readOnly'] = sprintf('readOnly=%s', $this->readOnly ? 'true' : 'false');

return $this->printContentItems($contentItems);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function __toString(): string
$contentItems['inversedBy'] = sprintf('inversedBy="%s"', $this->inversedBy);

if ($this->cascade) {
$contentItems['cascade'] = $this->printCascadeItem($this->cascade);
$contentItems['cascade'] = $this->printArrayItem($this->cascade, 'cascade');
}

$contentItems['fetch'] = sprintf('fetch="%s"', $this->fetch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function __toString(): string

$contentItems['targetEntity'] = sprintf('targetEntity="%s"', $this->targetEntity);
if ($this->cascade) {
$contentItems['cascade'] = $this->printCascadeItem($this->cascade);
$contentItems['cascade'] = $this->printArrayItem($this->cascade, 'cascade');
}
$contentItems['fetch'] = sprintf('fetch="%s"', $this->fetch);
$contentItems['inversedBy'] = sprintf('inversedBy="%s"', $this->inversedBy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function __toString(): string
$contentItems['targetEntity'] = sprintf('targetEntity="%s"', $this->targetEntity);

if ($this->cascade) {
$contentItems['cascade'] = $this->printCascadeItem($this->cascade);
$contentItems['cascade'] = $this->printArrayItem($this->cascade, 'cascade');
}
$contentItems['fetch'] = sprintf('fetch="%s"', $this->fetch);
$contentItems['orphanRemoval'] = sprintf('orphanRemoval=%s', $this->orphanRemoval ? 'true' : 'false');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function __toString(): string
$contentItems['inversedBy'] = sprintf('inversedBy="%s"', $this->inversedBy);

if ($this->cascade) {
$contentItems['cascade'] = $this->printCascadeItem($this->cascade);
$contentItems['cascade'] = $this->printArrayItem($this->cascade, 'cascade');
}

$contentItems['fetch'] = sprintf('fetch="%s"', $this->fetch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,10 @@

use Nette\Utils\Json;
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\Contract\Ast\PhpDoc\DoctrineTagNodeInterface;
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\AbstractDoctrineTagValueNode;

final class OrderByTagValueNode implements PhpDocTagValueNode, AttributeAwareNodeInterface, DoctrineTagNodeInterface
final class OrderByTagValueNode extends AbstractDoctrineTagValueNode
{
use AttributeTrait;

/**
* @var mixed[]
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc;

interface DoctrineTagNodeInterface
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;

interface DoctrineTagNodeInterface extends PhpDocTagValueNode
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function matchTag(string $tag): bool
return (bool) Strings::match($tag, '#^@ORM\\\\(\w+)$#');
}

public function parse(TokenIterator $tokenIterator, string $tag): PhpDocTagValueNode
public function parse(TokenIterator $tokenIterator, string $tag): ?PhpDocTagValueNode
{
return $this->ormTagParser->parse($tokenIterator, $tag);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function __construct(
$this->nodeAnnotationReader = $nodeAnnotationReader;
}

public function parse(TokenIterator $tokenIterator, string $tag): PhpDocTagValueNode
public function parse(TokenIterator $tokenIterator, string $tag): ?PhpDocTagValueNode
{
/** @var Class_|Property $node */
$node = $this->currentNodeProvider->getNode();
Expand Down Expand Up @@ -93,7 +93,7 @@ public function parse(TokenIterator $tokenIterator, string $tag): PhpDocTagValue
return $this->createPropertyTagValueNode($tag, $node, $annotationContent);
}

throw new NotImplementedException(__METHOD__ . ' ' . $tag);
return null;
}

/**
Expand Down Expand Up @@ -350,7 +350,6 @@ private function createJoinColumnTagValueNodeFromJoinColumnAnnotation(

private function cleanMultilineAnnotationContent(string $annotationContent): string
{
// @todo record for original * content restoration
return Strings::replace($annotationContent, '#(\s+)\*(\s+)#m', '$1$3');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* @ORM\Entity(readOnly=true, repositoryClass="Rector\DoctrinePhpDocParser\Tests\PhpDocParser\OrmTagParser\Class_\Source\ExistingRepositoryClass")
* @ORM\Entity
* @ORM\Entity()
* @ORM\Table(name="answer")
*/
final class SomeEntity
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
* @ORM\Entity(readOnly=true, repositoryClass="Rector\DoctrinePhpDocParser\Tests\PhpDocParser\OrmTagParser\Class_\Source\ExistingRepositoryClass")
* @ORM\Entity
* @ORM\Entity
* @ORM\Table(name="answer")
*/