Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TASK: Correctly migrate Neos\ContentRepository\Utility #69

Merged
merged 1 commit into from
Jun 17, 2024
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
8 changes: 2 additions & 6 deletions config/set/contentrepository-90.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
use Neos\Rector\Generic\Rules\FusionReplacePrototypeNameRector;
use Neos\Rector\Generic\ValueObject\FusionPrototypeNameReplacement;
use Neos\Rector\Generic\ValueObject\FusionPrototypeNameAddComment;
use Neos\Rector\ContentRepository90\Rules\ContentRepositoryUtilityRenderValidNodeNameRector;

return static function (RectorConfig $rectorConfig): void {
// Register FusionFileProcessor. All Fusion Rectors will be auto-registered at this processor.
Expand Down Expand Up @@ -394,12 +395,7 @@
new FusionPrototypeNameAddComment('Neos.Fusion:Attributes', 'TODO 9.0 migration: Neos.Fusion:Attributes has been removed without a replacement. You need to replace it by the property attributes in Neos.Fusion:Tag')
]);

$rectorConfig->ruleWithConfiguration(RenameStaticMethodRector::class, [new RenameStaticMethod(
\Neos\ContentRepository\Utility::class,
'renderValidNodeName',
\Neos\ContentRepository\Core\SharedModel\Node\NodeName::class,
'transliterateFromString'
)]);
$rectorConfig->rule(ContentRepositoryUtilityRenderValidNodeNameRector::class);

/**
* SPECIAL rules
Expand Down
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;
}
}
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';
}
}
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;
}
}

?>
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);
};
Loading