-
-
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 #69 from neos/migrate-utility
TASK: Correctly migrate Neos\ContentRepository\Utility
- Loading branch information
Showing
5 changed files
with
127 additions
and
6 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
53 changes: 53 additions & 0 deletions
53
src/ContentRepository90/Rules/ContentRepositoryUtilityRenderValidNodeNameRector.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,53 @@ | ||
<?php | ||
|
||
declare (strict_types=1); | ||
|
||
namespace Neos\Rector\ContentRepository90\Rules; | ||
|
||
use PhpParser\Node; | ||
use PhpParser\Node\Expr\StaticCall; | ||
use PhpParser\Node\Identifier; | ||
use PhpParser\Node\Name\FullyQualified; | ||
use Rector\Core\Rector\AbstractRector; | ||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; | ||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; | ||
use PHPStan\Type\ObjectType; | ||
|
||
final class ContentRepositoryUtilityRenderValidNodeNameRector extends AbstractRector | ||
{ | ||
|
||
public function getRuleDefinition(): RuleDefinition | ||
{ | ||
return new RuleDefinition('Replaces Utility::renderValidNodeName(...) into NodeName::fromString(...)->value.', [new CodeSample('\Neos\ContentRepository\Utility::renderValidNodeName(\'foo\');', '\Neos\ContentRepository\Core\SharedModel\Node\NodeName::fromString(\'foo\')->value;')]); | ||
} | ||
|
||
/** | ||
* @return array<class-string<Node>> | ||
*/ | ||
public function getNodeTypes(): array | ||
{ | ||
return [StaticCall::class]; | ||
} | ||
|
||
/** | ||
* @param StaticCall $node | ||
*/ | ||
public function refactor(Node $node): ?Node | ||
{ | ||
if (!$this->isName($node->name, 'renderValidNodeName')) { | ||
return null; | ||
} | ||
if (!$this->isObjectType($node->class, new ObjectType(\Neos\ContentRepository\Utility::class))) { | ||
return null; | ||
} | ||
$staticCall = $this->rename($node, \Neos\ContentRepository\Core\SharedModel\Node\NodeName::class, 'fromString'); | ||
return $this->nodeFactory->createPropertyFetch($staticCall, 'value'); | ||
} | ||
|
||
private function rename(StaticCall $staticCall, $newClassName, $newMethodName): StaticCall | ||
{ | ||
$staticCall->name = new Identifier($newMethodName); | ||
$staticCall->class = new FullyQualified($newClassName); | ||
return $staticCall; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...itoryUtilityRenderValidNodeNameRector/ContentRepositoryUtilityRenderValidNodeNameTest.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\ContentRepository90\Rules\ContextGetFirstLevelNodeCacheRector; | ||
|
||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class ContentRepositoryUtilityRenderValidNodeNameTest 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'; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...tory90/Rules/ContentRepositoryUtilityRenderValidNodeNameRector/Fixture/some_class.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\ContentRepository\Utility; | ||
|
||
class SomeClass | ||
{ | ||
public function __construct($nodeName) | ||
{ | ||
$nodeName = Utility::renderValidNodeName($nodeName); | ||
$liveNodeName = Utility::renderValidNodeName('live'); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
use Neos\ContentRepository\Utility; | ||
|
||
class SomeClass | ||
{ | ||
public function __construct($nodeName) | ||
{ | ||
$nodeName = \Neos\ContentRepository\Core\SharedModel\Node\NodeName::fromString($nodeName)->value; | ||
$liveNodeName = \Neos\ContentRepository\Core\SharedModel\Node\NodeName::fromString('live')->value; | ||
} | ||
} | ||
|
||
?> |
12 changes: 12 additions & 0 deletions
12
...tory90/Rules/ContentRepositoryUtilityRenderValidNodeNameRector/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,12 @@ | ||
<?php | ||
|
||
declare (strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
use Neos\Rector\Generic\Rules\InjectServiceIfNeededRector; | ||
use Neos\Rector\Generic\ValueObject\AddInjection; | ||
use Neos\Neos\Domain\Service\RenderingModeService; | ||
|
||
return static function (RectorConfig $rectorConfig) : void { | ||
$rectorConfig->rule(\Neos\Rector\ContentRepository90\Rules\ContentRepositoryUtilityRenderValidNodeNameRector::class); | ||
}; |