From 16d31a301796fc13687b4ab423bb9da072e8b968 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20B=C3=B6swetter?= Date: Tue, 5 Nov 2024 11:43:38 +0100 Subject: [PATCH] [TASK] adds/ updates phpstan packages and config and adapts classes accordingly [CLEANUP] adds description to command registration in Services.yaml [CLEANUP] updates README --- Build/phpstan.neon | 63 +++++++++++++++++-- Classes/Command/MigrateCommand.php | 26 ++++---- .../SortableDirectoryIterator.php | 17 ++--- Configuration/Services.yaml | 1 + README.md | 11 +++- composer.json | 8 ++- 6 files changed, 97 insertions(+), 29 deletions(-) diff --git a/Build/phpstan.neon b/Build/phpstan.neon index 3eb97be..546a93f 100644 --- a/Build/phpstan.neon +++ b/Build/phpstan.neon @@ -1,14 +1,65 @@ includes: - - %currentWorkingDirectory%/.Build/vendor/phpstan/phpstan-strict-rules/rules.neon - - %currentWorkingDirectory%/.Build/vendor/phpstan/phpstan-deprecation-rules/rules.neon - - %currentWorkingDirectory%/.Build/vendor/friendsoftypo3/phpstan-typo3/extension.neon + - ../.Build/vendor/phpstan/phpstan-strict-rules/rules.neon + - ../.Build/vendor/phpstan/phpstan-deprecation-rules/rules.neon + - ../.Build/vendor/friendsoftypo3/phpstan-typo3/extension.neon + - ../.Build/vendor/spaze/phpstan-disallowed-calls/extension.neon + - ../.Build/vendor/spaze/phpstan-disallowed-calls/disallowed-dangerous-calls.neon + - ../.Build/vendor/spaze/phpstan-disallowed-calls/disallowed-execution-calls.neon + - ../.Build/vendor/spaze/phpstan-disallowed-calls/disallowed-insecure-calls.neon + - ../.Build/vendor/spaze/phpstan-disallowed-calls/disallowed-loose-calls.neon + #- ../.Build/vendor/tomasvotruba/cognitive-complexity/config/extension.neon + - ../.Build/vendor/tomasvotruba/type-coverage/config/extension.neon parameters: level: 8 paths: - - %currentWorkingDirectory%/Classes + - ../Classes - ignoreErrors: + # Allow instanceof checks, particularly in tests + checkAlwaysTrueCheckTypeFunctionCall: false + + type_coverage: + return: 100 + param: 100 + property: 95 + constant: 0 # TODO: Set to 100, when PHP 8.3 is minimum requirement + + #cognitive_complexity: + # class: 10 + # function: 5 + + disallowedFunctionCalls: + - + function: + - 'var_dump()' + - 'xdebug_break()' + - 'debug()' + message: 'Use logging instead or remove if it was for debugging purposes.' + - + function: 'header()' + message: 'Use PSR-7 API instead' + - + function: + - 'exec()' + - 'shell_exec()' + allowInMethods: + - 'Portrino\PxDbmigrator\Command\MigrateCommand::migrateShellFile()' + - 'Portrino\PxDbmigrator\Command\MigrateCommand::migrateSqlFile()' + - 'Portrino\PxDbmigrator\Command\MigrateCommand::migrateTypo3CmsFile()' + + disallowedStaticCalls: + - + method: + - 'TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump()' + - 'TYPO3\CMS\Core\Utility\DebugUtility::debug()' + message: 'Use logging instead or remove if it was for debugging purposes.' + + disallowedSuperglobals: - - identifier: missingType.generics + superglobal: + - '$_GET' + - '$_POST' + - '$_FILES' + - '$_SERVER' + message: 'Use PSR-7 API instead' diff --git a/Classes/Command/MigrateCommand.php b/Classes/Command/MigrateCommand.php index d764681..1ce7f88 100644 --- a/Classes/Command/MigrateCommand.php +++ b/Classes/Command/MigrateCommand.php @@ -19,23 +19,25 @@ class MigrateCommand extends Command /** * @var array */ - protected $extConf; - - /** - * @var Registry - */ - protected $registry; + protected array $extConf = []; /** * @var string */ - protected $sqlCommandTemplate = '%s --default-character-set=UTF8 -u"%s" -p"%s" -h "%s" -D "%s" -e "source %s" 2>&1'; + protected string $sqlCommandTemplate = '%s --default-character-set=UTF8 -u"%s" -p"%s" -h "%s" -D "%s" -e "source %s" 2>&1'; - protected function configure() - { - $this->extConf = (GeneralUtility::makeInstance(ExtensionConfiguration::class))->get('px_dbmigrator'); - $this->registry = GeneralUtility::makeInstance(Registry::class); + public function __construct( + protected readonly ExtensionConfiguration $extensionConfiguration, + protected readonly Registry $registry, + ?string $name = null + ) { + parent::__construct($name); + $this->extConf = $this->extensionConfiguration->get('px_dbmigrator'); + } + + protected function configure(): void + { $this->setDescription( 'Executes pending *.sh, *.sql and *.typo3cms migration files from the configured migrations directory.' ); @@ -63,7 +65,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $io->writeln( sprintf( 'Migration folder not found. Please make sure "%s" exists!', - htmlspecialchars($pathFromConfig) + htmlspecialchars($pathFromConfig, ENT_QUOTES) ) ); } diff --git a/Classes/DirectoryIterator/SortableDirectoryIterator.php b/Classes/DirectoryIterator/SortableDirectoryIterator.php index 3f76909..58c9742 100644 --- a/Classes/DirectoryIterator/SortableDirectoryIterator.php +++ b/Classes/DirectoryIterator/SortableDirectoryIterator.php @@ -2,16 +2,19 @@ namespace Portrino\PxDbmigrator\DirectoryIterator; +/** + * @implements \IteratorAggregate + */ class SortableDirectoryIterator implements \IteratorAggregate { /** - * @var \ArrayObject + * @var \ArrayObject */ - private $_storage; + private \ArrayObject $storage; public function __construct(string $path) { - $this->_storage = new \ArrayObject(); + $this->storage = new \ArrayObject(); $files = new \DirectoryIterator($path); /** @var \DirectoryIterator $file */ @@ -19,10 +22,10 @@ public function __construct(string $path) if ($file->isDot()) { continue; } - $this->_storage->offsetSet($file->getFilename(), $file->getFileInfo()); + $this->storage->offsetSet($file->getFilename(), $file->getFileInfo()); } - $this->_storage->uksort( - function ($a, $b) { + $this->storage->uksort( + function (string $a, string $b) { return strcmp($a, $b); } ); @@ -30,6 +33,6 @@ function ($a, $b) { public function getIterator(): \Traversable { - return $this->_storage->getIterator(); + return $this->storage->getIterator(); } } diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index 262b997..d23acfc 100644 --- a/Configuration/Services.yaml +++ b/Configuration/Services.yaml @@ -12,4 +12,5 @@ services: tags: - name: 'console.command' command: 'migration:migrateall' + description: 'Executes pending *.sh, *.sql and *.typo3cms migration files from the configured migrations directory.' schedulable: false diff --git a/README.md b/README.md index de8075e..01a04b3 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,16 @@ Example: `1696560849-adds-some-required-pages.sql` No, the migrator only knows one direction. You’ll need to do it manually. -## 5 Authors +## 5 Compatibility + +| PxDbmigrator | TYPO3 | PHP | Support / Development | +|--------------|-------|-----------|--------------------------------------| +| 3.x | 13.4 | 8.2 - 8.3 | features, bugfixes, security updates | +| 2.x | 12.4 | 8.1 - 8.2 | bugfixes, security updates | +| 2.x | 11.5 | 7.4 - 8.1 | bugfixes, security updates | +| 2.x | 10.4 | 7.2 - 7.4 | bugfixes, security updates | + +## 6 Authors * See the list of [contributors](https://github.com/portrino/px_dbmigrator/graphs/contributors) who participated in this project. diff --git a/composer.json b/composer.json index a38dbf9..685561b 100644 --- a/composer.json +++ b/composer.json @@ -11,19 +11,21 @@ } ], "require": { - "typo3/cms-core": "^13.0" + "typo3/cms-core": "^13.4" }, "require-dev": { "ergebnis/composer-normalize": "^2.28", "friendsofphp/php-cs-fixer": "^3.14", "friendsoftypo3/phpstan-typo3": "^0.9", "helmich/typo3-typoscript-lint": "^3.1", - "php-coveralls/php-coveralls": "^2.5", "phpstan/phpstan": "^1.10", "phpstan/phpstan-deprecation-rules": "^1.1", "phpstan/phpstan-strict-rules": "^1.5", "seld/jsonlint": "^1.9", - "typo3/coding-standards": "dev-main" + "spaze/phpstan-disallowed-calls": "^3.4", + "tomasvotruba/cognitive-complexity": "^0.2.3", + "tomasvotruba/type-coverage": "^0.3.1", + "typo3/coding-standards": "^0.8" }, "suggest": { "portrino/px_dbsequencer": ""