From 9a5812a1342ada2420247bfc84cfe6426ee85e1f Mon Sep 17 00:00:00 2001 From: Simon Schaufelberger Date: Mon, 30 Sep 2024 22:01:50 +0200 Subject: [PATCH] [TASK] Downgrade to PHP 7.4 --- .../src/PackagesFileGenerator.php | 25 +++++++-- .../src/ComposerJsonFileProcessor.php | 28 +++++++--- .../src/ErgebnisComposerJsonPrinter.php | 13 +++-- .../ValueObject/EtaOrionisComposerJson.php | 13 +++-- .../src/ValueObject/PackageAndVersion.php | 20 +++++-- .../src/ValueObject/RenamePackage.php | 20 +++++-- .../ValueObject/ReplacePackageAndVersion.php | 16 +++++- .../fractor-fluid/src/FluidFileProcessor.php | 14 +++-- .../AddChangelogDocBlockForFractorRule.php | 22 +++++--- .../src/AbstractTypoScriptFractor.php | 2 +- .../src/Contract/TypoScriptFractor.php | 5 +- .../src/Contract/TypoScriptNodeVisitor.php | 2 +- .../src/TypoScriptFileProcessor.php | 50 ++++++++++++++--- .../src/TypoScriptStatementsIterator.php | 5 +- ...ScriptPrettyPrinterFormatConfiguration.php | 41 +++++++++++--- .../fractor-xml/src/AbstractXmlFractor.php | 5 +- .../src/Contract/DomNodeVisitor.php | 2 +- .../fractor-xml/src/Contract/XmlFractor.php | 2 +- .../fractor-xml/src/DomDocumentIterator.php | 3 +- packages/fractor-xml/src/IndentFactory.php | 13 +++-- .../fractor-xml/src/PrettyXmlFormatter.php | 13 +++-- packages/fractor-xml/src/XmlFileProcessor.php | 35 +++++++++--- .../fractor-yaml/src/YamlFileProcessor.php | 28 +++++++--- packages/fractor/config/application.php | 8 +++ .../fractor/src/Application/FractorRunner.php | 53 ++++++++++++++++--- .../fractor/src/Application/RuleSkipper.php | 20 +++++-- .../Application/ValueObject/AppliedRule.php | 16 ++++-- .../src/Application/ValueObject/File.php | 28 ++++++++-- .../AllowedFileExtensionsResolver.php | 11 +++- .../Configuration/ConfigurationFactory.php | 20 +++++-- .../SkipConfigurationFactory.php | 13 +++-- .../ValueObject/Configuration.php | 45 +++++++++++++--- .../ValueObject/SkipConfiguration.php | 14 +++-- .../src/Configuration/ValueObjectInliner.php | 2 +- .../src/Console/Command/ProcessCommand.php | 26 +++++++-- .../Console/Output/SymfonyConsoleOutput.php | 16 ++++-- packages/fractor/src/Differ/ConsoleDiffer.php | 13 ++++- packages/fractor/src/Differ/DefaultDiffer.php | 5 +- .../Formatter/ColorConsoleDiffFormatter.php | 5 +- .../fractor/src/Differ/ValueObject/Diff.php | 20 +++++-- .../src/Differ/ValueObject/FileDiff.php | 39 +++++++++++--- .../ValueObjectFactory/FileDiffFactory.php | 34 +++++++++--- .../src/FileSystem/FileInfoFactory.php | 13 +++-- .../fractor/src/FileSystem/FilePathHelper.php | 13 +++-- .../fractor/src/FileSystem/FilesFinder.php | 29 +++++++--- .../fractor/src/FileSystem/PathSkipper.php | 20 +++++-- .../FileSystem/Skipper/FileInfoMatcher.php | 24 ++++++--- .../FileSystem/Skipper/FilePathNormalizer.php | 6 +-- .../Skipper/FnMatchPathNormalizer.php | 4 +- .../FileSystem/Skipper/RealpathMatcher.php | 2 +- .../Skipper/SkippedPathsResolver.php | 22 +++++--- .../src/FileSystem/WildcardResolver.php | 4 +- packages/fractor/src/Helper/ArrayUtility.php | 2 +- packages/fractor/src/Helper/StringUtility.php | 2 +- .../FractorsChangelogLinesResolver.php | 13 +++-- .../Reporting/FractorsChangelogResolver.php | 13 +++-- .../src/Testing/Fixture/FixtureSplitter.php | 2 +- .../src/ValueObject/FileProcessResult.php | 11 ++-- packages/fractor/src/ValueObject/Indent.php | 13 +++-- .../fractor/src/ValueObject/ProcessResult.php | 9 +++- ...CacheHashFromTypolinkTypoScriptFractor.php | 11 +++- .../Yaml/TranslationFileYamlFractor.php | 2 +- ...ateEmailFlagToEmailTypeFlexFormFractor.php | 5 +- ...tAndDouble2ToTypeNumberFlexFormFractor.php | 5 +- ...lTypeFolderToTypeFolderFlexFormFractor.php | 5 +- .../MigrateNullFlagFlexFormFractor.php | 5 +- ...dPasswordToPasswordTypeFlexFormFractor.php | 5 +- ...eColorpickerToTypeColorFlexFormFractor.php | 5 +- .../MigrateRequiredFlagFlexFormFractor.php | 5 +- ...grateTypeNoneColsToSizeFlexFormFractor.php | 5 +- ...emoveTceFormsDomElementFlexFormFractor.php | 7 ++- ...rotectEmailAddressesAsciiOptionFractor.php | 5 +- ...eNewContentElementWizardOptionsFractor.php | 5 +- .../RemoveWorkspaceModeOptionsFractor.php | 5 +- ...nameConfigXhtmlDoctypeToDoctypeFractor.php | 5 +- ...RenameTcemainLinkHandlerMailKeyFractor.php | 5 +- ...UseConfigArrayForTSFEPropertiesFractor.php | 9 ++-- .../src/AbstractFlexformFractor.php | 2 +- ...AbstractRemoveTypoScriptSettingFractor.php | 5 +- rector.php | 13 +++-- ...FractorApplicationReleaseVersionWorker.php | 13 +++-- ...FractorApplicationReleaseVersionWorker.php | 20 +++++-- 82 files changed, 854 insertions(+), 260 deletions(-) diff --git a/packages/extension-installer/src/PackagesFileGenerator.php b/packages/extension-installer/src/PackagesFileGenerator.php index 5487142a..57c9cbee 100644 --- a/packages/extension-installer/src/PackagesFileGenerator.php +++ b/packages/extension-installer/src/PackagesFileGenerator.php @@ -21,11 +21,26 @@ private function __construct() {} } PHP; - public function __construct( - private readonly InstalledRepositoryInterface $repository, - private readonly InstallationManager $installationManager, - private readonly string $fileToGenerate - ) { + /** + * @readonly + */ + private InstalledRepositoryInterface $repository; + + /** + * @readonly + */ + private InstallationManager $installationManager; + + /** + * @readonly + */ + private string $fileToGenerate; + + public function __construct(InstalledRepositoryInterface $repository, InstallationManager $installationManager, string $fileToGenerate) + { + $this->repository = $repository; + $this->installationManager = $installationManager; + $this->fileToGenerate = $fileToGenerate; } public function generate(): void diff --git a/packages/fractor-composer-json/src/ComposerJsonFileProcessor.php b/packages/fractor-composer-json/src/ComposerJsonFileProcessor.php index eaf139e7..f79fedd4 100644 --- a/packages/fractor-composer-json/src/ComposerJsonFileProcessor.php +++ b/packages/fractor-composer-json/src/ComposerJsonFileProcessor.php @@ -14,16 +14,32 @@ /** * @implements FileProcessor */ -final readonly class ComposerJsonFileProcessor implements FileProcessor +final class ComposerJsonFileProcessor implements FileProcessor { + /** + * @var iterable + * @readonly + */ + private iterable $rules; + + /** + * @readonly + */ + private ComposerJsonPrinter $composerJsonPrinter; + + /** + * @readonly + */ + private ComposerJsonFactory $composerJsonFactory; + /** * @param iterable $rules */ - public function __construct( - private iterable $rules, - private ComposerJsonPrinter $composerJsonPrinter, - private ComposerJsonFactory $composerJsonFactory - ) { + public function __construct(iterable $rules, ComposerJsonPrinter $composerJsonPrinter, ComposerJsonFactory $composerJsonFactory) + { + $this->rules = $rules; + $this->composerJsonPrinter = $composerJsonPrinter; + $this->composerJsonFactory = $composerJsonFactory; } public function handle(File $file, iterable $appliedRules): void diff --git a/packages/fractor-composer-json/src/ErgebnisComposerJsonPrinter.php b/packages/fractor-composer-json/src/ErgebnisComposerJsonPrinter.php index e3df614a..107b51e8 100644 --- a/packages/fractor-composer-json/src/ErgebnisComposerJsonPrinter.php +++ b/packages/fractor-composer-json/src/ErgebnisComposerJsonPrinter.php @@ -9,11 +9,16 @@ use a9f\FractorComposerJson\Contract\ComposerJsonPrinter; use Ergebnis\Json\Printer\PrinterInterface; -final readonly class ErgebnisComposerJsonPrinter implements ComposerJsonPrinter +final class ErgebnisComposerJsonPrinter implements ComposerJsonPrinter { - public function __construct( - private PrinterInterface $printer - ) { + /** + * @readonly + */ + private PrinterInterface $printer; + + public function __construct(PrinterInterface $printer) + { + $this->printer = $printer; } public function printToString(Indent $indent, ComposerJson $composerJson): string diff --git a/packages/fractor-composer-json/src/ValueObject/EtaOrionisComposerJson.php b/packages/fractor-composer-json/src/ValueObject/EtaOrionisComposerJson.php index dc5ed7ad..32ca9e32 100644 --- a/packages/fractor-composer-json/src/ValueObject/EtaOrionisComposerJson.php +++ b/packages/fractor-composer-json/src/ValueObject/EtaOrionisComposerJson.php @@ -7,11 +7,16 @@ use a9f\Fractor\Application\ValueObject\File; use a9f\FractorComposerJson\Contract\ComposerJson; -final readonly class EtaOrionisComposerJson implements ComposerJson +final class EtaOrionisComposerJson implements ComposerJson { - public function __construct( - private \EtaOrionis\ComposerJsonManipulator\ComposerJson $composerJson - ) { + /** + * @readonly + */ + private \EtaOrionis\ComposerJsonManipulator\ComposerJson $composerJson; + + public function __construct(\EtaOrionis\ComposerJsonManipulator\ComposerJson $composerJson) + { + $this->composerJson = $composerJson; } public static function fromFile(File $file): self diff --git a/packages/fractor-composer-json/src/ValueObject/PackageAndVersion.php b/packages/fractor-composer-json/src/ValueObject/PackageAndVersion.php index 72240825..7c1a75b7 100644 --- a/packages/fractor-composer-json/src/ValueObject/PackageAndVersion.php +++ b/packages/fractor-composer-json/src/ValueObject/PackageAndVersion.php @@ -4,12 +4,22 @@ namespace a9f\FractorComposerJson\ValueObject; -final readonly class PackageAndVersion +final class PackageAndVersion { - public function __construct( - private string $packageName, - private string $version - ) { + /** + * @readonly + */ + private string $packageName; + + /** + * @readonly + */ + private string $version; + + public function __construct(string $packageName, string $version) + { + $this->packageName = $packageName; + $this->version = $version; } public function getPackageName(): string diff --git a/packages/fractor-composer-json/src/ValueObject/RenamePackage.php b/packages/fractor-composer-json/src/ValueObject/RenamePackage.php index be89982b..fc9b1e2e 100644 --- a/packages/fractor-composer-json/src/ValueObject/RenamePackage.php +++ b/packages/fractor-composer-json/src/ValueObject/RenamePackage.php @@ -4,12 +4,22 @@ namespace a9f\FractorComposerJson\ValueObject; -final readonly class RenamePackage +final class RenamePackage { - public function __construct( - private string $oldPackageName, - private string $newPackageName - ) { + /** + * @readonly + */ + private string $oldPackageName; + + /** + * @readonly + */ + private string $newPackageName; + + public function __construct(string $oldPackageName, string $newPackageName) + { + $this->oldPackageName = $oldPackageName; + $this->newPackageName = $newPackageName; } public function getOldPackageName(): string diff --git a/packages/fractor-composer-json/src/ValueObject/ReplacePackageAndVersion.php b/packages/fractor-composer-json/src/ValueObject/ReplacePackageAndVersion.php index 5aeb33be..02aeb729 100644 --- a/packages/fractor-composer-json/src/ValueObject/ReplacePackageAndVersion.php +++ b/packages/fractor-composer-json/src/ValueObject/ReplacePackageAndVersion.php @@ -7,17 +7,29 @@ use a9f\FractorComposerJson\ChangePackageVersionComposerJsonFractor; use Webmozart\Assert\Assert; -final readonly class ReplacePackageAndVersion +final class ReplacePackageAndVersion { + /** + * @readonly + */ + private string $version; + + /** + * @readonly + */ private string $oldPackageName; + /** + * @readonly + */ private string $newPackageName; public function __construct( string $oldPackageName, string $newPackageName, - private string $version + string $version ) { + $this->version = $version; Assert::notSame( $oldPackageName, $newPackageName, diff --git a/packages/fractor-fluid/src/FluidFileProcessor.php b/packages/fractor-fluid/src/FluidFileProcessor.php index d0fc74bd..19db5147 100644 --- a/packages/fractor-fluid/src/FluidFileProcessor.php +++ b/packages/fractor-fluid/src/FluidFileProcessor.php @@ -12,14 +12,20 @@ /** * @implements FileProcessor */ -final readonly class FluidFileProcessor implements FileProcessor +final class FluidFileProcessor implements FileProcessor { + /** + * @var iterable + * @readonly + */ + private iterable $rules; + /** * @param iterable $rules */ - public function __construct( - private iterable $rules - ) { + public function __construct(iterable $rules) + { + $this->rules = $rules; } public function canHandle(File $file): bool diff --git a/packages/fractor-phpstan-rules/src/Rules/AddChangelogDocBlockForFractorRule.php b/packages/fractor-phpstan-rules/src/Rules/AddChangelogDocBlockForFractorRule.php index 37263241..522e076a 100644 --- a/packages/fractor-phpstan-rules/src/Rules/AddChangelogDocBlockForFractorRule.php +++ b/packages/fractor-phpstan-rules/src/Rules/AddChangelogDocBlockForFractorRule.php @@ -18,17 +18,27 @@ /** * @implements Rule */ -final readonly class AddChangelogDocBlockForFractorRule implements Rule +final class AddChangelogDocBlockForFractorRule implements Rule { /** * @var string */ public const ERROR_MESSAGE = 'Provide @changelog doc block for "%s" Fractor rule'; - public function __construct( - private ReflectionProvider $reflectionProvider, - private FileTypeMapper $fileTypeMapper - ) { + /** + * @readonly + */ + private ReflectionProvider $reflectionProvider; + + /** + * @readonly + */ + private FileTypeMapper $fileTypeMapper; + + public function __construct(ReflectionProvider $reflectionProvider, FileTypeMapper $fileTypeMapper) + { + $this->reflectionProvider = $reflectionProvider; + $this->fileTypeMapper = $fileTypeMapper; } public function getNodeType(): string @@ -84,7 +94,7 @@ public function processNode(Node $node, Scope $scope): array ); $phpDocString = $resolvedPhpDoc->getPhpDocString(); - if (\str_contains($phpDocString, '@changelog')) { + if (strpos($phpDocString, '@changelog') !== false) { return []; } diff --git a/packages/fractor-typoscript/src/AbstractTypoScriptFractor.php b/packages/fractor-typoscript/src/AbstractTypoScriptFractor.php index b24ce13d..6222b041 100644 --- a/packages/fractor-typoscript/src/AbstractTypoScriptFractor.php +++ b/packages/fractor-typoscript/src/AbstractTypoScriptFractor.php @@ -26,7 +26,7 @@ final public function beforeTraversal(File $file, array $statements): void /** * @return Statement|list|int */ - final public function enterNode(Statement $node): Statement|array|int + final public function enterNode(Statement $node) { $result = $this->refactor($node); diff --git a/packages/fractor-typoscript/src/Contract/TypoScriptFractor.php b/packages/fractor-typoscript/src/Contract/TypoScriptFractor.php index 9fc20f29..c8773614 100644 --- a/packages/fractor-typoscript/src/Contract/TypoScriptFractor.php +++ b/packages/fractor-typoscript/src/Contract/TypoScriptFractor.php @@ -9,5 +9,8 @@ interface TypoScriptFractor extends FractorRule, TypoScriptNodeVisitor { - public function refactor(Statement $statement): null|Statement|int; + /** + * @return null|Statement|int + */ + public function refactor(Statement $statement); } diff --git a/packages/fractor-typoscript/src/Contract/TypoScriptNodeVisitor.php b/packages/fractor-typoscript/src/Contract/TypoScriptNodeVisitor.php index 2a785be2..5376744e 100644 --- a/packages/fractor-typoscript/src/Contract/TypoScriptNodeVisitor.php +++ b/packages/fractor-typoscript/src/Contract/TypoScriptNodeVisitor.php @@ -21,7 +21,7 @@ public function beforeTraversal(File $file, array $statements): void; /** * @return Statement|list|TypoScriptStatementsIterator::* */ - public function enterNode(Statement $node): Statement|array|int; + public function enterNode(Statement $node); public function leaveNode(Statement $node): void; diff --git a/packages/fractor-typoscript/src/TypoScriptFileProcessor.php b/packages/fractor-typoscript/src/TypoScriptFileProcessor.php index 263f62de..443453e7 100644 --- a/packages/fractor-typoscript/src/TypoScriptFileProcessor.php +++ b/packages/fractor-typoscript/src/TypoScriptFileProcessor.php @@ -18,20 +18,54 @@ /** * @implements FileProcessor */ -final readonly class TypoScriptFileProcessor implements FileProcessor +final class TypoScriptFileProcessor implements FileProcessor { + /** + * @var iterable + * @readonly + */ + private iterable $rules; + + /** + * @readonly + */ + private Parser $parser; + + /** + * @readonly + */ + private PrettyPrinter $printer; + + /** + * @readonly + */ + private PrettyPrinterConfigurationFactory $prettyPrinterConfigurationFactory; + + /** + * @readonly + */ + private TypoScriptPrettyPrinterFormatConfiguration $typoScriptPrettyPrinterFormatConfiguration; + + /** + * @readonly + */ private BufferedOutput $output; /** * @param iterable $rules */ public function __construct( - private iterable $rules, - private Parser $parser, - private PrettyPrinter $printer, - private PrettyPrinterConfigurationFactory $prettyPrinterConfigurationFactory, - private TypoScriptPrettyPrinterFormatConfiguration $typoScriptPrettyPrinterFormatConfiguration + iterable $rules, + Parser $parser, + PrettyPrinter $printer, + PrettyPrinterConfigurationFactory $prettyPrinterConfigurationFactory, + TypoScriptPrettyPrinterFormatConfiguration $typoScriptPrettyPrinterFormatConfiguration ) { + $this->rules = $rules; + $this->parser = $parser; + $this->printer = $printer; + $this->prettyPrinterConfigurationFactory = $prettyPrinterConfigurationFactory; + $this->typoScriptPrettyPrinterFormatConfiguration = $typoScriptPrettyPrinterFormatConfiguration; $this->output = new BufferedOutput(); } @@ -59,9 +93,9 @@ public function handle(File $file, iterable $appliedRules): void $newTypoScriptContent = $this->output->fetch(); $typoScriptContent = rtrim($newTypoScriptContent) . "\n"; $file->changeFileContent($typoScriptContent); - } catch (TokenizerException) { + } catch (TokenizerException $exception) { return; - } catch (ParseError) { + } catch (ParseError $exception) { } } diff --git a/packages/fractor-typoscript/src/TypoScriptStatementsIterator.php b/packages/fractor-typoscript/src/TypoScriptStatementsIterator.php index 5b398275..4feb0490 100644 --- a/packages/fractor-typoscript/src/TypoScriptStatementsIterator.php +++ b/packages/fractor-typoscript/src/TypoScriptStatementsIterator.php @@ -11,7 +11,7 @@ use Helmich\TypoScriptParser\Parser\AST\Statement; use Webmozart\Assert\Assert; -final readonly class TypoScriptStatementsIterator +final class TypoScriptStatementsIterator { /** * @var int @@ -20,6 +20,7 @@ /** * @var array + * @readonly */ private iterable $visitors; @@ -75,7 +76,7 @@ private function processStatementList(array $statements): array /** * @return self::*|Statement|list */ - private function traverseNode(Statement $node): int|Statement|array + private function traverseNode(Statement $node) { $lastCalledVisitor = null; $result = $node; diff --git a/packages/fractor-typoscript/src/ValueObject/TypoScriptPrettyPrinterFormatConfiguration.php b/packages/fractor-typoscript/src/ValueObject/TypoScriptPrettyPrinterFormatConfiguration.php index 832f6925..483e0bb9 100644 --- a/packages/fractor-typoscript/src/ValueObject/TypoScriptPrettyPrinterFormatConfiguration.php +++ b/packages/fractor-typoscript/src/ValueObject/TypoScriptPrettyPrinterFormatConfiguration.php @@ -7,15 +7,40 @@ use a9f\FractorTypoScript\Configuration\TypoScriptProcessorOption; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; -final readonly class TypoScriptPrettyPrinterFormatConfiguration +final class TypoScriptPrettyPrinterFormatConfiguration { - public function __construct( - public int $size, - public string $style, - public bool $addClosingGlobal, - public bool $includeEmptyLineBreaks, - public bool $indentConditions - ) { + /** + * @readonly + */ + public int $size; + + /** + * @readonly + */ + public string $style; + + /** + * @readonly + */ + public bool $addClosingGlobal; + + /** + * @readonly + */ + public bool $includeEmptyLineBreaks; + + /** + * @readonly + */ + public bool $indentConditions; + + public function __construct(int $size, string $style, bool $addClosingGlobal, bool $includeEmptyLineBreaks, bool $indentConditions) + { + $this->size = $size; + $this->style = $style; + $this->addClosingGlobal = $addClosingGlobal; + $this->includeEmptyLineBreaks = $includeEmptyLineBreaks; + $this->indentConditions = $indentConditions; } public static function createFromParameterBag(ParameterBagInterface $parameterBag): self diff --git a/packages/fractor-xml/src/AbstractXmlFractor.php b/packages/fractor-xml/src/AbstractXmlFractor.php index ab5d9007..17c99804 100644 --- a/packages/fractor-xml/src/AbstractXmlFractor.php +++ b/packages/fractor-xml/src/AbstractXmlFractor.php @@ -19,7 +19,10 @@ public function beforeTraversal(File $file, \DOMDocument $rootNode): void $this->file = $file; } - public function enterNode(\DOMNode $node): \DOMNode|int + /** + * @return \DOMNode|int + */ + public function enterNode(\DOMNode $node) { Assert::isInstanceOf($this->file, File::class); if (! $this->canHandle($node)) { diff --git a/packages/fractor-xml/src/Contract/DomNodeVisitor.php b/packages/fractor-xml/src/Contract/DomNodeVisitor.php index 9a7a7f96..2028479a 100644 --- a/packages/fractor-xml/src/Contract/DomNodeVisitor.php +++ b/packages/fractor-xml/src/Contract/DomNodeVisitor.php @@ -17,7 +17,7 @@ public function beforeTraversal(File $file, \DOMDocument $rootNode): void; /** * @return \DOMNode|DomDocumentIterator::* */ - public function enterNode(\DOMNode $node): \DOMNode|int; + public function enterNode(\DOMNode $node); public function leaveNode(\DOMNode $node): void; diff --git a/packages/fractor-xml/src/Contract/XmlFractor.php b/packages/fractor-xml/src/Contract/XmlFractor.php index 51159dab..3c5e6af4 100644 --- a/packages/fractor-xml/src/Contract/XmlFractor.php +++ b/packages/fractor-xml/src/Contract/XmlFractor.php @@ -14,5 +14,5 @@ public function canHandle(\DOMNode $node): bool; /** * @return \DOMNode|DomDocumentIterator::*|null */ - public function refactor(\DOMNode $node): \DOMNode|int|null; + public function refactor(\DOMNode $node); } diff --git a/packages/fractor-xml/src/DomDocumentIterator.php b/packages/fractor-xml/src/DomDocumentIterator.php index 36ccb74a..2c7273c5 100644 --- a/packages/fractor-xml/src/DomDocumentIterator.php +++ b/packages/fractor-xml/src/DomDocumentIterator.php @@ -9,7 +9,7 @@ use a9f\FractorXml\Exception\ShouldNotHappenException; use Webmozart\Assert\Assert; -final readonly class DomDocumentIterator +final class DomDocumentIterator { /** * @var int @@ -18,6 +18,7 @@ /** * @var array + * @readonly */ private iterable $visitors; diff --git a/packages/fractor-xml/src/IndentFactory.php b/packages/fractor-xml/src/IndentFactory.php index 16b98d7e..027e8962 100644 --- a/packages/fractor-xml/src/IndentFactory.php +++ b/packages/fractor-xml/src/IndentFactory.php @@ -8,11 +8,16 @@ use a9f\FractorXml\Configuration\XmlProcessorOption; use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface; -final readonly class IndentFactory +final class IndentFactory { - public function __construct( - private ContainerBagInterface $parameterBag - ) { + /** + * @readonly + */ + private ContainerBagInterface $parameterBag; + + public function __construct(ContainerBagInterface $parameterBag) + { + $this->parameterBag = $parameterBag; } public function create(): Indent diff --git a/packages/fractor-xml/src/PrettyXmlFormatter.php b/packages/fractor-xml/src/PrettyXmlFormatter.php index db772e31..a9ecefb7 100644 --- a/packages/fractor-xml/src/PrettyXmlFormatter.php +++ b/packages/fractor-xml/src/PrettyXmlFormatter.php @@ -7,11 +7,16 @@ use a9f\Fractor\ValueObject\Indent; use a9f\FractorXml\Contract\Formatter; -final readonly class PrettyXmlFormatter implements Formatter +final class PrettyXmlFormatter implements Formatter { - public function __construct( - private \PrettyXml\Formatter $prettyXmlFormatter - ) { + /** + * @readonly + */ + private \PrettyXml\Formatter $prettyXmlFormatter; + + public function __construct(\PrettyXml\Formatter $prettyXmlFormatter) + { + $this->prettyXmlFormatter = $prettyXmlFormatter; } public function format(Indent $indent, string $content): string diff --git a/packages/fractor-xml/src/XmlFileProcessor.php b/packages/fractor-xml/src/XmlFileProcessor.php index 728bdd5d..55967f10 100644 --- a/packages/fractor-xml/src/XmlFileProcessor.php +++ b/packages/fractor-xml/src/XmlFileProcessor.php @@ -15,17 +15,38 @@ /** * @implements FileProcessor */ -final readonly class XmlFileProcessor implements FileProcessor +final class XmlFileProcessor implements FileProcessor { + /** + * @readonly + */ + private DomDocumentFactory $domDocumentFactory; + + /** + * @readonly + */ + private Formatter $formatter; + + /** + * @var iterable + * @readonly + */ + private iterable $rules; + + /** + * @readonly + */ + private Indent $indent; + /** * @param iterable $rules */ - public function __construct( - private DomDocumentFactory $domDocumentFactory, - private Formatter $formatter, - private iterable $rules, - private Indent $indent - ) { + public function __construct(DomDocumentFactory $domDocumentFactory, Formatter $formatter, iterable $rules, Indent $indent) + { + $this->domDocumentFactory = $domDocumentFactory; + $this->formatter = $formatter; + $this->rules = $rules; + $this->indent = $indent; } public function canHandle(File $file): bool diff --git a/packages/fractor-yaml/src/YamlFileProcessor.php b/packages/fractor-yaml/src/YamlFileProcessor.php index c990b618..68bf1de7 100644 --- a/packages/fractor-yaml/src/YamlFileProcessor.php +++ b/packages/fractor-yaml/src/YamlFileProcessor.php @@ -15,16 +15,32 @@ /** * @implements FileProcessor */ -final readonly class YamlFileProcessor implements FileProcessor +final class YamlFileProcessor implements FileProcessor { + /** + * @var iterable + * @readonly + */ + private iterable $rules; + + /** + * @readonly + */ + private YamlParser $yamlParser; + + /** + * @readonly + */ + private YamlDumper $yamlDumper; + /** * @param iterable $rules */ - public function __construct( - private iterable $rules, - private YamlParser $yamlParser, - private YamlDumper $yamlDumper - ) { + public function __construct(iterable $rules, YamlParser $yamlParser, YamlDumper $yamlDumper) + { + $this->rules = $rules; + $this->yamlParser = $yamlParser; + $this->yamlDumper = $yamlDumper; } public function canHandle(File $file): bool diff --git a/packages/fractor/config/application.php b/packages/fractor/config/application.php index 3e43219a..2f2437a2 100644 --- a/packages/fractor/config/application.php +++ b/packages/fractor/config/application.php @@ -9,6 +9,7 @@ use a9f\Fractor\Configuration\SkipConfigurationFactory; use a9f\Fractor\Configuration\ValueObject\SkipConfiguration; use a9f\Fractor\Console\Application\FractorApplication; +use a9f\Fractor\Console\Command\ProcessCommand; use a9f\Fractor\Console\Output\OutputFormatterCollector; use a9f\Fractor\Differ\ConsoleDiffer; use a9f\Fractor\Differ\Contract\Differ; @@ -79,6 +80,13 @@ static function (ChildDefinition $definition, AsCommand $attribute): void { } } ); + // PHP 7.4 compatibility + $containerBuilder->register(ProcessCommand::class) + ->addTag('console.command', [ + 'command' => 'process', + 'description' => 'Runs Fractor with the given configuration file', + ]) + ->setAutowired(true); $services->set('parameter_bag', ContainerBag::class) ->args([service('service_container')]) diff --git a/packages/fractor/src/Application/FractorRunner.php b/packages/fractor/src/Application/FractorRunner.php index cb230fe3..ade479db 100644 --- a/packages/fractor/src/Application/FractorRunner.php +++ b/packages/fractor/src/Application/FractorRunner.php @@ -22,19 +22,56 @@ * Main Fractor class. This takes care of collecting a list of files, iterating over them and calling all registered * processors for them. */ -final readonly class FractorRunner +final class FractorRunner { + /** + * @readonly + */ + private FilesFinder $fileFinder; + + /** + * @readonly + */ + private FilesCollector $fileCollector; + + /** + * @var iterable> + * @readonly + */ + private iterable $processors; + + /** + * @readonly + */ + private FileWriter $fileWriter; + + /** + * @readonly + */ + private FileDiffFactory $fileDiffFactory; + + /** + * @readonly + */ + private RuleSkipper $ruleSkipper; + /** * @param iterable> $processors */ public function __construct( - private FilesFinder $fileFinder, - private FilesCollector $fileCollector, - private iterable $processors, - private FileWriter $fileWriter, - private FileDiffFactory $fileDiffFactory, - private RuleSkipper $ruleSkipper + FilesFinder $fileFinder, + FilesCollector $fileCollector, + iterable $processors, + FileWriter $fileWriter, + FileDiffFactory $fileDiffFactory, + RuleSkipper $ruleSkipper ) { + $this->fileFinder = $fileFinder; + $this->fileCollector = $fileCollector; + $this->processors = $processors; + $this->fileWriter = $fileWriter; + $this->fileDiffFactory = $fileDiffFactory; + $this->ruleSkipper = $ruleSkipper; Assert::allIsInstanceOf($this->processors, FileProcessor::class); } @@ -105,7 +142,7 @@ public function run(Output $output, Configuration $configuration): ProcessResult private function filterApplicableRules(iterable $rules, File $file): \Generator { foreach ($rules as $rule) { - if ($this->ruleSkipper->shouldSkip($rule::class, $file->getFilePath())) { + if ($this->ruleSkipper->shouldSkip(get_class($rule), $file->getFilePath())) { continue; } diff --git a/packages/fractor/src/Application/RuleSkipper.php b/packages/fractor/src/Application/RuleSkipper.php index df31285b..afe38f1a 100644 --- a/packages/fractor/src/Application/RuleSkipper.php +++ b/packages/fractor/src/Application/RuleSkipper.php @@ -8,12 +8,22 @@ use a9f\Fractor\Configuration\ValueObject\SkipConfiguration; use a9f\Fractor\FileSystem\Skipper\FileInfoMatcher; -final readonly class RuleSkipper +final class RuleSkipper { - public function __construct( - private SkipConfiguration $configuration, - private FileInfoMatcher $fileInfoMatcher - ) { + /** + * @readonly + */ + private SkipConfiguration $configuration; + + /** + * @readonly + */ + private FileInfoMatcher $fileInfoMatcher; + + public function __construct(SkipConfiguration $configuration, FileInfoMatcher $fileInfoMatcher) + { + $this->configuration = $configuration; + $this->fileInfoMatcher = $fileInfoMatcher; } /** diff --git a/packages/fractor/src/Application/ValueObject/AppliedRule.php b/packages/fractor/src/Application/ValueObject/AppliedRule.php index ec3503e5..e24d228a 100644 --- a/packages/fractor/src/Application/ValueObject/AppliedRule.php +++ b/packages/fractor/src/Application/ValueObject/AppliedRule.php @@ -6,19 +6,25 @@ use a9f\Fractor\Application\Contract\FractorRule; -final readonly class AppliedRule +final class AppliedRule { + /** + * @var class-string + * @readonly + */ + private string $fractorRule; + /** * @param class-string $fractorRule */ - private function __construct( - private string $fractorRule, - ) { + private function __construct(string $fractorRule) + { + $this->fractorRule = $fractorRule; } public static function fromRule(FractorRule $fractorRule): self { - return new self($fractorRule::class); + return new self(get_class($fractorRule)); } /** diff --git a/packages/fractor/src/Application/ValueObject/File.php b/packages/fractor/src/Application/ValueObject/File.php index 3d2458e5..15282b53 100644 --- a/packages/fractor/src/Application/ValueObject/File.php +++ b/packages/fractor/src/Application/ValueObject/File.php @@ -9,15 +9,31 @@ final class File { + /** + * @readonly + */ + private string $filePath; + + private string $content; + private bool $hasChanged = false; private string $originalContent; - private readonly string $directoryName; + /** + * @readonly + */ + private string $directoryName; - private readonly string $fileName; + /** + * @readonly + */ + private string $fileName; - private readonly string $fileExtension; + /** + * @readonly + */ + private string $fileExtension; private ?FileDiff $fileDiff = null; @@ -27,9 +43,11 @@ final class File private array $appliedRules = []; public function __construct( - private readonly string $filePath, - private string $content + string $filePath, + string $content ) { + $this->filePath = $filePath; + $this->content = $content; $this->originalContent = $this->content; $this->directoryName = dirname($this->filePath); $this->fileName = basename($this->filePath); diff --git a/packages/fractor/src/Configuration/AllowedFileExtensionsResolver.php b/packages/fractor/src/Configuration/AllowedFileExtensionsResolver.php index ae8ad938..1ae1c13e 100644 --- a/packages/fractor/src/Configuration/AllowedFileExtensionsResolver.php +++ b/packages/fractor/src/Configuration/AllowedFileExtensionsResolver.php @@ -8,14 +8,21 @@ use a9f\Fractor\Application\Contract\FractorRule; use Webmozart\Assert\Assert; -final readonly class AllowedFileExtensionsResolver +final class AllowedFileExtensionsResolver { + /** + * @var iterable> + * @readonly + */ + private iterable $processors; + /** * @param iterable> $processors */ public function __construct( - private iterable $processors + iterable $processors ) { + $this->processors = $processors; Assert::allIsInstanceOf($this->processors, FileProcessor::class); } diff --git a/packages/fractor/src/Configuration/ConfigurationFactory.php b/packages/fractor/src/Configuration/ConfigurationFactory.php index f601a815..aa74daa1 100644 --- a/packages/fractor/src/Configuration/ConfigurationFactory.php +++ b/packages/fractor/src/Configuration/ConfigurationFactory.php @@ -9,12 +9,22 @@ use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface; use Webmozart\Assert\Assert; -final readonly class ConfigurationFactory +final class ConfigurationFactory { - public function __construct( - private ContainerBagInterface $parameterBag, - private AllowedFileExtensionsResolver $allowedFileExtensionsResolver - ) { + /** + * @readonly + */ + private ContainerBagInterface $parameterBag; + + /** + * @readonly + */ + private AllowedFileExtensionsResolver $allowedFileExtensionsResolver; + + public function __construct(ContainerBagInterface $parameterBag, AllowedFileExtensionsResolver $allowedFileExtensionsResolver) + { + $this->parameterBag = $parameterBag; + $this->allowedFileExtensionsResolver = $allowedFileExtensionsResolver; } public function createFromInput(InputInterface $input): Configuration diff --git a/packages/fractor/src/Configuration/SkipConfigurationFactory.php b/packages/fractor/src/Configuration/SkipConfigurationFactory.php index 2d60c75f..aea300ae 100644 --- a/packages/fractor/src/Configuration/SkipConfigurationFactory.php +++ b/packages/fractor/src/Configuration/SkipConfigurationFactory.php @@ -7,11 +7,16 @@ use a9f\Fractor\Configuration\ValueObject\SkipConfiguration; use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface; -final readonly class SkipConfigurationFactory +final class SkipConfigurationFactory { - public function __construct( - private ContainerBagInterface $parameterBag - ) { + /** + * @readonly + */ + private ContainerBagInterface $parameterBag; + + public function __construct(ContainerBagInterface $parameterBag) + { + $this->parameterBag = $parameterBag; } public function create(): SkipConfiguration diff --git a/packages/fractor/src/Configuration/ValueObject/Configuration.php b/packages/fractor/src/Configuration/ValueObject/Configuration.php index c75dbfe3..a339dfd0 100644 --- a/packages/fractor/src/Configuration/ValueObject/Configuration.php +++ b/packages/fractor/src/Configuration/ValueObject/Configuration.php @@ -9,20 +9,53 @@ /** * This is class is created on runtime and cannot be injected via Dependency Injection */ -final readonly class Configuration +final class Configuration { + /** + * @var string[] + * @readonly + */ + private array $fileExtensions; + + /** + * @var list + * @readonly + */ + private array $paths; + + /** + * @var string[] + * @readonly + */ + private array $skip; + + /** + * @readonly + */ + private bool $dryRun; + + /** + * @readonly + */ + private bool $quiet; + /** * @param string[] $fileExtensions * @param list $paths * @param string[] $skip */ public function __construct( - private array $fileExtensions, - private array $paths, - private array $skip, - private bool $dryRun, - private bool $quiet + array $fileExtensions, + array $paths, + array $skip, + bool $dryRun, + bool $quiet ) { + $this->fileExtensions = $fileExtensions; + $this->paths = $paths; + $this->skip = $skip; + $this->dryRun = $dryRun; + $this->quiet = $quiet; Assert::allStringNotEmpty($this->paths, 'No directories given'); } diff --git a/packages/fractor/src/Configuration/ValueObject/SkipConfiguration.php b/packages/fractor/src/Configuration/ValueObject/SkipConfiguration.php index 88512e18..7d61472c 100644 --- a/packages/fractor/src/Configuration/ValueObject/SkipConfiguration.php +++ b/packages/fractor/src/Configuration/ValueObject/SkipConfiguration.php @@ -4,14 +4,20 @@ namespace a9f\Fractor\Configuration\ValueObject; -final readonly class SkipConfiguration +final class SkipConfiguration { + /** + * @var string[] + * @readonly + */ + private array $skip; + /** * @param string[] $skip */ - public function __construct( - private array $skip - ) { + public function __construct(array $skip) + { + $this->skip = $skip; } /** diff --git a/packages/fractor/src/Configuration/ValueObjectInliner.php b/packages/fractor/src/Configuration/ValueObjectInliner.php index 978af741..5d79f34a 100644 --- a/packages/fractor/src/Configuration/ValueObjectInliner.php +++ b/packages/fractor/src/Configuration/ValueObjectInliner.php @@ -15,7 +15,7 @@ final class ValueObjectInliner * @param object|object[] $object * @return InlineServiceConfigurator|InlineServiceConfigurator[] */ - public static function inline(object | array $object): InlineServiceConfigurator | array + public static function inline($object) { if (is_object($object)) { return self::inlineSingle($object); diff --git a/packages/fractor/src/Console/Command/ProcessCommand.php b/packages/fractor/src/Console/Command/ProcessCommand.php index 78c15236..46742133 100644 --- a/packages/fractor/src/Console/Command/ProcessCommand.php +++ b/packages/fractor/src/Console/Command/ProcessCommand.php @@ -12,21 +12,37 @@ use a9f\Fractor\Console\Output\OutputFormatterCollector; use a9f\Fractor\Console\Output\SymfonyConsoleOutput; use a9f\Fractor\ValueObject\ProcessResult; -use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; -#[AsCommand(name: 'process', description: 'Runs Fractor with the given configuration file')] final class ProcessCommand extends Command { + /** + * @readonly + */ + private FractorRunner $runner; + + /** + * @readonly + */ + private ConfigurationFactory $configurationFactory; + + /** + * @readonly + */ + private OutputFormatterCollector $outputFormatterCollector; + public function __construct( - private readonly FractorRunner $runner, - private readonly ConfigurationFactory $configurationFactory, - private readonly OutputFormatterCollector $outputFormatterCollector + FractorRunner $runner, + ConfigurationFactory $configurationFactory, + OutputFormatterCollector $outputFormatterCollector ) { + $this->runner = $runner; + $this->configurationFactory = $configurationFactory; + $this->outputFormatterCollector = $outputFormatterCollector; parent::__construct(); } diff --git a/packages/fractor/src/Console/Output/SymfonyConsoleOutput.php b/packages/fractor/src/Console/Output/SymfonyConsoleOutput.php index fe259b22..fb546353 100644 --- a/packages/fractor/src/Console/Output/SymfonyConsoleOutput.php +++ b/packages/fractor/src/Console/Output/SymfonyConsoleOutput.php @@ -11,11 +11,16 @@ final class SymfonyConsoleOutput implements Output { + /** + * @readonly + */ + private OutputInterface $output; + private ?ProgressBar $progressBar = null; - public function __construct( - private readonly OutputInterface $output - ) { + public function __construct(OutputInterface $output) + { + $this->output = $output; } public function progressStart(int $max = 0): void @@ -55,6 +60,9 @@ public function listing(array $lines): void private function getProgressBar(): ProgressBar { - return $this->progressBar ?? throw new RuntimeException('The ProgressBar is not started.'); + if (! isset($this->progressBar)) { + throw new RuntimeException('The ProgressBar is not started.'); + } + return $this->progressBar; } } diff --git a/packages/fractor/src/Differ/ConsoleDiffer.php b/packages/fractor/src/Differ/ConsoleDiffer.php index d5763fc9..232e8294 100644 --- a/packages/fractor/src/Differ/ConsoleDiffer.php +++ b/packages/fractor/src/Differ/ConsoleDiffer.php @@ -10,13 +10,22 @@ use SebastianBergmann\Diff\Differ as CoreDiffer; use SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder; -final readonly class ConsoleDiffer implements Differ +final class ConsoleDiffer implements Differ { + /** + * @readonly + */ + private ColorConsoleDiffFormatter $colorConsoleDiffFormatter; + + /** + * @readonly + */ private CoreDiffer $differ; public function __construct( - private ColorConsoleDiffFormatter $colorConsoleDiffFormatter + ColorConsoleDiffFormatter $colorConsoleDiffFormatter ) { + $this->colorConsoleDiffFormatter = $colorConsoleDiffFormatter; $unifiedDiffOutputBuilder = new UnifiedDiffOutputBuilder(); $this->differ = new CoreDiffer($unifiedDiffOutputBuilder); } diff --git a/packages/fractor/src/Differ/DefaultDiffer.php b/packages/fractor/src/Differ/DefaultDiffer.php index 7627b1d0..1159654a 100644 --- a/packages/fractor/src/Differ/DefaultDiffer.php +++ b/packages/fractor/src/Differ/DefaultDiffer.php @@ -9,8 +9,11 @@ use SebastianBergmann\Diff\Differ as CoreDiffer; use SebastianBergmann\Diff\Output\StrictUnifiedDiffOutputBuilder; -final readonly class DefaultDiffer implements Differ +final class DefaultDiffer implements Differ { + /** + * @readonly + */ private CoreDiffer $differ; public function __construct() diff --git a/packages/fractor/src/Differ/Formatter/ColorConsoleDiffFormatter.php b/packages/fractor/src/Differ/Formatter/ColorConsoleDiffFormatter.php index 6dcc2655..d53a395f 100644 --- a/packages/fractor/src/Differ/Formatter/ColorConsoleDiffFormatter.php +++ b/packages/fractor/src/Differ/Formatter/ColorConsoleDiffFormatter.php @@ -7,7 +7,7 @@ use Nette\Utils\Strings; use Symfony\Component\Console\Formatter\OutputFormatter; -final readonly class ColorConsoleDiffFormatter +final class ColorConsoleDiffFormatter { /** * @var string @@ -33,6 +33,9 @@ */ private const NEWLINES_REGEX = "#\n\r|\n#"; + /** + * @readonly + */ private string $template; public function __construct() diff --git a/packages/fractor/src/Differ/ValueObject/Diff.php b/packages/fractor/src/Differ/ValueObject/Diff.php index 7b07f4be..6b0fda8f 100644 --- a/packages/fractor/src/Differ/ValueObject/Diff.php +++ b/packages/fractor/src/Differ/ValueObject/Diff.php @@ -4,12 +4,22 @@ namespace a9f\Fractor\Differ\ValueObject; -final readonly class Diff +final class Diff { - public function __construct( - private string $oldContent, - private string $newContent - ) { + /** + * @readonly + */ + private string $oldContent; + + /** + * @readonly + */ + private string $newContent; + + public function __construct(string $oldContent, string $newContent) + { + $this->oldContent = $oldContent; + $this->newContent = $newContent; } public function getOldContent(): string diff --git a/packages/fractor/src/Differ/ValueObject/FileDiff.php b/packages/fractor/src/Differ/ValueObject/FileDiff.php index 9f7fbe0c..12730054 100644 --- a/packages/fractor/src/Differ/ValueObject/FileDiff.php +++ b/packages/fractor/src/Differ/ValueObject/FileDiff.php @@ -6,7 +6,7 @@ use Nette\Utils\Strings; -final readonly class FileDiff +final class FileDiff { /** * @var string @@ -19,13 +19,36 @@ */ private const FIRST_LINE_REGEX = '#@@(.*?)(?<' . self::FIRST_LINE_KEY . '>\\d+)(.*?)@@#'; - public function __construct( - private string $relativeFilePath, - private string $diff, - private string $diffConsoleFormatted, - /** @var string[] $appliedRules */ - private array $appliedRules = [] - ) { + /** + * @readonly + */ + private string $relativeFilePath; + + /** + * @readonly + */ + private string $diff; + + /** + * @readonly + */ + private string $diffConsoleFormatted; + + /** + * @readonly + * @var string[] + */ + private array $appliedRules = []; + + /** + * @param string[] $appliedRules + */ + public function __construct(string $relativeFilePath, string $diff, string $diffConsoleFormatted, array $appliedRules = []) + { + $this->relativeFilePath = $relativeFilePath; + $this->diff = $diff; + $this->diffConsoleFormatted = $diffConsoleFormatted; + $this->appliedRules = $appliedRules; } public function getRelativeFilePath(): string diff --git a/packages/fractor/src/Differ/ValueObjectFactory/FileDiffFactory.php b/packages/fractor/src/Differ/ValueObjectFactory/FileDiffFactory.php index bd2c41c4..876f045d 100644 --- a/packages/fractor/src/Differ/ValueObjectFactory/FileDiffFactory.php +++ b/packages/fractor/src/Differ/ValueObjectFactory/FileDiffFactory.php @@ -11,14 +11,34 @@ use a9f\Fractor\FileSystem\FilePathHelper; use a9f\Fractor\Reporting\FractorsChangelogLinesResolver; -final readonly class FileDiffFactory +final class FileDiffFactory { - public function __construct( - private DefaultDiffer $defaultDiffer, - private ConsoleDiffer $consoleDiffer, - private FilePathHelper $filePathHelper, - private FractorsChangelogLinesResolver $fractorsChangelogLinesResolver, - ) { + /** + * @readonly + */ + private DefaultDiffer $defaultDiffer; + + /** + * @readonly + */ + private ConsoleDiffer $consoleDiffer; + + /** + * @readonly + */ + private FilePathHelper $filePathHelper; + + /** + * @readonly + */ + private FractorsChangelogLinesResolver $fractorsChangelogLinesResolver; + + public function __construct(DefaultDiffer $defaultDiffer, ConsoleDiffer $consoleDiffer, FilePathHelper $filePathHelper, FractorsChangelogLinesResolver $fractorsChangelogLinesResolver) + { + $this->defaultDiffer = $defaultDiffer; + $this->consoleDiffer = $consoleDiffer; + $this->filePathHelper = $filePathHelper; + $this->fractorsChangelogLinesResolver = $fractorsChangelogLinesResolver; } public function createFileDiff(File $file): FileDiff diff --git a/packages/fractor/src/FileSystem/FileInfoFactory.php b/packages/fractor/src/FileSystem/FileInfoFactory.php index 8a649bfc..d98798c8 100644 --- a/packages/fractor/src/FileSystem/FileInfoFactory.php +++ b/packages/fractor/src/FileSystem/FileInfoFactory.php @@ -8,11 +8,16 @@ use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Finder\SplFileInfo; -final readonly class FileInfoFactory +final class FileInfoFactory { - public function __construct( - private Filesystem $filesystem - ) { + /** + * @readonly + */ + private Filesystem $filesystem; + + public function __construct(Filesystem $filesystem) + { + $this->filesystem = $filesystem; } public function createFileInfoFromPath(string $filePath): SplFileInfo diff --git a/packages/fractor/src/FileSystem/FilePathHelper.php b/packages/fractor/src/FileSystem/FilePathHelper.php index 3ebe26de..376b029a 100644 --- a/packages/fractor/src/FileSystem/FilePathHelper.php +++ b/packages/fractor/src/FileSystem/FilePathHelper.php @@ -8,11 +8,16 @@ use Symfony\Component\Filesystem\Filesystem; use Webmozart\Assert\Assert; -final readonly class FilePathHelper +final class FilePathHelper { - public function __construct( - private Filesystem $filesystem - ) { + /** + * @readonly + */ + private Filesystem $filesystem; + + public function __construct(Filesystem $filesystem) + { + $this->filesystem = $filesystem; } public function relativePath(string $fileRealPath): string diff --git a/packages/fractor/src/FileSystem/FilesFinder.php b/packages/fractor/src/FileSystem/FilesFinder.php index 2699db82..197008a4 100644 --- a/packages/fractor/src/FileSystem/FilesFinder.php +++ b/packages/fractor/src/FileSystem/FilesFinder.php @@ -7,13 +7,28 @@ use Symfony\Component\Finder\Finder; use Webmozart\Assert\Assert; -final readonly class FilesFinder +final class FilesFinder { - public function __construct( - private WildcardResolver $wildcardResolver, - private FileAndDirectoryFilter $fileAndDirectoryFilter, - private PathSkipper $pathSkipper - ) { + /** + * @readonly + */ + private WildcardResolver $wildcardResolver; + + /** + * @readonly + */ + private FileAndDirectoryFilter $fileAndDirectoryFilter; + + /** + * @readonly + */ + private PathSkipper $pathSkipper; + + public function __construct(WildcardResolver $wildcardResolver, FileAndDirectoryFilter $fileAndDirectoryFilter, PathSkipper $pathSkipper) + { + $this->wildcardResolver = $wildcardResolver; + $this->fileAndDirectoryFilter = $fileAndDirectoryFilter; + $this->pathSkipper = $pathSkipper; } /** @@ -45,7 +60,7 @@ public function findFiles(array $source, array $suffixes, bool $sortByName = tru $directories = $this->fileAndDirectoryFilter->filterDirectories($filesAndDirectories); $filteredFilePathsInDirectories = $this->findInDirectories($directories, $suffixes, $sortByName); - return [...$filteredFilePaths, ...$filteredFilePathsInDirectories]; + return array_merge($filteredFilePaths, $filteredFilePathsInDirectories); } /** diff --git a/packages/fractor/src/FileSystem/PathSkipper.php b/packages/fractor/src/FileSystem/PathSkipper.php index 3b683c80..48efaec5 100644 --- a/packages/fractor/src/FileSystem/PathSkipper.php +++ b/packages/fractor/src/FileSystem/PathSkipper.php @@ -7,12 +7,22 @@ use a9f\Fractor\FileSystem\Skipper\FileInfoMatcher; use a9f\Fractor\FileSystem\Skipper\SkippedPathsResolver; -final readonly class PathSkipper +final class PathSkipper { - public function __construct( - private FileInfoMatcher $fileInfoMatcher, - private SkippedPathsResolver $skippedPathsResolver - ) { + /** + * @readonly + */ + private FileInfoMatcher $fileInfoMatcher; + + /** + * @readonly + */ + private SkippedPathsResolver $skippedPathsResolver; + + public function __construct(FileInfoMatcher $fileInfoMatcher, SkippedPathsResolver $skippedPathsResolver) + { + $this->fileInfoMatcher = $fileInfoMatcher; + $this->skippedPathsResolver = $skippedPathsResolver; } /** diff --git a/packages/fractor/src/FileSystem/Skipper/FileInfoMatcher.php b/packages/fractor/src/FileSystem/Skipper/FileInfoMatcher.php index 3553bbe5..070c10cf 100644 --- a/packages/fractor/src/FileSystem/Skipper/FileInfoMatcher.php +++ b/packages/fractor/src/FileSystem/Skipper/FileInfoMatcher.php @@ -4,12 +4,22 @@ namespace a9f\Fractor\FileSystem\Skipper; -final readonly class FileInfoMatcher +final class FileInfoMatcher { - public function __construct( - private FnMatchMatcher $fnMatcher, - private RealpathMatcher $realpathMatcher - ) { + /** + * @readonly + */ + private FnMatchMatcher $fnMatcher; + + /** + * @readonly + */ + private RealpathMatcher $realpathMatcher; + + public function __construct(FnMatchMatcher $fnMatcher, RealpathMatcher $realpathMatcher) + { + $this->fnMatcher = $fnMatcher; + $this->realpathMatcher = $realpathMatcher; } /** @@ -42,11 +52,11 @@ private function doesFilePathMatchPattern(string $filePath, string $ignoredPath) return false; } - if (str_starts_with($filePath, $ignoredPath)) { + if (strncmp($filePath, $ignoredPath, strlen($ignoredPath)) === 0) { return true; } - if (str_ends_with($filePath, $ignoredPath)) { + if (substr_compare($filePath, $ignoredPath, -strlen($ignoredPath)) === 0) { return true; } diff --git a/packages/fractor/src/FileSystem/Skipper/FilePathNormalizer.php b/packages/fractor/src/FileSystem/Skipper/FilePathNormalizer.php index 1a676d08..376d526a 100644 --- a/packages/fractor/src/FileSystem/Skipper/FilePathNormalizer.php +++ b/packages/fractor/src/FileSystem/Skipper/FilePathNormalizer.php @@ -6,7 +6,7 @@ use Nette\Utils\Strings; -final readonly class FilePathNormalizer +final class FilePathNormalizer { /** * @see https://regex101.com/r/d4F5Fm/1 @@ -52,7 +52,7 @@ public function normalizePathAndSchema(string $originalPath): string $normalizedPath = self::normalizeDirectorySeparator((string) $path); $path = Strings::replace($normalizedPath, self::TWO_AND_MORE_SLASHES_REGEX, '/'); - $pathRoot = str_starts_with($path, '/') ? $directorySeparator : ''; + $pathRoot = strncmp($path, '/', strlen('/')) === 0 ? $directorySeparator : ''; $pathParts = explode('/', trim($path, '/')); $normalizedPathParts = $this->normalizePathParts($pathParts, $scheme); @@ -87,7 +87,7 @@ private function normalizePathParts(array $pathParts, string $scheme): array continue; } - if (! \str_ends_with($removedPart, '.phar')) { + if (substr_compare($removedPart, '.phar', -strlen('.phar')) !== 0) { continue; } diff --git a/packages/fractor/src/FileSystem/Skipper/FnMatchPathNormalizer.php b/packages/fractor/src/FileSystem/Skipper/FnMatchPathNormalizer.php index 5a3eae61..92778ad5 100644 --- a/packages/fractor/src/FileSystem/Skipper/FnMatchPathNormalizer.php +++ b/packages/fractor/src/FileSystem/Skipper/FnMatchPathNormalizer.php @@ -8,11 +8,11 @@ final class FnMatchPathNormalizer { public static function normalizeForFnmatch(string $path): string { - if (str_ends_with($path, '*') || str_starts_with($path, '*')) { + if (substr_compare($path, '*', -strlen('*')) === 0 || strncmp($path, '*', strlen('*')) === 0) { return '*' . trim($path, '*') . '*'; } - if (\str_contains($path, '..')) { + if (strpos($path, '..') !== false) { /** @var string|false $realPath */ $realPath = realpath($path); if ($realPath === false) { diff --git a/packages/fractor/src/FileSystem/Skipper/RealpathMatcher.php b/packages/fractor/src/FileSystem/Skipper/RealpathMatcher.php index e487b5e8..c7f7d187 100644 --- a/packages/fractor/src/FileSystem/Skipper/RealpathMatcher.php +++ b/packages/fractor/src/FileSystem/Skipper/RealpathMatcher.php @@ -33,6 +33,6 @@ public function match(string $matchingPath, string $filePath): bool $normalizedMatchingPath = rtrim($normalizedMatchingPath, '/') . '/'; } - return str_starts_with($normalizedFilePath, $normalizedMatchingPath); + return strncmp($normalizedFilePath, $normalizedMatchingPath, strlen($normalizedMatchingPath)) === 0; } } diff --git a/packages/fractor/src/FileSystem/Skipper/SkippedPathsResolver.php b/packages/fractor/src/FileSystem/Skipper/SkippedPathsResolver.php index 81a309ed..23dc0582 100644 --- a/packages/fractor/src/FileSystem/Skipper/SkippedPathsResolver.php +++ b/packages/fractor/src/FileSystem/Skipper/SkippedPathsResolver.php @@ -8,15 +8,25 @@ final class SkippedPathsResolver { + /** + * @readonly + */ + private FilePathNormalizer $filePathNormalizer; + + /** + * @readonly + */ + private SkipConfiguration $skip; + /** * @var null|string[] */ - private null|array $skippedPaths = null; + private ?array $skippedPaths = null; - public function __construct( - private readonly FilePathNormalizer $filePathNormalizer, - private readonly SkipConfiguration $skip - ) { + public function __construct(FilePathNormalizer $filePathNormalizer, SkipConfiguration $skip) + { + $this->filePathNormalizer = $filePathNormalizer; + $this->skip = $skip; } /** @@ -36,7 +46,7 @@ public function resolve(): array continue; } - if (\str_contains((string) $value, '*')) { + if (strpos((string) $value, '*') !== false) { $this->skippedPaths[] = $this->filePathNormalizer->normalizePathAndSchema($value); continue; } diff --git a/packages/fractor/src/FileSystem/WildcardResolver.php b/packages/fractor/src/FileSystem/WildcardResolver.php index f71cd723..70d34597 100644 --- a/packages/fractor/src/FileSystem/WildcardResolver.php +++ b/packages/fractor/src/FileSystem/WildcardResolver.php @@ -16,9 +16,9 @@ public function resolveAllWildcards(array $paths): array { $absolutePathsFound = []; foreach ($paths as $path) { - if (\str_contains($path, '*')) { + if (strpos($path, '*') !== false) { $foundPaths = $this->foundInGlob($path); - $absolutePathsFound = [...$absolutePathsFound, ...$foundPaths]; + $absolutePathsFound = array_merge($absolutePathsFound, $foundPaths); } else { $absolutePathsFound[] = $path; } diff --git a/packages/fractor/src/Helper/ArrayUtility.php b/packages/fractor/src/Helper/ArrayUtility.php index 2c55ce84..11cd6d27 100644 --- a/packages/fractor/src/Helper/ArrayUtility.php +++ b/packages/fractor/src/Helper/ArrayUtility.php @@ -30,6 +30,6 @@ public static function trimExplode(string $delimiter, string $string, bool $remo $result = $temp; } - return array_map(trim(...), $result); + return array_map(\Closure::fromCallable('trim'), $result); } } diff --git a/packages/fractor/src/Helper/StringUtility.php b/packages/fractor/src/Helper/StringUtility.php index 1a3f167a..31779762 100644 --- a/packages/fractor/src/Helper/StringUtility.php +++ b/packages/fractor/src/Helper/StringUtility.php @@ -17,6 +17,6 @@ class StringUtility */ public static function inList(string $list, string $item): bool { - return str_contains(',' . $list . ',', ',' . $item . ','); + return strpos(',' . $list . ',', ',' . $item . ',') !== false; } } diff --git a/packages/fractor/src/Reporting/FractorsChangelogLinesResolver.php b/packages/fractor/src/Reporting/FractorsChangelogLinesResolver.php index 1988068d..db3fe664 100644 --- a/packages/fractor/src/Reporting/FractorsChangelogLinesResolver.php +++ b/packages/fractor/src/Reporting/FractorsChangelogLinesResolver.php @@ -7,11 +7,16 @@ use a9f\Fractor\Application\ValueObject\AppliedRule; use Nette\Utils\Strings; -final readonly class FractorsChangelogLinesResolver +final class FractorsChangelogLinesResolver { - public function __construct( - private FractorsChangelogResolver $fractorsChangelogResolver - ) { + /** + * @readonly + */ + private FractorsChangelogResolver $fractorsChangelogResolver; + + public function __construct(FractorsChangelogResolver $fractorsChangelogResolver) + { + $this->fractorsChangelogResolver = $fractorsChangelogResolver; } /** diff --git a/packages/fractor/src/Reporting/FractorsChangelogResolver.php b/packages/fractor/src/Reporting/FractorsChangelogResolver.php index b4922492..787d133e 100644 --- a/packages/fractor/src/Reporting/FractorsChangelogResolver.php +++ b/packages/fractor/src/Reporting/FractorsChangelogResolver.php @@ -6,11 +6,16 @@ use a9f\Fractor\Application\ValueObject\AppliedRule; -final readonly class FractorsChangelogResolver +final class FractorsChangelogResolver { - public function __construct( - private ChangelogExtractor $changelogExtractor - ) { + /** + * @readonly + */ + private ChangelogExtractor $changelogExtractor; + + public function __construct(ChangelogExtractor $changelogExtractor) + { + $this->changelogExtractor = $changelogExtractor; } /** diff --git a/packages/fractor/src/Testing/Fixture/FixtureSplitter.php b/packages/fractor/src/Testing/Fixture/FixtureSplitter.php index 5cf3eaae..24064f38 100644 --- a/packages/fractor/src/Testing/Fixture/FixtureSplitter.php +++ b/packages/fractor/src/Testing/Fixture/FixtureSplitter.php @@ -10,7 +10,7 @@ final class FixtureSplitter { public static function containsSplit(string $fixtureFileContent): bool { - return str_contains($fixtureFileContent, "-----\n") || str_contains($fixtureFileContent, "-----\r\n"); + return strpos($fixtureFileContent, "-----\n") !== false || strpos($fixtureFileContent, "-----\r\n") !== false; } /** diff --git a/packages/fractor/src/ValueObject/FileProcessResult.php b/packages/fractor/src/ValueObject/FileProcessResult.php index 3cccbebd..e90fde1d 100644 --- a/packages/fractor/src/ValueObject/FileProcessResult.php +++ b/packages/fractor/src/ValueObject/FileProcessResult.php @@ -8,9 +8,14 @@ class FileProcessResult { - public function __construct( - private readonly ?FileDiff $fileDiff - ) { + /** + * @readonly + */ + private ?FileDiff $fileDiff; + + public function __construct(?FileDiff $fileDiff) + { + $this->fileDiff = $fileDiff; } public function getFileDiff(): ?FileDiff diff --git a/packages/fractor/src/ValueObject/Indent.php b/packages/fractor/src/ValueObject/Indent.php index 4a9ca0cb..d0a52857 100644 --- a/packages/fractor/src/ValueObject/Indent.php +++ b/packages/fractor/src/ValueObject/Indent.php @@ -10,7 +10,7 @@ /** * @see https://github.com/ergebnis/json-normalizer/blob/main/src/Format/Indent.php */ -final readonly class Indent +final class Indent { public const STYLE_SPACE = 'space'; @@ -24,9 +24,14 @@ self::STYLE_TAB => "\t", ]; - private function __construct( - private string $value - ) { + /** + * @readonly + */ + private string $value; + + private function __construct(string $value) + { + $this->value = $value; } public static function fromFile(File $file): self diff --git a/packages/fractor/src/ValueObject/ProcessResult.php b/packages/fractor/src/ValueObject/ProcessResult.php index 3b33ffed..f7aa095a 100644 --- a/packages/fractor/src/ValueObject/ProcessResult.php +++ b/packages/fractor/src/ValueObject/ProcessResult.php @@ -9,12 +9,19 @@ class ProcessResult { + /** + * @var FileDiff[] + * @readonly + */ + private array $fileDiffs; + /** * @param FileDiff[] $fileDiffs */ public function __construct( - private readonly array $fileDiffs + array $fileDiffs ) { + $this->fileDiffs = $fileDiffs; Assert::allIsInstanceOf($this->fileDiffs, FileDiff::class); } diff --git a/packages/typo3-fractor/rules/TYPO3v10/TypoScript/RemoveUseCacheHashFromTypolinkTypoScriptFractor.php b/packages/typo3-fractor/rules/TYPO3v10/TypoScript/RemoveUseCacheHashFromTypolinkTypoScriptFractor.php index c7b87164..568c17f7 100644 --- a/packages/typo3-fractor/rules/TYPO3v10/TypoScript/RemoveUseCacheHashFromTypolinkTypoScriptFractor.php +++ b/packages/typo3-fractor/rules/TYPO3v10/TypoScript/RemoveUseCacheHashFromTypolinkTypoScriptFractor.php @@ -17,14 +17,21 @@ */ final class RemoveUseCacheHashFromTypolinkTypoScriptFractor extends AbstractTypoScriptFractor { - public function refactor(Statement $statement): null|Statement|int + /** + * @return null|Statement|int + */ + public function refactor(Statement $statement) { if (! $statement instanceof Assignment) { return $statement; } // for some weird reason, "foo.bar.baz = 1" leads to "relativeName" being "foo.bar.baz" - if (! str_ends_with($statement->object->absoluteName, '.typolink.useCacheHash')) { + if (substr_compare( + $statement->object->absoluteName, + '.typolink.useCacheHash', + -strlen('.typolink.useCacheHash') + ) !== 0) { return $statement; } diff --git a/packages/typo3-fractor/rules/TYPO3v10/Yaml/TranslationFileYamlFractor.php b/packages/typo3-fractor/rules/TYPO3v10/Yaml/TranslationFileYamlFractor.php index 4424fd75..b8a8ab88 100644 --- a/packages/typo3-fractor/rules/TYPO3v10/Yaml/TranslationFileYamlFractor.php +++ b/packages/typo3-fractor/rules/TYPO3v10/Yaml/TranslationFileYamlFractor.php @@ -96,7 +96,7 @@ private function buildNewTranslations(array $oldTranslations): array { return array_filter( $oldTranslations, - static fn ($oldTranslationFile): bool => ! \str_starts_with($oldTranslationFile, 'EXT:form') + static fn ($oldTranslationFile): bool => strncmp($oldTranslationFile, 'EXT:form', strlen('EXT:form')) !== 0 ); } } diff --git a/packages/typo3-fractor/rules/TYPO3v12/FlexForm/MigrateEmailFlagToEmailTypeFlexFormFractor.php b/packages/typo3-fractor/rules/TYPO3v12/FlexForm/MigrateEmailFlagToEmailTypeFlexFormFractor.php index 32727d77..8daf1c5d 100644 --- a/packages/typo3-fractor/rules/TYPO3v12/FlexForm/MigrateEmailFlagToEmailTypeFlexFormFractor.php +++ b/packages/typo3-fractor/rules/TYPO3v12/FlexForm/MigrateEmailFlagToEmailTypeFlexFormFractor.php @@ -33,7 +33,10 @@ public function beforeTraversal(File $file, \DOMDocument $rootNode): void $this->domDocument = $rootNode; } - public function refactor(\DOMNode $node): \DOMNode|int|null + /** + * @return \DOMNode|int|null + */ + public function refactor(\DOMNode $node) { if (! $node instanceof \DOMElement) { return null; diff --git a/packages/typo3-fractor/rules/TYPO3v12/FlexForm/MigrateEvalIntAndDouble2ToTypeNumberFlexFormFractor.php b/packages/typo3-fractor/rules/TYPO3v12/FlexForm/MigrateEvalIntAndDouble2ToTypeNumberFlexFormFractor.php index 49d7daf2..6bb9c73e 100644 --- a/packages/typo3-fractor/rules/TYPO3v12/FlexForm/MigrateEvalIntAndDouble2ToTypeNumberFlexFormFractor.php +++ b/packages/typo3-fractor/rules/TYPO3v12/FlexForm/MigrateEvalIntAndDouble2ToTypeNumberFlexFormFractor.php @@ -43,7 +43,10 @@ public function beforeTraversal(File $file, \DOMDocument $rootNode): void $this->domDocument = $rootNode; } - public function refactor(\DOMNode $node): \DOMNode|int|null + /** + * @return \DOMNode|int|null + */ + public function refactor(\DOMNode $node) { if (! $node instanceof \DOMElement) { return null; diff --git a/packages/typo3-fractor/rules/TYPO3v12/FlexForm/MigrateInternalTypeFolderToTypeFolderFlexFormFractor.php b/packages/typo3-fractor/rules/TYPO3v12/FlexForm/MigrateInternalTypeFolderToTypeFolderFlexFormFractor.php index 8e5dfa45..8c32fed7 100644 --- a/packages/typo3-fractor/rules/TYPO3v12/FlexForm/MigrateInternalTypeFolderToTypeFolderFlexFormFractor.php +++ b/packages/typo3-fractor/rules/TYPO3v12/FlexForm/MigrateInternalTypeFolderToTypeFolderFlexFormFractor.php @@ -31,7 +31,10 @@ public function beforeTraversal(File $file, \DOMDocument $rootNode): void $this->domDocument = $rootNode; } - public function refactor(\DOMNode $node): \DOMNode|int|null + /** + * @return \DOMNode|int|null + */ + public function refactor(\DOMNode $node) { if (! $node instanceof \DOMElement) { return null; diff --git a/packages/typo3-fractor/rules/TYPO3v12/FlexForm/MigrateNullFlagFlexFormFractor.php b/packages/typo3-fractor/rules/TYPO3v12/FlexForm/MigrateNullFlagFlexFormFractor.php index 4ab40d3f..1cdaf318 100644 --- a/packages/typo3-fractor/rules/TYPO3v12/FlexForm/MigrateNullFlagFlexFormFractor.php +++ b/packages/typo3-fractor/rules/TYPO3v12/FlexForm/MigrateNullFlagFlexFormFractor.php @@ -39,7 +39,10 @@ public function beforeTraversal(File $file, \DOMDocument $rootNode): void $this->domDocument = $rootNode; } - public function refactor(\DOMNode $node): \DOMNode|int|null + /** + * @return \DOMNode|int|null + */ + public function refactor(\DOMNode $node) { if (! $node instanceof \DOMElement) { return null; diff --git a/packages/typo3-fractor/rules/TYPO3v12/FlexForm/MigratePasswordAndSaltedPasswordToPasswordTypeFlexFormFractor.php b/packages/typo3-fractor/rules/TYPO3v12/FlexForm/MigratePasswordAndSaltedPasswordToPasswordTypeFlexFormFractor.php index 828b1894..f8ee2eb8 100644 --- a/packages/typo3-fractor/rules/TYPO3v12/FlexForm/MigratePasswordAndSaltedPasswordToPasswordTypeFlexFormFractor.php +++ b/packages/typo3-fractor/rules/TYPO3v12/FlexForm/MigratePasswordAndSaltedPasswordToPasswordTypeFlexFormFractor.php @@ -43,7 +43,10 @@ public function beforeTraversal(File $file, \DOMDocument $rootNode): void $this->domDocument = $rootNode; } - public function refactor(\DOMNode $node): \DOMNode|int|null + /** + * @return \DOMNode|int|null + */ + public function refactor(\DOMNode $node) { if (! $node instanceof \DOMElement) { return null; diff --git a/packages/typo3-fractor/rules/TYPO3v12/FlexForm/MigrateRenderTypeColorpickerToTypeColorFlexFormFractor.php b/packages/typo3-fractor/rules/TYPO3v12/FlexForm/MigrateRenderTypeColorpickerToTypeColorFlexFormFractor.php index b83c5f6f..96db12c8 100644 --- a/packages/typo3-fractor/rules/TYPO3v12/FlexForm/MigrateRenderTypeColorpickerToTypeColorFlexFormFractor.php +++ b/packages/typo3-fractor/rules/TYPO3v12/FlexForm/MigrateRenderTypeColorpickerToTypeColorFlexFormFractor.php @@ -32,7 +32,10 @@ public function beforeTraversal(File $file, \DOMDocument $rootNode): void $this->domDocument = $rootNode; } - public function refactor(\DOMNode $node): \DOMNode|int|null + /** + * @return \DOMNode|int|null + */ + public function refactor(\DOMNode $node) { if (! $node instanceof \DOMElement) { return null; diff --git a/packages/typo3-fractor/rules/TYPO3v12/FlexForm/MigrateRequiredFlagFlexFormFractor.php b/packages/typo3-fractor/rules/TYPO3v12/FlexForm/MigrateRequiredFlagFlexFormFractor.php index 78fd5c5e..af42e1a4 100644 --- a/packages/typo3-fractor/rules/TYPO3v12/FlexForm/MigrateRequiredFlagFlexFormFractor.php +++ b/packages/typo3-fractor/rules/TYPO3v12/FlexForm/MigrateRequiredFlagFlexFormFractor.php @@ -34,7 +34,10 @@ public function beforeTraversal(File $file, \DOMDocument $rootNode): void $this->domDocument = $rootNode; } - public function refactor(\DOMNode $node): \DOMNode|int|null + /** + * @return \DOMNode|int|null + */ + public function refactor(\DOMNode $node) { if (! $node instanceof \DOMElement) { return null; diff --git a/packages/typo3-fractor/rules/TYPO3v12/FlexForm/MigrateTypeNoneColsToSizeFlexFormFractor.php b/packages/typo3-fractor/rules/TYPO3v12/FlexForm/MigrateTypeNoneColsToSizeFlexFormFractor.php index 2c01f52e..978cf1b4 100644 --- a/packages/typo3-fractor/rules/TYPO3v12/FlexForm/MigrateTypeNoneColsToSizeFlexFormFractor.php +++ b/packages/typo3-fractor/rules/TYPO3v12/FlexForm/MigrateTypeNoneColsToSizeFlexFormFractor.php @@ -31,7 +31,10 @@ public function beforeTraversal(File $file, \DOMDocument $rootNode): void $this->domDocument = $rootNode; } - public function refactor(\DOMNode $node): \DOMNode|int|null + /** + * @return \DOMNode|int|null + */ + public function refactor(\DOMNode $node) { if (! $node instanceof \DOMElement) { return null; diff --git a/packages/typo3-fractor/rules/TYPO3v12/FlexForm/RemoveTceFormsDomElementFlexFormFractor.php b/packages/typo3-fractor/rules/TYPO3v12/FlexForm/RemoveTceFormsDomElementFlexFormFractor.php index 03905e82..fa9942cf 100644 --- a/packages/typo3-fractor/rules/TYPO3v12/FlexForm/RemoveTceFormsDomElementFlexFormFractor.php +++ b/packages/typo3-fractor/rules/TYPO3v12/FlexForm/RemoveTceFormsDomElementFlexFormFractor.php @@ -24,7 +24,10 @@ public function canHandle(\DOMNode $node): bool return parent::canHandle($node) && $node->nodeName === 'TCEforms'; } - public function refactor(\DOMNode $node): \DOMNode|int|null + /** + * @return \DOMNode|int|null + */ + public function refactor(\DOMNode $node) { $parent = $node->parentNode; if (! $parent instanceof \DOMNode) { @@ -35,7 +38,7 @@ public function refactor(\DOMNode $node): \DOMNode|int|null $childNodes = iterator_to_array($node->childNodes->getIterator()); foreach ($childNodes as $child) { if (! $child instanceof \DOMNode) { - throw new ShouldNotHappenException(sprintf('Expected DOMNode, got %s', $child::class), 1718997872); + throw new ShouldNotHappenException(sprintf('Expected DOMNode, got %s', get_class($child)), 1718997872); } $parent->insertBefore($child->cloneNode(true), $node); diff --git a/packages/typo3-fractor/rules/TYPO3v12/TypoScript/RemoveConfigSpamProtectEmailAddressesAsciiOptionFractor.php b/packages/typo3-fractor/rules/TYPO3v12/TypoScript/RemoveConfigSpamProtectEmailAddressesAsciiOptionFractor.php index 8dc19987..c13b4bae 100644 --- a/packages/typo3-fractor/rules/TYPO3v12/TypoScript/RemoveConfigSpamProtectEmailAddressesAsciiOptionFractor.php +++ b/packages/typo3-fractor/rules/TYPO3v12/TypoScript/RemoveConfigSpamProtectEmailAddressesAsciiOptionFractor.php @@ -16,7 +16,10 @@ */ final class RemoveConfigSpamProtectEmailAddressesAsciiOptionFractor extends AbstractTypoScriptFractor { - public function refactor(Statement $statement): null|Statement|int + /** + * @return null|Statement|int + */ + public function refactor(Statement $statement) { if (! $statement instanceof Assignment) { return null; diff --git a/packages/typo3-fractor/rules/TYPO3v12/TypoScript/RemoveNewContentElementWizardOptionsFractor.php b/packages/typo3-fractor/rules/TYPO3v12/TypoScript/RemoveNewContentElementWizardOptionsFractor.php index 443392ba..d3d002cd 100644 --- a/packages/typo3-fractor/rules/TYPO3v12/TypoScript/RemoveNewContentElementWizardOptionsFractor.php +++ b/packages/typo3-fractor/rules/TYPO3v12/TypoScript/RemoveNewContentElementWizardOptionsFractor.php @@ -16,7 +16,10 @@ */ final class RemoveNewContentElementWizardOptionsFractor extends AbstractTypoScriptFractor { - public function refactor(Statement $statement): null|Statement|int + /** + * @return null|Statement|int + */ + public function refactor(Statement $statement) { if (! $statement instanceof Assignment) { return null; diff --git a/packages/typo3-fractor/rules/TYPO3v12/TypoScript/RemoveWorkspaceModeOptionsFractor.php b/packages/typo3-fractor/rules/TYPO3v12/TypoScript/RemoveWorkspaceModeOptionsFractor.php index 809ca0f9..c7b83774 100644 --- a/packages/typo3-fractor/rules/TYPO3v12/TypoScript/RemoveWorkspaceModeOptionsFractor.php +++ b/packages/typo3-fractor/rules/TYPO3v12/TypoScript/RemoveWorkspaceModeOptionsFractor.php @@ -16,7 +16,10 @@ */ final class RemoveWorkspaceModeOptionsFractor extends AbstractTypoScriptFractor { - public function refactor(Statement $statement): null|Statement|int + /** + * @return null|Statement|int + */ + public function refactor(Statement $statement) { if (! $statement instanceof Assignment) { return null; diff --git a/packages/typo3-fractor/rules/TYPO3v12/TypoScript/RenameConfigXhtmlDoctypeToDoctypeFractor.php b/packages/typo3-fractor/rules/TYPO3v12/TypoScript/RenameConfigXhtmlDoctypeToDoctypeFractor.php index f208a51a..ac5d164a 100644 --- a/packages/typo3-fractor/rules/TYPO3v12/TypoScript/RenameConfigXhtmlDoctypeToDoctypeFractor.php +++ b/packages/typo3-fractor/rules/TYPO3v12/TypoScript/RenameConfigXhtmlDoctypeToDoctypeFractor.php @@ -15,7 +15,10 @@ */ final class RenameConfigXhtmlDoctypeToDoctypeFractor extends AbstractTypoScriptFractor { - public function refactor(Statement $statement): null|Statement|int + /** + * @return null|Statement|int + */ + public function refactor(Statement $statement) { if (! $statement instanceof Assignment) { return null; diff --git a/packages/typo3-fractor/rules/TYPO3v12/TypoScript/RenameTcemainLinkHandlerMailKeyFractor.php b/packages/typo3-fractor/rules/TYPO3v12/TypoScript/RenameTcemainLinkHandlerMailKeyFractor.php index 3887f156..da75f22e 100644 --- a/packages/typo3-fractor/rules/TYPO3v12/TypoScript/RenameTcemainLinkHandlerMailKeyFractor.php +++ b/packages/typo3-fractor/rules/TYPO3v12/TypoScript/RenameTcemainLinkHandlerMailKeyFractor.php @@ -17,7 +17,10 @@ */ final class RenameTcemainLinkHandlerMailKeyFractor extends AbstractTypoScriptFractor { - public function refactor(Statement $statement): null|Statement|int + /** + * @return null|Statement|int + */ + public function refactor(Statement $statement) { if (! $statement instanceof NestedAssignment && ! $statement instanceof Assignment) { return null; diff --git a/packages/typo3-fractor/rules/TYPO3v12/TypoScript/UseConfigArrayForTSFEPropertiesFractor.php b/packages/typo3-fractor/rules/TYPO3v12/TypoScript/UseConfigArrayForTSFEPropertiesFractor.php index 8c51ac77..f63b1cc9 100644 --- a/packages/typo3-fractor/rules/TYPO3v12/TypoScript/UseConfigArrayForTSFEPropertiesFractor.php +++ b/packages/typo3-fractor/rules/TYPO3v12/TypoScript/UseConfigArrayForTSFEPropertiesFractor.php @@ -23,17 +23,20 @@ final class UseConfigArrayForTSFEPropertiesFractor extends AbstractTypoScriptFra 'baseUrl', ]; - public function refactor(Statement $statement): null|Statement|int + /** + * @return null|Statement + */ + public function refactor(Statement $statement) { if (! $statement instanceof Assignment) { return null; } - if (! str_ends_with($statement->object->absoluteName, '.data')) { + if (substr_compare($statement->object->absoluteName, '.data', -strlen('.data')) !== 0) { return null; } - if (! str_starts_with($statement->value->value, 'TSFE:')) { + if (strncmp($statement->value->value, 'TSFE:', strlen('TSFE:')) !== 0) { return null; } diff --git a/packages/typo3-fractor/src/AbstractFlexformFractor.php b/packages/typo3-fractor/src/AbstractFlexformFractor.php index 27f02051..f8e31b4a 100644 --- a/packages/typo3-fractor/src/AbstractFlexformFractor.php +++ b/packages/typo3-fractor/src/AbstractFlexformFractor.php @@ -11,7 +11,7 @@ abstract class AbstractFlexformFractor extends AbstractXmlFractor { public function canHandle(\DOMNode $node): bool { - $rootNode = $node->ownerDocument?->firstChild; + $rootNode = ($nullsafeVariable1 = $node->ownerDocument) instanceof \DOMDocument ? $nullsafeVariable1->firstChild : null; if ($rootNode === null) { throw new ShouldNotHappenException('Node\'s document does not have a root node'); diff --git a/packages/typo3-fractor/src/AbstractRemoveTypoScriptSettingFractor.php b/packages/typo3-fractor/src/AbstractRemoveTypoScriptSettingFractor.php index 4252b019..d0078d69 100644 --- a/packages/typo3-fractor/src/AbstractRemoveTypoScriptSettingFractor.php +++ b/packages/typo3-fractor/src/AbstractRemoveTypoScriptSettingFractor.php @@ -20,7 +20,10 @@ */ abstract class AbstractRemoveTypoScriptSettingFractor extends AbstractTypoScriptFractor { - final public function refactor(Statement $statement): null|Statement|int + /** + * @return null|Statement|int + */ + final public function refactor(Statement $statement) { if (! $statement instanceof Assignment) { return null; diff --git a/rector.php b/rector.php index bd42b7d8..ba650c20 100644 --- a/rector.php +++ b/rector.php @@ -3,14 +3,21 @@ declare(strict_types=1); use Rector\Config\RectorConfig; +use Rector\Set\ValueObject\DowngradeLevelSetList; return RectorConfig::configure() - ->withPhpSets(php82: true) - ->withPreparedSets(deadCode: true, typeDeclarations: true, earlyReturn: true, strictBooleans: true) + ->withPhpSets(false, false, false, false, true) + ->withSets([DowngradeLevelSetList::DOWN_TO_PHP_74]) + ->withPreparedSets(true, false, false, true, false, false, false, true, true) ->withImportNames(true, true, false, true) ->withSkip([ __DIR__ . '/packages/extension-installer/generated', - __DIR__ . '/packages/fractor-rule-generator/templates', + __DIR__ . '/packages/fractor-rule-generator/', + __DIR__ . '/packages/fractor-doc-generator/', + __DIR__ . '/packages/typo3-fractor/rules/TYPO3v12/FlexForm/', + __DIR__ . '/packages/typo3-fractor/rules/TYPO3v12/TypoScript/', + __DIR__ . '/packages/*/tests/*', + __DIR__ . '/packages/*/rules-tests/*', ]) ->withPaths([ __DIR__ . '/ecs.php', diff --git a/src/Release/ReleaseWorker/DefineFractorApplicationReleaseVersionWorker.php b/src/Release/ReleaseWorker/DefineFractorApplicationReleaseVersionWorker.php index 47a5508e..0cb778b1 100644 --- a/src/Release/ReleaseWorker/DefineFractorApplicationReleaseVersionWorker.php +++ b/src/Release/ReleaseWorker/DefineFractorApplicationReleaseVersionWorker.php @@ -8,11 +8,16 @@ use PharIo\Version\Version; use Symplify\MonorepoBuilder\Release\Contract\ReleaseWorker\ReleaseWorkerInterface; -final readonly class DefineFractorApplicationReleaseVersionWorker implements ReleaseWorkerInterface +final class DefineFractorApplicationReleaseVersionWorker implements ReleaseWorkerInterface { - public function __construct( - private FractorApplicationReleaseWriter $fractorApplicationReleaseWriter - ) { + /** + * @readonly + */ + private FractorApplicationReleaseWriter $fractorApplicationReleaseWriter; + + public function __construct(FractorApplicationReleaseWriter $fractorApplicationReleaseWriter) + { + $this->fractorApplicationReleaseWriter = $fractorApplicationReleaseWriter; } public function getDescription(Version $version): string diff --git a/src/Release/ReleaseWorker/UpdateFractorApplicationReleaseVersionWorker.php b/src/Release/ReleaseWorker/UpdateFractorApplicationReleaseVersionWorker.php index 34b1225f..fb9b8e1b 100644 --- a/src/Release/ReleaseWorker/UpdateFractorApplicationReleaseVersionWorker.php +++ b/src/Release/ReleaseWorker/UpdateFractorApplicationReleaseVersionWorker.php @@ -9,12 +9,22 @@ use Symplify\MonorepoBuilder\Release\Contract\ReleaseWorker\ReleaseWorkerInterface; use Symplify\MonorepoBuilder\Utils\VersionUtils; -final readonly class UpdateFractorApplicationReleaseVersionWorker implements ReleaseWorkerInterface +final class UpdateFractorApplicationReleaseVersionWorker implements ReleaseWorkerInterface { - public function __construct( - private FractorApplicationReleaseWriter $fractorApplicationReleaseWriter, - private VersionUtils $versionUtils - ) { + /** + * @readonly + */ + private FractorApplicationReleaseWriter $fractorApplicationReleaseWriter; + + /** + * @readonly + */ + private VersionUtils $versionUtils; + + public function __construct(FractorApplicationReleaseWriter $fractorApplicationReleaseWriter, VersionUtils $versionUtils) + { + $this->fractorApplicationReleaseWriter = $fractorApplicationReleaseWriter; + $this->versionUtils = $versionUtils; } public function getDescription(Version $version): string