-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #118 from neos/feature/node-template
FEATURE: Add todo warnings for all NodeTemplate::* methods
- Loading branch information
Showing
9 changed files
with
300 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/Generic/Rules/ObjectInstantiationToWarningCommentRector.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
declare (strict_types=1); | ||
|
||
namespace Neos\Rector\Generic\Rules; | ||
|
||
use Neos\Rector\Generic\ValueObject\ObjectInstantiationToWarningComment; | ||
use Neos\Rector\Utility\CodeSampleLoader; | ||
use PhpParser\Node; | ||
use PhpParser\Node\Name; | ||
use PHPStan\Type\ObjectType; | ||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface; | ||
use Rector\Core\Rector\AbstractRector; | ||
use Rector\NodeTypeResolver\Node\AttributeKey; | ||
use Rector\PostRector\Collector\NodesToAddCollector; | ||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class ObjectInstantiationToWarningCommentRector extends AbstractRector implements ConfigurableRectorInterface | ||
{ | ||
use AllTraits; | ||
|
||
/** | ||
* @var ObjectInstantiationToWarningComment[] | ||
*/ | ||
private array $objectInstantiationToWarningComments = []; | ||
|
||
public function __construct( | ||
private readonly NodesToAddCollector $nodesToAddCollector, | ||
) { | ||
} | ||
|
||
public function getRuleDefinition(): RuleDefinition | ||
{ | ||
return CodeSampleLoader::fromFile('"Warning comments for various non-supported signals', __CLASS__, [ | ||
new ObjectInstantiationToWarningComment(Node::class, '!! This signal "beforeMove" on Node doesn\'t exist anymore') | ||
]); | ||
} | ||
|
||
/** | ||
* @return array<class-string<Node>> | ||
*/ | ||
public function getNodeTypes(): array | ||
{ | ||
return [Name::class]; | ||
} | ||
|
||
/** | ||
* @param \PhpParser\Node\Name $node | ||
*/ | ||
public function refactor(Node $node): ?Node | ||
{ | ||
assert($node instanceof Name); | ||
|
||
if ($node->getAttribute(AttributeKey::PARENT_NODE) instanceof Node\Stmt\UseUse) { | ||
return null; | ||
} | ||
|
||
foreach ($this->objectInstantiationToWarningComments as $objectInstantiationToWarningComment) { | ||
if (!$this->isObjectType($node, new ObjectType($objectInstantiationToWarningComment->className))) { | ||
continue; | ||
} | ||
|
||
$this->nodesToAddCollector->addNodesBeforeNode( | ||
[ | ||
self::todoComment(sprintf($objectInstantiationToWarningComment->warningMessage, $objectInstantiationToWarningComment->className)) | ||
], | ||
$node | ||
); | ||
} | ||
return $node; | ||
} | ||
|
||
|
||
/** | ||
* @param mixed[] $configuration | ||
*/ | ||
public function configure(array $configuration): void | ||
{ | ||
Assert::allIsAOf($configuration, ObjectInstantiationToWarningComment::class); | ||
$this->objectInstantiationToWarningComments = $configuration; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/Generic/ValueObject/ObjectInstantiationToWarningComment.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neos\Rector\Generic\ValueObject; | ||
|
||
class ObjectInstantiationToWarningComment | ||
{ | ||
public function __construct( | ||
public readonly string $className, | ||
public readonly string $warningMessage, | ||
) { | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...s/Generic/Rules/ObjectInstantiationToWarningCommentRector/Fixture/new-object-fqcn.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
use Neos\Flow\Package\Package as BasePackage; | ||
|
||
class Package extends BasePackage | ||
{ | ||
public function boot() | ||
{ | ||
$myComment = new \My\Class\To\Comment(); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
use Neos\Flow\Package\Package as BasePackage; | ||
|
||
class Package extends BasePackage | ||
{ | ||
public function boot() | ||
{ | ||
// TODO 9.0 migration: This is a comment | ||
|
||
$myComment = new \My\Class\To\Comment(); | ||
} | ||
} | ||
|
||
?> |
31 changes: 31 additions & 0 deletions
31
...Generic/Rules/ObjectInstantiationToWarningCommentRector/Fixture/new-object-nested.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
use My\Class\To\Comment; | ||
use Neos\Flow\Package\Package as BasePackage; | ||
|
||
class Package extends BasePackage | ||
{ | ||
public function boot() | ||
{ | ||
$author = (new Comment(['author']))->getAutor(); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
use My\Class\To\Comment; | ||
use Neos\Flow\Package\Package as BasePackage; | ||
|
||
class Package extends BasePackage | ||
{ | ||
public function boot() | ||
{ | ||
// TODO 9.0 migration: This is a comment | ||
|
||
$author = (new Comment(['author']))->getAutor(); | ||
} | ||
} | ||
|
||
?> |
31 changes: 31 additions & 0 deletions
31
tests/Generic/Rules/ObjectInstantiationToWarningCommentRector/Fixture/new-object.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
use My\Class\To\Comment; | ||
use Neos\Flow\Package\Package as BasePackage; | ||
|
||
class Package extends BasePackage | ||
{ | ||
public function boot() | ||
{ | ||
$myComment = new Comment(); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
use My\Class\To\Comment; | ||
use Neos\Flow\Package\Package as BasePackage; | ||
|
||
class Package extends BasePackage | ||
{ | ||
public function boot() | ||
{ | ||
// TODO 9.0 migration: This is a comment | ||
|
||
$myComment = new Comment(); | ||
} | ||
} | ||
|
||
?> |
31 changes: 31 additions & 0 deletions
31
...jectInstantiationToWarningCommentRector/ObjectInstantiationToWarningCommentRectorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Neos\Rector\Tests\Generic\Rules\ToStringToPropertyFetchRector; | ||
|
||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class ObjectInstantiationToWarningCommentRectorTest extends AbstractRectorTestCase | ||
{ | ||
/** | ||
* @dataProvider provideData() | ||
*/ | ||
public function test(string $fileInfo): void | ||
{ | ||
$this->doTestFile($fileInfo); | ||
} | ||
|
||
/** | ||
* @return \Iterator<string> | ||
*/ | ||
public function provideData(): \Iterator | ||
{ | ||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule.php'; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
tests/Generic/Rules/ObjectInstantiationToWarningCommentRector/config/configured_rule.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare (strict_types=1); | ||
|
||
use Neos\Rector\Generic\Rules\ObjectInstantiationToWarningCommentRector; | ||
use Neos\Rector\Generic\ValueObject\ObjectInstantiationToWarningComment; | ||
use Rector\Config\RectorConfig; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->ruleWithConfiguration(ObjectInstantiationToWarningCommentRector::class, [ | ||
new ObjectInstantiationToWarningComment(\My\Class\To\Comment::class, 'This is a comment'), | ||
]); | ||
}; |
45 changes: 45 additions & 0 deletions
45
tests/Sets/ContentRepository90/Fixture/node-template.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
use Neos\ContentRepository\Domain\Model\NodeTemplate; | ||
|
||
class SomeClass { | ||
|
||
public function foo() | ||
{ | ||
$nodeTemplate = new NodeTemplate(); | ||
$nodeTemplate->getIdentifier(); | ||
$nodeTemplate->getName(); | ||
$nodeTemplate->getWorkspace(); | ||
$nodeTemplate->setIdentifier(); | ||
$nodeTemplate->setName(); | ||
} | ||
} | ||
----- | ||
<?php | ||
|
||
use Neos\ContentRepository\Domain\Model\NodeTemplate; | ||
|
||
class SomeClass { | ||
|
||
public function foo() | ||
{ | ||
// TODO 9.0 migration: !! NodeTemplate is removed in Neos 9.0. Use the "CreateNodeAggregateWithNode" command to create new nodes or "CreateNodeVariant" command to create variants of an existing node in other dimensions. | ||
|
||
$nodeTemplate = new NodeTemplate(); | ||
// TODO 9.0 migration: !! NodeTemplate::getIdentifier is removed in Neos 9.0. Use the "CreateNodeAggregateWithNode" command to create new nodes or "CreateNodeVariant" command to create variants of an existing node in other dimensions. | ||
|
||
$nodeTemplate->getIdentifier(); | ||
// TODO 9.0 migration: !! NodeTemplate::getName is removed in Neos 9.0. Use the "CreateNodeAggregateWithNode" command to create new nodes or "CreateNodeVariant" command to create variants of an existing node in other dimensions. | ||
|
||
$nodeTemplate->getName(); | ||
// TODO 9.0 migration: !! NodeTemplate::getWorkspace is removed in Neos 9.0. Use the "CreateNodeAggregateWithNode" command to create new nodes or "CreateNodeVariant" command to create variants of an existing node in other dimensions. | ||
|
||
$nodeTemplate->getWorkspace(); | ||
// TODO 9.0 migration: !! NodeTemplate::setIdentifier is removed in Neos 9.0. Use the "CreateNodeAggregateWithNode" command to create new nodes or "CreateNodeVariant" command to create variants of an existing node in other dimensions. | ||
|
||
$nodeTemplate->setIdentifier(); | ||
// TODO 9.0 migration: !! NodeTemplate::setName is removed in Neos 9.0. Use the "CreateNodeAggregateWithNode" command to create new nodes or "CreateNodeVariant" command to create variants of an existing node in other dimensions. | ||
|
||
$nodeTemplate->setName(); | ||
} | ||
} |