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
1 change: 1 addition & 0 deletions config/set/knplabs/doctrine-gedmo-to-knplabs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
services:
Rector\DoctrineGedmoToKnplabs\Rector\Class_\TimestampableBehaviorRector: null
Rector\DoctrineGedmoToKnplabs\Rector\Class_\SluggableBehaviorRector: null
Rector\DoctrineGedmoToKnplabs\Rector\Class_\TreeBehaviorRector: ~
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Rector\BetterPhpDocParser\PhpDocNode\Gedmo;

use Gedmo\Mapping\Annotation\TreeLeft;
use Rector\BetterPhpDocParser\PhpDocNode\AbstractTagValueNode;

final class TreeLeftTagValueNode extends AbstractTagValueNode
{
/**
* @var string
*/
public const CLASS_NAME = TreeLeft::class;

public function __toString(): string
{
return '';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Rector\BetterPhpDocParser\PhpDocNode\Gedmo;

use Gedmo\Mapping\Annotation\TreeLevel;
use Rector\BetterPhpDocParser\PhpDocNode\AbstractTagValueNode;

final class TreeLevelTagValueNode extends AbstractTagValueNode
{
/**
* @var string
*/
public const CLASS_NAME = TreeLevel::class;

public function __toString(): string
{
return '';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Rector\BetterPhpDocParser\PhpDocNode\Gedmo;

use Gedmo\Mapping\Annotation\TreeParent;
use Rector\BetterPhpDocParser\PhpDocNode\AbstractTagValueNode;

final class TreeParentTagValueNode extends AbstractTagValueNode
{
/**
* @var string
*/
public const CLASS_NAME = TreeParent::class;

public function __toString(): string
{
return '';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Rector\BetterPhpDocParser\PhpDocNode\Gedmo;

use Gedmo\Mapping\Annotation\TreeRight;
use Rector\BetterPhpDocParser\PhpDocNode\AbstractTagValueNode;

final class TreeRightTagValueNode extends AbstractTagValueNode
{
/**
* @var string
*/
public const CLASS_NAME = TreeRight::class;

public function __toString(): string
{
return '';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Rector\BetterPhpDocParser\PhpDocNode\Gedmo;

use Gedmo\Mapping\Annotation\TreeRoot;
use Rector\BetterPhpDocParser\PhpDocNode\AbstractTagValueNode;

final class TreeRootTagValueNode extends AbstractTagValueNode
{
/**
* @var string
*/
public const CLASS_NAME = TreeRoot::class;

public function __toString(): string
{
return '';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Rector\BetterPhpDocParser\PhpDocNode\Gedmo;

use Gedmo\Mapping\Annotation\Tree;
use Rector\BetterPhpDocParser\PhpDocNode\AbstractTagValueNode;

final class TreeTagValueNode extends AbstractTagValueNode
{
/**
* @var string
*/
public const CLASS_NAME = Tree::class;

/**
* @var string
*/
private $type;

public function __construct(string $type)
{
$this->type = $type;
}

public function __toString(): string
{
return sprintf('(type="%s")', $this->type);
}

public function getType(): string
{
return $this->type;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace Rector\BetterPhpDocParser\PhpDocNodeFactory;

use Doctrine\ORM\Mapping\Annotation;
use PhpParser\Node;
use PhpParser\Node\Stmt\Property;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;

abstract class AbstractBasicPropertyPhpDocNodeFactory extends AbstractPhpDocNodeFactory
{
protected function createFromNode(Node $node): ?PhpDocTagValueNode
{
if (! $node instanceof Property) {
return null;
}

/** @var Annotation|null $annotation */
$annotation = $this->nodeAnnotationReader->readPropertyAnnotation($node, $this->getClass());
if ($annotation === null) {
return null;
}

$getTagValueNodeClass = $this->getTagValueNodeClass();
return new $getTagValueNodeClass();
}

abstract protected function getTagValueNodeClass(): string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Rector\BetterPhpDocParser\PhpDocNodeFactory\Gedmo;

use Gedmo\Mapping\Annotation\TreeLeft;
use PhpParser\Node;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
use PHPStan\PhpDocParser\Parser\TokenIterator;
use Rector\BetterPhpDocParser\PhpDocNode\Gedmo\TreeLeftTagValueNode;
use Rector\BetterPhpDocParser\PhpDocNodeFactory\AbstractBasicPropertyPhpDocNodeFactory;

final class TreeLeftPhpDocNodeFactory extends AbstractBasicPropertyPhpDocNodeFactory
{
public function getClass(): string
{
return TreeLeft::class;
}

/**
* @return TreeLeftTagValueNode|null
*/
public function createFromNodeAndTokens(Node $node, TokenIterator $tokenIterator): ?PhpDocTagValueNode
{
return $this->createFromNode($node);
}

protected function getTagValueNodeClass(): string
{
return TreeLeftTagValueNode::class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Rector\BetterPhpDocParser\PhpDocNodeFactory\Gedmo;

use Gedmo\Mapping\Annotation\TreeLevel;
use PhpParser\Node;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
use PHPStan\PhpDocParser\Parser\TokenIterator;
use Rector\BetterPhpDocParser\PhpDocNode\Gedmo\TreeLevelTagValueNode;
use Rector\BetterPhpDocParser\PhpDocNodeFactory\AbstractBasicPropertyPhpDocNodeFactory;

final class TreeLevelPhpDocNodeFactory extends AbstractBasicPropertyPhpDocNodeFactory
{
public function getClass(): string
{
return TreeLevel::class;
}

/**
* @return TreeLevelTagValueNode|null
*/
public function createFromNodeAndTokens(Node $node, TokenIterator $tokenIterator): ?PhpDocTagValueNode
{
return $this->createFromNode($node);
}

protected function getTagValueNodeClass(): string
{
return TreeLevelTagValueNode::class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Rector\BetterPhpDocParser\PhpDocNodeFactory\Gedmo;

use Gedmo\Mapping\Annotation\TreeParent;
use PhpParser\Node;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
use PHPStan\PhpDocParser\Parser\TokenIterator;
use Rector\BetterPhpDocParser\PhpDocNode\Gedmo\TreeParentTagValueNode;
use Rector\BetterPhpDocParser\PhpDocNodeFactory\AbstractBasicPropertyPhpDocNodeFactory;

final class TreeParentPhpDocNodeFactory extends AbstractBasicPropertyPhpDocNodeFactory
{
public function getClass(): string
{
return TreeParent::class;
}

/**
* @return TreeParentTagValueNode|null
*/
public function createFromNodeAndTokens(Node $node, TokenIterator $tokenIterator): ?PhpDocTagValueNode
{
return $this->createFromNode($node);
}

protected function getTagValueNodeClass(): string
{
return TreeParentTagValueNode::class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace Rector\BetterPhpDocParser\PhpDocNodeFactory\Gedmo;

use Gedmo\Mapping\Annotation\Tree;
use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
use PHPStan\PhpDocParser\Parser\TokenIterator;
use Rector\BetterPhpDocParser\PhpDocNode\Gedmo\TreeTagValueNode;
use Rector\BetterPhpDocParser\PhpDocNodeFactory\AbstractPhpDocNodeFactory;

final class TreePhpDocNodeFactory extends AbstractPhpDocNodeFactory
{
public function getClass(): string
{
return Tree::class;
}

/**
* @return TreeTagValueNode|null
*/
public function createFromNodeAndTokens(Node $node, TokenIterator $tokenIterator): ?PhpDocTagValueNode
{
if (! $node instanceof Class_) {
return null;
}

/** @var Tree|null $tree */
$tree = $this->nodeAnnotationReader->readClassAnnotation($node, $this->getClass());
if ($tree === null) {
return null;
}

return new TreeTagValueNode($tree->type);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Rector\BetterPhpDocParser\PhpDocNodeFactory\Gedmo;

use Gedmo\Mapping\Annotation\TreeRight;
use PhpParser\Node;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
use PHPStan\PhpDocParser\Parser\TokenIterator;
use Rector\BetterPhpDocParser\PhpDocNode\Gedmo\TreeRightTagValueNode;
use Rector\BetterPhpDocParser\PhpDocNodeFactory\AbstractBasicPropertyPhpDocNodeFactory;

final class TreeRightPhpDocNodeFactory extends AbstractBasicPropertyPhpDocNodeFactory
{
public function getClass(): string
{
return TreeRight::class;
}

/**
* @return TreeRightTagValueNode|null
*/
public function createFromNodeAndTokens(Node $node, TokenIterator $tokenIterator): ?PhpDocTagValueNode
{
return $this->createFromNode($node);
}

protected function getTagValueNodeClass(): string
{
return TreeRightTagValueNode::class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Rector\BetterPhpDocParser\PhpDocNodeFactory\Gedmo;

use Gedmo\Mapping\Annotation\TreeRoot;
use PhpParser\Node;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
use PHPStan\PhpDocParser\Parser\TokenIterator;
use Rector\BetterPhpDocParser\PhpDocNode\Gedmo\TreeRootTagValueNode;
use Rector\BetterPhpDocParser\PhpDocNodeFactory\AbstractBasicPropertyPhpDocNodeFactory;

final class TreeRootPhpDocNodeFactory extends AbstractBasicPropertyPhpDocNodeFactory
{
public function getClass(): string
{
return TreeRoot::class;
}

/**
* @return TreeRootTagValueNode|null
*/
public function createFromNodeAndTokens(Node $node, TokenIterator $tokenIterator): ?PhpDocTagValueNode
{
return $this->createFromNode($node);
}

protected function getTagValueNodeClass(): string
{
return TreeRootTagValueNode::class;
}
}
Loading