Skip to content

Commit

Permalink
!!![TASK] Improve yaml file processor code
Browse files Browse the repository at this point in the history
If you have your own yaml rector rules, then you have to adjust the
namespace of the YamlFileProcessor
  • Loading branch information
simonschaufi committed Dec 3, 2023
1 parent 8663bfd commit 4d5ed23
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 28 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"symfony/polyfill-php80": "^1.26",
"symfony/polyfill-php81": "^1.26",
"symfony/string": "^5.0 || ^6.0",
"symfony/yaml": "^5.0 || ^6.0",
"symplify/smart-file-system": "^9.3 || ^10.0 || ^11.0",
"webmozart/assert": "^1.0"
},
Expand Down
18 changes: 9 additions & 9 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@
$services->load('Ssch\\TYPO3Rector\\', __DIR__ . '/../src')
->exclude([
__DIR__ . '/../src/Rector',
__DIR__ . '/../src/Set',
__DIR__ . '/../src/ValueObject',
__DIR__ . '/../src/AttributeDecorator/ExtbaseValidateAttributeDecorator.php',
__DIR__ . '/../src/FileProcessor/TypoScript/Conditions',
__DIR__ . '/../src/FileProcessor/TypoScript/Rector',
__DIR__ . '/../src/FileProcessor/TypoScript/PostRector',
__DIR__ . '/../src/FileProcessor/Yaml/Form/Rector',
__DIR__ . '/../src/Console/Application/Typo3RectorKernel.php',
__DIR__ . '/../src/FileProcessor/Composer/Rector',
__DIR__ . '/../src/FileProcessor/FlexForms/Rector',
__DIR__ . '/../src/FileProcessor/Resources/Icons/Rector',
__DIR__ . '/../src/FileProcessor/Resources/Files/Rector',
__DIR__ . '/../src/FileProcessor/Fluid/Rector',
__DIR__ . '/../src/Console/Application/Typo3RectorKernel.php',
__DIR__ . '/../src/FileProcessor/Resources/Files/Rector',
__DIR__ . '/../src/FileProcessor/Resources/Icons/Rector',
__DIR__ . '/../src/FileProcessor/TypoScript/Conditions',
__DIR__ . '/../src/FileProcessor/TypoScript/PostRector',
__DIR__ . '/../src/FileProcessor/TypoScript/Rector',
__DIR__ . '/../src/FileProcessor/Yaml/Form/Rector',
__DIR__ . '/../src/Set',
__DIR__ . '/../src/ValueObject',
]);

$services->set(Traverser::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

declare(strict_types=1);

namespace Ssch\TYPO3Rector\Contract\FileProcessor\Yaml\Form;
namespace Ssch\TYPO3Rector\Contract\FileProcessor\Yaml;

use Rector\Core\Contract\Rector\RectorInterface;

interface FormYamlRectorInterface extends RectorInterface
interface YamlRectorInterface extends RectorInterface
{
/**
* @param mixed[] $yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
use Rector\ChangesReporting\ValueObject\RectorWithLineChange;
use Rector\Core\Provider\CurrentFileProvider;
use Rector\Core\ValueObject\Application\File;
use Ssch\TYPO3Rector\Contract\FileProcessor\Yaml\Form\FormYamlRectorInterface;
use Ssch\TYPO3Rector\Contract\FileProcessor\Yaml\YamlRectorInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

/**
* @changelog https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/10.0/Feature-80420-AllowMultipleRecipientsInEmailFinisher.html
* @see \Ssch\TYPO3Rector\Tests\FileProcessor\Yaml\Form\Rector\v10\v0\EmailFinisherRector\EmailFinisherRectorTest
*/
final class EmailFinisherRector implements FormYamlRectorInterface
final class EmailFinisherRector implements YamlRectorInterface
{
/**
* @var string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

namespace Ssch\TYPO3Rector\FileProcessor\Yaml\Form\Rector\v10\v0;

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

/**
* @changelog https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/10.0/Breaking-87009-UseMultipleTranslationFilesByDefaultInEXTform.html
* @see \Ssch\TYPO3Rector\Tests\FileProcessor\Yaml\Form\Rector\v10\v0\TranslationFileRector\TranslationFileRectorTest
*/
final class TranslationFileRector implements FormYamlRectorInterface
final class TranslationFileRector implements YamlRectorInterface
{
/**
* @var string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Ssch\TYPO3Rector\FileProcessor\Yaml\Form;
namespace Ssch\TYPO3Rector\FileProcessor\Yaml;

use Rector\ChangesReporting\ValueObjectFactory\FileDiffFactory;
use Rector\Core\Contract\Processor\FileProcessorInterface;
Expand All @@ -12,12 +12,12 @@
use Rector\Core\ValueObject\Error\SystemError;
use Rector\Core\ValueObject\Reporting\FileDiff;
use Rector\Parallel\ValueObject\Bridge;
use Ssch\TYPO3Rector\Contract\FileProcessor\Yaml\Form\FormYamlRectorInterface;
use Ssch\TYPO3Rector\Contract\FileProcessor\Yaml\YamlRectorInterface;
use Ssch\TYPO3Rector\Helper\SymfonyYamlParser;
use Ssch\TYPO3Rector\ValueObject\Indent;
use Symplify\SmartFileSystem\SmartFileInfo;

final class FormYamlFileProcessor implements FileProcessorInterface
final class YamlFileProcessor implements FileProcessorInterface
{
/**
* @var string[]
Expand All @@ -35,28 +35,28 @@ final class FormYamlFileProcessor implements FileProcessorInterface
private FileDiffFactory $fileDiffFactory;

/**
* @var FormYamlRectorInterface[]
* @var YamlRectorInterface[]
* @readonly
*/
private array $transformer = [];
private array $yamlRectors = [];

/**
* @readonly
*/
private SymfonyYamlParser $symfonyYamlParser;

/**
* @param FormYamlRectorInterface[] $transformer
* @param YamlRectorInterface[] $yamlRectors
*/
public function __construct(
CurrentFileProvider $currentFileProvider,
FileDiffFactory $fileDiffFactory,
SymfonyYamlParser $symfonyYamlParser,
array $transformer
array $yamlRectors
) {
$this->currentFileProvider = $currentFileProvider;
$this->fileDiffFactory = $fileDiffFactory;
$this->transformer = $transformer;
$this->yamlRectors = $yamlRectors;
$this->symfonyYamlParser = $symfonyYamlParser;
}

Expand All @@ -83,8 +83,8 @@ public function process(File $file, Configuration $configuration): array

$newYaml = $yaml;

foreach ($this->transformer as $transformer) {
$newYaml = $transformer->refactor($newYaml);
foreach ($this->yamlRectors as $yamlRector) {
$newYaml = $yamlRector->refactor($newYaml);
}

// Nothing has changed. Early return here.
Expand All @@ -104,7 +104,7 @@ public function process(File $file, Configuration $configuration): array
public function supports(File $file, Configuration $configuration): bool
{
// Prevent unnecessary processing
if ($this->transformer === []) {
if ($this->yamlRectors === []) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

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

use Ssch\TYPO3Rector\Contract\FileProcessor\Yaml\Form\FormYamlRectorInterface;
use Ssch\TYPO3Rector\Contract\FileProcessor\Yaml\YamlRectorInterface;
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
final class __Name__ implements YamlRectorInterface
{
/**
* @param mixed[] $yaml
Expand Down

0 comments on commit 4d5ed23

Please sign in to comment.