Skip to content

Commit

Permalink
[FEATURE] Add template for yaml based rectors
Browse files Browse the repository at this point in the history
It is now possible to generate yaml rectors
  • Loading branch information
simonschaufi committed Oct 12, 2023
1 parent 7f67a36 commit 666dcd9
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ insert_final_newline = true

[tabs.txt]
indent_style = tab

[*.yaml.inc]
indent_size = 2
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

finishers:
-
options:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
TYPO3:
CMS:
Form:
prototypes:
standard:
formElementsDefinition:
Form:
renderingOptions:
translation:
translationFile:
10: 'EXT:form/Resources/Private/Language/locallang.xlf'
20: 'EXT:myextension/Resources/Private/Language/locallang.xlf'
CMS:
Form:
prototypes:
standard:
formElementsDefinition:
Form:
renderingOptions:
translation:
translationFile:
10: 'EXT:form/Resources/Private/Language/locallang.xlf'
20: 'EXT:myextension/Resources/Private/Language/locallang.xlf'
-----
TYPO3:
CMS:
Form:
prototypes:
standard:
formElementsDefinition:
Form:
renderingOptions:
translation:
translationFiles:
20: 'EXT:myextension/Resources/Private/Language/locallang.xlf'
CMS:
Form:
prototypes:
standard:
formElementsDefinition:
Form:
renderingOptions:
translation:
translationFiles:
20: 'EXT:myextension/Resources/Private/Language/locallang.xlf'
1 change: 1 addition & 0 deletions utils/generator/src/Command/Typo3GenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ private function askForType(): Question
'tca',
'flexform',
'typoscript',
'yaml',
], 0);
$question->setMaxAttempts(3);
$question->setErrorMessage('Type %s is invalid.');
Expand Down
3 changes: 3 additions & 0 deletions utils/generator/src/Finder/TemplateFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ private function addRuleAndTestCase(string $type): array
case 'typoscript':
$filePaths[] = __DIR__ . '/../../templates/tests/Rector/__Major__/__Minor__/' . $type . '/__Test_Directory__/Fixture/fixture.typoscript.inc';
break;
case 'yaml':
$filePaths[] = __DIR__ . '/../../templates/tests/Rector/__Major__/__Minor__/' . $type . '/__Test_Directory__/Fixture/fixture.yaml.inc';
break;
default:
$filePaths[] = __DIR__ . '/../../templates/tests/Rector/__Major__/__Minor__/' . $type . '/__Test_Directory__/Fixture/fixture.php.inc';
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace Ssch\TYPO3Rector\Rector\__Major__\__Minor__\__Type__;

use Ssch\TYPO3Rector\Contract\FileProcessor\Yaml\Form\FormYamlRectorInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

/**
* @changelog __Changelog_Url__
* @see \Ssch\TYPO3Rector\Tests\Rector\__Major__\__Minor__\__Type__\__Test_Directory__\__Name__Test
*/
final class __Name__ implements FormYamlRectorInterface
{
/**
* @param mixed[] $yaml
*/
public function refactor(array $yaml): array
{
// Your code here

return $yaml;
}

/**
* @codeCoverageIgnore
*/
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition('__Description__', [new CodeSample(
<<<'CODE_SAMPLE'
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
CODE_SAMPLE
)]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
TYPO3:
CMS:
Form:
prototypes:
standard:
finishersDefinition:
EmailToReceiver:
FormEngine:
elements:
recipients:
el:
_arrayContainer:
el:
email:
TCEforms:
label: tt_content.finishersDefinition.EmailToSender.recipients.email.label
config:
type: input
-----
TYPO3:
CMS:
Form:
prototypes:
standard:
finishersDefinition:
EmailToReceiver:
FormEngine:
elements:
recipients:
el:
_arrayContainer:
el:
email:
label: tt_content.finishersDefinition.EmailToSender.recipients.email.label
config:
type: input
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace Ssch\TYPO3Rector\Tests\Rector\__Major__\__Minor__\__Type__\__Test_Directory__;

use Iterator;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;

final class __Name__Test extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
public function test(string $filePath): void
{
$this->doTestFile($filePath);
}

/**
* @return Iterator<array<string>>
*/
public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture', '*.yaml.inc');
}

public function provideConfigFilePath(): string
{
return __DIR__ . '/config/configured_rule.php';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Ssch\TYPO3Rector\Rector\__Major__\__Minor__\__Type__\__Name__;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../../../../../../../config/config_test.php');
$rectorConfig->rule(__Name__::class);
};

0 comments on commit 666dcd9

Please sign in to comment.