Skip to content

Commit

Permalink
Merge branch 'php-81'
Browse files Browse the repository at this point in the history
  • Loading branch information
corpsee committed Feb 11, 2024
2 parents 5a3e181 + 2d9084c commit 6e89391
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 94 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
/phpunit.xml.dist export-ignore
/psalm.xml.dist export-ignore
/codecov.yml export-ignore
/rector.php export-ignore
6 changes: 3 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
}
},
"require": {
"php": ">=7.4.0",
"php": ">=8.1.0",
"ext-json": "*",
"psr/container": "^1.1",
"symfony/mailer": "^5.4"
Expand All @@ -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": {
Expand Down
30 changes: 30 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;
//use Rector\Set\ValueObject\SetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->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,*/
]);
};
5 changes: 1 addition & 4 deletions src/Build/BuildMetaWriterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@
*/
interface BuildMetaWriterInterface
{
/**
* @param mixed $value
*/
public function write(
BuildInterface $build,
?string $plugin,
string $key,
$value
mixed $value
): void;
}
5 changes: 1 addition & 4 deletions src/CommandExecutorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
*/
interface CommandExecutorInterface
{
/**
* @param mixed ...$params
*/
public function executeCommand(...$params): bool;
public function executeCommand(mixed ...$params): bool;

public function enableCommandOutput(): void;

Expand Down
5 changes: 1 addition & 4 deletions src/ParameterBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/ParameterBagInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
28 changes: 7 additions & 21 deletions src/Plugin/PathResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@
*/
class PathResolver implements PathResolverInterface
{
private BuildInterface $build;

private BuildLoggerInterface $buildLogger;

private VariableInterpolatorInterface $variableInterpolator;

protected ParameterBag $buildSettings;

private ?string $buildDirectory = null;
Expand All @@ -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);
}

Expand Down Expand Up @@ -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))
);
}

Expand All @@ -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]);
}
Expand All @@ -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)
Expand Down Expand Up @@ -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)
);
}
}
Expand Down
53 changes: 11 additions & 42 deletions src/Plugin/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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];
Expand Down
5 changes: 1 addition & 4 deletions src/View/ViewInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 1 addition & 3 deletions tests/src/Plugin/PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 6e89391

Please sign in to comment.