Skip to content

Commit

Permalink
[TASK] adds/ updates phpstan packages and config and adapts classes a…
Browse files Browse the repository at this point in the history
…ccordingly

[CLEANUP] adds description to command registration in Services.yaml
[CLEANUP] updates README
  • Loading branch information
EvilBMP committed Nov 5, 2024
1 parent 86391c1 commit 16d31a3
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 29 deletions.
63 changes: 57 additions & 6 deletions Build/phpstan.neon
Original file line number Diff line number Diff line change
@@ -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'
26 changes: 14 additions & 12 deletions Classes/Command/MigrateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,25 @@ class MigrateCommand extends Command
/**
* @var array<string, mixed>
*/
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.'
);
Expand Down Expand Up @@ -63,7 +65,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$io->writeln(
sprintf(
'<fg=red>Migration folder not found. Please make sure "%s" exists!</>',
htmlspecialchars($pathFromConfig)
htmlspecialchars($pathFromConfig, ENT_QUOTES)
)
);
}
Expand Down
17 changes: 10 additions & 7 deletions Classes/DirectoryIterator/SortableDirectoryIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,37 @@

namespace Portrino\PxDbmigrator\DirectoryIterator;

/**
* @implements \IteratorAggregate<string, \SplFileInfo>
*/
class SortableDirectoryIterator implements \IteratorAggregate
{
/**
* @var \ArrayObject
* @var \ArrayObject<string, \SplFileInfo>
*/
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 */
foreach ($files as $file) {
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);
}
);
}

public function getIterator(): \Traversable
{
return $this->_storage->getIterator();
return $this->storage->getIterator();
}
}
1 change: 1 addition & 0 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": ""
Expand Down

0 comments on commit 16d31a3

Please sign in to comment.