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

Add comments for FusionReplacePrototypeNameRector if needed #51

Merged
merged 2 commits into from
Apr 22, 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
12 changes: 8 additions & 4 deletions config/set/contentrepository-90.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,14 @@
]);

$rectorConfig->ruleWithConfiguration(FusionReplacePrototypeNameRector::class, [
new FusionPrototypeNameReplacement('Neos.Fusion:Array' , 'Neos.Fusion:Join'),
new FusionPrototypeNameReplacement('Neos.Fusion:RawArray' , 'Neos.Fusion:DataStructure'),
new FusionPrototypeNameReplacement('Neos.Fusion:Collection' , 'Neos.Fusion:Loop'),
new FusionPrototypeNameReplacement('Neos.Fusion:RawCollection', 'Neos.Fusion:Map'),
new FusionPrototypeNameReplacement('Neos.Fusion:Array', 'Neos.Fusion:Join'),
new FusionPrototypeNameReplacement('Neos.Fusion:RawArray', 'Neos.Fusion:DataStructure'),
new FusionPrototypeNameReplacement('Neos.Fusion:Collection', 'Neos.Fusion:Loop',
'Migration of Neos.Fusion:Collection to Neos.Fusion:Loop needs manual action. The key `children` has to be renamed to `items` which cannot be done automatically'
),
new FusionPrototypeNameReplacement('Neos.Fusion:RawCollection', 'Neos.Fusion:Map',
'Migration of Neos.Fusion:RawCollection to Neos.Fusion:Map needs manual action. The key `children` has to be renamed to `items` which cannot be done automatically'
),
]);


Expand Down
12 changes: 11 additions & 1 deletion src/Generic/Rules/FusionReplacePrototypeNameRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,20 @@ public function getRuleDefinition(): RuleDefinition

public function refactorFileContent(string $fileContent): string
{
$comments = [];
foreach ($this->fusionPrototypeNameReplacements as $fusionPrototypeNameReplacement) {
$replacementCount = 0;
$pattern = '/(^|[=\s\(<\/])(' .$fusionPrototypeNameReplacement->oldName. ')([\s\{\)\/>]|$)/';
$replacement = '$1'.$fusionPrototypeNameReplacement->newName.'$3';
$fileContent = preg_replace($pattern, $replacement, $fileContent);
$fileContent = preg_replace($pattern, $replacement, $fileContent, count: $replacementCount);

if($replacementCount > 0 && $fusionPrototypeNameReplacement->comment !== null) {
$comments[] = '// TODO 9.0 migration:' . $fusionPrototypeNameReplacement->comment;
}
}

if (count($comments) > 0){
$fileContent = implode("\n", $comments) . "\n" . $fileContent;
}

return $fileContent;
Expand Down
1 change: 1 addition & 0 deletions src/Generic/ValueObject/FusionPrototypeNameReplacement.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class FusionPrototypeNameReplacement
public function __construct(
public readonly string $oldName,
public readonly string $newName,
public readonly ?string $comment = null
) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ prototype(Neos.Neos:SomethingOld) < prototype(Neos.Neos:Raw) {
renderer = Neos.Neos:Raw {

old = Neos.Neos:SomethingOld
older = Neos.Neos:SomethingOlder

renderer = afx`
<Neos.Neos:SomethingOld foo=""></Neos.Neos:SomethingOld>
Expand All @@ -15,6 +16,8 @@ prototype(Neos.Neos:SomethingOld) < prototype(Neos.Neos:Raw) {
}
}
-----
// TODO 9.0 migration:Neos.Neos:Raw: This comment should be added on top of the file.
// TODO 9.0 migration:Neos.Neos:SomethingOlder: This comment should be added on top of the file.
prototype(Neos.Neos:SomethingNew) < prototype(Neos.Neos:NewRaw) {

raw = Neos.Neos:NewRaw
Expand All @@ -23,6 +26,7 @@ prototype(Neos.Neos:SomethingNew) < prototype(Neos.Neos:NewRaw) {
renderer = Neos.Neos:NewRaw {

old = Neos.Neos:SomethingNew
older = Neos.Neos:SomethingNewer

renderer = afx`
<Neos.Neos:SomethingNew foo=""></Neos.Neos:SomethingNew>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
$rectorConfig->disableParallel(); // does not work for fusion files - see https://github.com/rectorphp/rector-src/pull/2597#issuecomment-1190120688

$rectorConfig->ruleWithConfiguration(FusionReplacePrototypeNameRector::class, [
new FusionPrototypeNameReplacement('Neos.Neos:Raw', 'Neos.Neos:NewRaw'),
new FusionPrototypeNameReplacement('Neos.Neos:Raw', 'Neos.Neos:NewRaw', 'Neos.Neos:Raw: This comment should be added on top of the file.'),
new FusionPrototypeNameReplacement('Neos.Neos:NotExisting', 'Neos.Neos:NewNotExisting', 'Neos.Neos:NotExisting: This comment should NOT be added on top of the file.'),
new FusionPrototypeNameReplacement('Neos.Neos:SomethingOld', 'Neos.Neos:SomethingNew'),
new FusionPrototypeNameReplacement('Neos.Neos:SomethingOlder', 'Neos.Neos:SomethingNewer', 'Neos.Neos:SomethingOlder: This comment should be added on top of the file.'),
]);
};
Loading