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 62e6f85 + 923769d commit 165e81a
Show file tree
Hide file tree
Showing 35 changed files with 148 additions and 189 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": "*",
"ext-simplexml": "*",
"ext-libxml": "*",
Expand All @@ -62,11 +62,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,*/
]);
};
2 changes: 1 addition & 1 deletion src/CodeQuality/Pahout.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function execute(): bool

$success = true;

list($files, $hints) = $this->processReport($this->commandExecutor->getLastCommandOutput());
[$files, $hints] = $this->processReport($this->commandExecutor->getLastCommandOutput());

if (0 < \count($hints)) {
if (-1 !== $this->allowedWarnings && \count($hints) > $this->allowedWarnings) {
Expand Down
2 changes: 1 addition & 1 deletion src/CodeQuality/Phan.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private function processReport(string $jsonString): int
self::getName(),
$data['check_name']."\n\n".$data['description'],
$this->severity((int)$data['severity']),
isset($data['location']['path']) ? $data['location']['path'] : '??',
$data['location']['path'] ?? '??',
isset($data['location']['lines']['begin']) ? (int)$data['location']['lines']['begin'] : 0,
isset($data['location']['lines']['end']) ? (int)$data['location']['lines']['end'] : 0
);
Expand Down
2 changes: 1 addition & 1 deletion src/CodeQuality/Phlint.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected function getPluginDefaultBinaryNames(): array

private function processReport(string $output): array
{
$data = \explode(\chr(226), \preg_replace('#\\x1b[[][^A-Za-z\n]*[A-Za-z]#', '', \trim($output)));
$data = \explode(\chr(226), (string)\preg_replace('#\\x1b[[][^A-Za-z\n]*[A-Za-z]#', '', \trim($output)));
\array_pop($data);
\array_shift($data);

Expand Down
6 changes: 3 additions & 3 deletions src/CodeQuality/PhpCodeSniffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static function getName(): string
*/
public function execute(): bool
{
list($ignores, $standard, $suffixes, $severity, $errorSeverity, $warningSeverity) = $this->getFlags();
[$ignores, $standard, $suffixes, $severity, $errorSeverity, $warningSeverity] = $this->getFlags();

$executable = $this->commandExecutor->findBinary($this->binaryNames, $this->binaryPath);

Expand All @@ -77,7 +77,7 @@ public function execute(): bool
);

$output = $this->commandExecutor->getLastCommandOutput();
list($errors, $warnings) = $this->processReport($output);
[$errors, $warnings] = $this->processReport($output);

$this->commandExecutor->enableCommandOutput();

Expand Down Expand Up @@ -212,7 +212,7 @@ private function processReport(string $output): array
$warnings = $data['totals']['warnings'];

foreach ($data['files'] as $fileName => $file) {
$fileName = \str_replace($this->build->getBuildPath(), '', $fileName);
$fileName = \str_replace($this->build->getBuildPath(), '', (string)$fileName);

foreach ($file['messages'] as $message) {
$this->buildErrorWriter->write(
Expand Down
2 changes: 1 addition & 1 deletion src/CodeQuality/PhpCpd.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function execute(): bool
$this->directory
)
);
if (false !== \strpos($lastLine, '--names-exclude')) {
if (\str_contains($lastLine, '--names-exclude')) {
$ignoresString = $ignoreForNewVersion;
}

Expand Down
21 changes: 6 additions & 15 deletions src/CodeQuality/PhpCsFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private function processReport(string $output): int
$warnings = 0;
foreach ($data['files'] as $item) {
$filename = $item['name'];
$appliedFixers = isset($item['appliedFixers']) ? $item['appliedFixers'] : [];
$appliedFixers = $item['appliedFixers'] ?? [];

$parser = new Parser();
$parsed = $parser->parse($item['diff']);
Expand All @@ -201,20 +201,11 @@ private function processReport(string $output): int
}
$chunkDiff = [];
foreach ($chunk->getLines() as $line) {
switch ($line->getType()) {
case Line::ADDED:
$symbol = '+';

break;
case Line::REMOVED:
$symbol = '-';

break;
default:
$symbol = ' ';

break;
}
$symbol = match ($line->getType()) {
Line::ADDED => '+',
Line::REMOVED => '-',
default => ' ',
};
$chunkDiff[] = $symbol . $line->getContent();
if ($foundChanges) {
continue;
Expand Down
4 changes: 1 addition & 3 deletions src/CodeQuality/PhpLoc.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ public function execute(): bool
{
$ignoreString = '';
if ($this->ignores) {
$map = function (string $ignore): string {
return \sprintf(' --exclude="%s"', $ignore);
};
$map = fn(string $ignore): string => \sprintf(' --exclude="%s"', $ignore);

$ignoreString = \array_map($map, $this->ignores);
$ignoreString = \implode('', $ignoreString);
Expand Down
2 changes: 1 addition & 1 deletion src/CodeQuality/PhpMessDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ protected function getPluginDefaultBinaryNames(): array
private function processRules(): void
{
foreach ($this->rules as &$rule) {
if (false !== \strpos($rule, '/')) {
if (\str_contains((string) $rule, '/')) {
$rule = $this->build->getBuildPath() . $rule;
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/CodeQuality/PhpStan.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function execute(): bool
$this->commandExecutor->enableCommandOutput();

$success = true;
list($total_errors, $files) = $this->processReport($this->commandExecutor->getLastCommandOutput());
[$total_errors, $files] = $this->processReport($this->commandExecutor->getLastCommandOutput());

if (0 < $total_errors) {
if (-1 !== $this->allowedErrors && $total_errors > $this->allowedErrors) {
Expand All @@ -65,18 +65,18 @@ public function execute(): bool

foreach ($files as $file => $payload) {
if (0 < $payload['errors']) {
$file = \str_replace($this->build->getBuildPath(), '', $file);
$file = \str_replace($this->build->getBuildPath(), '', (string) $file);
$len = \strlen($file);
$out = '';
$filename = (false !== \strpos($file, ' (')) ? \strstr($file, ' (', true) : $file;
$filename = (\str_contains($file, ' (')) ? \strstr($file, ' (', true) : $file;

foreach ($payload['messages'] as $message) {
if (\strlen($message['message']) > $len) {
$len = \strlen($message['message']);
if (\strlen((string)$message['message']) > $len) {
$len = \strlen((string)$message['message']);
}
$out .= \vsprintf(' %d%s %s' . PHP_EOL, [
$message['line'],
\str_repeat(' ', 6 - \strlen($message['line'])),
\str_repeat(' ', 6 - \strlen((string)$message['line'])),
$message['message'],
]);

Expand Down
2 changes: 1 addition & 1 deletion src/CodeQuality/Psalm.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function execute(): bool
$this->commandExecutor->enableCommandOutput();

$success = true;
list($errors, $infos) = $this->processReport($this->commandExecutor->getLastCommandOutput());
[$errors, $infos] = $this->processReport($this->commandExecutor->getLastCommandOutput());

if (0 < \count($errors)) {
if (-1 !== $this->allowedErrors && \count($errors) > $this->allowedErrors) {
Expand Down
6 changes: 3 additions & 3 deletions src/CodeQuality/TechnicalDebt.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private function getErrorList(): int
$ignoreAbsolute = $this->build->getBuildPath() . $ignore;

if ('/' === $ignoreAbsolute[0]) {
if (0 === \strpos($filePath, $ignoreAbsolute)) {
if (\str_starts_with($filePath, $ignoreAbsolute)) {
$ignored = true;

break;
Expand Down Expand Up @@ -192,8 +192,8 @@ private function returnResult(): string
$string = '';
$fileNumber = 0;
foreach ($this->errorPerFile as $oneLine) {
$fileNumber += \strlen($oneLine);
$string .= \str_pad($oneLine, 60, ' ', STR_PAD_RIGHT);
$fileNumber += \strlen((string)$oneLine);
$string .= \str_pad((string)$oneLine, 60, ' ', STR_PAD_RIGHT);
$string .= \str_pad((string)$fileNumber, 4, ' ', STR_PAD_LEFT);
$string .= "/" . $this->numberOfAnalysedFile . " (" . \floor($fileNumber * 100 / $this->numberOfAnalysedFile) . " %)\n";
}
Expand Down
2 changes: 1 addition & 1 deletion src/Common/CopyBuild.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function execute(): bool
$cmd,
$buildPath,
$this->directory,
\rtrim($buildPath, '/'),
\rtrim((string)$buildPath, '/'),
$this->directory
);

Expand Down
22 changes: 7 additions & 15 deletions src/Common/Git.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,13 @@ protected function initPluginSettings(): void
*/
private function runAction(string $action, array $options = []): bool
{
switch ($action) {
case 'merge':
return $this->runMergeAction($options);

case 'tag':
return $this->runTagAction($options);

case 'pull':
return $this->runPullAction($options);

case 'push':
return $this->runPushAction($options);
}

return false;
return match ($action) {
'merge' => $this->runMergeAction($options),
'tag' => $this->runTagAction($options),
'pull' => $this->runPullAction($options),
'push' => $this->runPushAction($options),
default => false,
};
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/Deploy/Mage.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@ private function getMageLog(): array
throw new Exception('Log dir read fail');
}

$list = \array_filter($list, function ($name) {
return \preg_match('/^log-\d+-\d+\.log$/', $name);
});
$list = \array_filter($list, fn($name) => \preg_match('/^log-\d+-\d+\.log$/', (string)$name));

if (empty($list)) {
throw new Exception('Log dir filter fail');
Expand Down
4 changes: 1 addition & 3 deletions src/Deploy/Mage3.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ private function getMageLog(): array
throw new Exception('Log dir read fail');
}

$list = \array_filter($list, function ($name) {
return \preg_match('/^\d+_\d+\.log$/', $name);
});
$list = \array_filter($list, fn($name) => \preg_match('/^\d+_\d+\.log$/', (string)$name));

if (empty($list)) {
throw new Exception('Log dir filter fail');
Expand Down
Loading

0 comments on commit 165e81a

Please sign in to comment.