diff --git a/.gitattributes b/.gitattributes index fee66c5..f055917 100644 --- a/.gitattributes +++ b/.gitattributes @@ -15,3 +15,4 @@ /phpunit.xml.dist export-ignore /psalm.xml.dist export-ignore /codecov.yml export-ignore +/rector.php export-ignore diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 9e860a5..b12023b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -8,7 +8,7 @@ jobs: strategy: fail-fast: false matrix: - php-version: ['7.4', '8.0', '8.1'] + php-version: ['8.1', '8.2'] steps: - uses: actions/checkout@v2 @@ -39,12 +39,12 @@ jobs: - name: Run tests run: | - if [[ ${{ matrix.php-version }} == '7.4' ]]; then + if [[ ${{ matrix.php-version }} == '8.1' ]]; then export CODECOVERAGE=1 && vendor/bin/phpunit --verbose --coverage-clover=coverage.xml else vendor/bin/phpunit fi - name: Submit code coverage - if: matrix.php-version == '7.4' + if: matrix.php-version == '8.1' uses: codecov/codecov-action@v1 diff --git a/Makefile b/Makefile index d1b2801..9074700 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ -PHP?=php7.4 +PHP?=php8.1 COMPOSER=/usr/local/bin/composer php-info: - @echo "Default PHP version: $(PHP) (Run with custom PHP version: make install PHP=php8.0).\n"; + @echo "Default PHP version: $(PHP) (Run with custom PHP version: make install PHP=php8.2).\n"; list: php-info ## List @sed -rn 's/^([a-zA-Z_-]+):.*?## (.*)$$/"\1" "\2"/p' < $(MAKEFILE_LIST) | xargs printf "%-20s%s\n" @@ -31,5 +31,11 @@ code-style-fix: php-info install ## Fix code style psalm: php-info install ## Run Psalm check $(PHP) vendor/bin/psalm --config=psalm.xml.dist --threads=4 --show-snippet=true --show-info=true -.PHONY: php-info list install install-force update test test-coverage mutation-test code-style-fix psalm +rector: php-info install ## Run Rector + $(PHP) vendor/bin/rector process --clear-cache --dry-run + +rector-fix: php-info install ## Run Rector + $(PHP) vendor/bin/rector process --clear-cache + +.PHONY: php-info list install install-force update test test-coverage mutation-test code-style-fix psalm rector rector-fix .DEFAULT_GOAL := list diff --git a/composer.json b/composer.json index afa06f5..ad93a84 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,7 @@ } }, "require": { - "php": ">=7.4.0", + "php": ">=8.1.0", "ext-json": "*", "psr/container": "^1.1", "symfony/mailer": "^5.4" @@ -51,11 +51,12 @@ "phpmd/phpmd": "^1.5", "sebastian/phpcpd": "^6.0", "phploc/phploc": "^7.0", - "php-parallel-lint/php-parallel-lint": "^1.3" + "php-parallel-lint/php-parallel-lint": "^1.3", + "rector/rector": "^1.0" }, "extra": { "platform": { - "php": "7.4.*" + "php": "8.1.*" } }, "config": { diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..bf7a4d5 --- /dev/null +++ b/rector.php @@ -0,0 +1,30 @@ +paths([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]); + + $rectorConfig->skip([]); + + $rectorConfig->importNames(); + $rectorConfig->importShortClasses(false); + + // register a single rule + $rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class); + + $rectorConfig->sets([ + LevelSetList::UP_TO_PHP_81, +/* SetList::PHP_81, + SetList::CODE_QUALITY, + SetList::DEAD_CODE,*/ + ]); +}; diff --git a/src/Build/BuildMetaWriterInterface.php b/src/Build/BuildMetaWriterInterface.php index f02637e..4fc6899 100644 --- a/src/Build/BuildMetaWriterInterface.php +++ b/src/Build/BuildMetaWriterInterface.php @@ -12,13 +12,10 @@ */ interface BuildMetaWriterInterface { - /** - * @param mixed $value - */ public function write( BuildInterface $build, ?string $plugin, string $key, - $value + mixed $value ): void; } diff --git a/src/CommandExecutorInterface.php b/src/CommandExecutorInterface.php index 9dcf5b6..d7eee88 100644 --- a/src/CommandExecutorInterface.php +++ b/src/CommandExecutorInterface.php @@ -14,10 +14,7 @@ */ interface CommandExecutorInterface { - /** - * @param mixed ...$params - */ - public function executeCommand(...$params): bool; + public function executeCommand(mixed ...$params): bool; public function enableCommandOutput(): void; diff --git a/src/ParameterBag.php b/src/ParameterBag.php index 5facda6..7787643 100644 --- a/src/ParameterBag.php +++ b/src/ParameterBag.php @@ -12,11 +12,8 @@ */ class ParameterBag implements ParameterBagInterface, \IteratorAggregate, \Countable { - protected array $parameters; - - public function __construct(array $parameters = []) + public function __construct(protected array $parameters = []) { - $this->parameters = $parameters; } /** diff --git a/src/ParameterBagInterface.php b/src/ParameterBagInterface.php index 0249354..a49d541 100644 --- a/src/ParameterBagInterface.php +++ b/src/ParameterBagInterface.php @@ -13,11 +13,9 @@ interface ParameterBagInterface { /** - * @param mixed $default - * * @return mixed|null */ - public function get(string $key, $default = null); + public function get(string $key, mixed $default = null); public function has(string $key): bool; diff --git a/src/Plugin/PathResolver.php b/src/Plugin/PathResolver.php index 4f0ddc9..8a6e7a6 100644 --- a/src/Plugin/PathResolver.php +++ b/src/Plugin/PathResolver.php @@ -17,12 +17,6 @@ */ class PathResolver implements PathResolverInterface { - private BuildInterface $build; - - private BuildLoggerInterface $buildLogger; - - private VariableInterpolatorInterface $variableInterpolator; - protected ParameterBag $buildSettings; private ?string $buildDirectory = null; @@ -35,15 +29,11 @@ class PathResolver implements PathResolverInterface private ?array $buildIgnores = null; public function __construct( - BuildInterface $build, - BuildLoggerInterface $buildLogger, - VariableInterpolatorInterface $variableInterpolator, + private readonly BuildInterface $build, + private readonly BuildLoggerInterface $buildLogger, + private readonly VariableInterpolatorInterface $variableInterpolator, array $projectConfig = [] ) { - $this->build = $build; - $this->buildLogger = $buildLogger; - $this->variableInterpolator = $variableInterpolator; - $this->initBuildSettings($projectConfig); } @@ -98,9 +88,7 @@ public function resolveIgnores(array $pluginIgnores, bool $onlyInBuildPath = tru if ($pluginIgnores) { $ignores = \array_merge( $ignores, - \array_filter($pluginIgnores, function ($item) { - return !empty($item); - }) + \array_filter($pluginIgnores, fn($item) => !empty($item)) ); } @@ -120,7 +108,7 @@ public function resolveIgnores(array $pluginIgnores, bool $onlyInBuildPath = tru foreach ($ignores as $index => $ignore) { if ( !$ignore || - ($onlyInBuildPath && '/' === \substr($ignore, 0, 1)) + ($onlyInBuildPath && \str_starts_with((string) $ignore, '/')) ) { unset($ignores[$index]); } @@ -134,7 +122,7 @@ public function resolveIgnores(array $pluginIgnores, bool $onlyInBuildPath = tru private function getRealPath(string $path, bool $isFile = false): string { $path = \rtrim( - \preg_replace( + (string) \preg_replace( '#[/]{2,}#', '/', \str_replace(['/', '\\'], '/', $path) @@ -231,9 +219,7 @@ private function getBuildIgnores(): array if ($buildSettingsIgnores) { $this->buildIgnores = \array_filter( $buildSettingsIgnores, - function (string $item) { - return !empty($item); - } + fn(string $item) => !empty($item) ); } } diff --git a/src/Plugin/Plugin.php b/src/Plugin/Plugin.php index a1b079a..d566919 100644 --- a/src/Plugin/Plugin.php +++ b/src/Plugin/Plugin.php @@ -23,26 +23,6 @@ */ abstract class Plugin implements PluginInterface { - protected BuildInterface $build; - - protected ProjectInterface $project; - - protected ApplicationInterface $application; - - protected BuildLoggerInterface $buildLogger; - - protected BuildErrorWriterInterface $buildErrorWriter; - - protected BuildMetaWriterInterface $buildMetaWriter; - - protected CommandExecutorInterface $commandExecutor; - - protected VariableInterpolatorInterface $variableInterpolator; - - protected PathResolverInterface $pathResolver; - - protected ContainerInterface $container; - protected ParameterBag $options; protected ParameterBag $buildSettings; @@ -82,28 +62,17 @@ abstract class Plugin implements PluginInterface * @throws \Throwable */ public function __construct( - BuildInterface $build, - ProjectInterface $project, - BuildLoggerInterface $buildLogger, - BuildErrorWriterInterface $buildErrorWriter, - BuildMetaWriterInterface $buildMetaWriter, - CommandExecutorInterface $commandExecutor, - VariableInterpolatorInterface $variableInterpolator, - PathResolverInterface $pathResolver, - ApplicationInterface $application, - ContainerInterface $container + protected BuildInterface $build, + protected ProjectInterface $project, + protected BuildLoggerInterface $buildLogger, + protected BuildErrorWriterInterface $buildErrorWriter, + protected BuildMetaWriterInterface $buildMetaWriter, + protected CommandExecutorInterface $commandExecutor, + protected VariableInterpolatorInterface $variableInterpolator, + protected PathResolverInterface $pathResolver, + protected ApplicationInterface $application, + protected ContainerInterface $container ) { - $this->build = $build; - $this->project = $project; - $this->buildLogger = $buildLogger; - $this->buildErrorWriter = $buildErrorWriter; - $this->buildMetaWriter = $buildMetaWriter; - $this->commandExecutor = $commandExecutor; - $this->variableInterpolator = $variableInterpolator; - $this->pathResolver = $pathResolver; - $this->application = $application; - $this->container = $container; - $this->initOptions(); $this->initBuildSettings(); @@ -186,7 +155,7 @@ protected function initOptions(): void { $projectConfig = $this->project->getBuildConfig(); - $pluginName = $this->getName(); + $pluginName = static::getName(); $pluginOptionsArray = []; if (!empty($projectConfig[$pluginName])) { $pluginOptionsArray = $projectConfig[$pluginName]; diff --git a/src/View/ViewInterface.php b/src/View/ViewInterface.php index 22d0eaf..1c290cf 100644 --- a/src/View/ViewInterface.php +++ b/src/View/ViewInterface.php @@ -19,10 +19,7 @@ public function hasVariable(string $key): bool; */ public function getVariable(string $key); - /** - * @param mixed $value - */ - public function setVariable(string $key, $value): bool; + public function setVariable(string $key, mixed $value): bool; public function setVariables(array $values): bool; diff --git a/tests/src/Plugin/PluginTest.php b/tests/src/Plugin/PluginTest.php index 621e703..73dee38 100644 --- a/tests/src/Plugin/PluginTest.php +++ b/tests/src/Plugin/PluginTest.php @@ -174,9 +174,7 @@ public function setUp(): void $this->variableInterpolator = $this->createMock(VariableInterpolatorInterface::class); $this->variableInterpolator ->method('interpolate') - ->willReturnCallback(function ($string) { - return \str_replace(['%BUILD_PATH%'], $this->buildPath, $string); - }); + ->willReturnCallback(fn($string) => \str_replace(['%BUILD_PATH%'], $this->buildPath, (string) $string)); $this->buildLogger = $this->createMock(BuildLoggerInterface::class); $this->buildErrorWriter = $this->createMock(BuildErrorWriterInterface::class);