Skip to content

Commit 5c98dad

Browse files
committed
Updated PHPStan and Rector to v2.
1 parent 9945829 commit 5c98dad

File tree

9 files changed

+46
-53
lines changed

9 files changed

+46
-53
lines changed

.github/workflows/test-php.yml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,21 @@ on:
88
branches:
99
- main
1010
- 'feature/**'
11+
workflow_dispatch:
12+
inputs:
13+
enable_terminal:
14+
type: boolean
15+
description: 'Enable terminal session.'
16+
required: false
17+
default: false
1118

1219
jobs:
1320
test-php:
1421
runs-on: ubuntu-latest
1522

1623
strategy:
1724
matrix:
18-
php-versions: ['8.2', '8.3']
25+
php-versions: ['8.2', '8.3', '8.4']
1926

2027
steps:
2128
- name: Checkout code
@@ -33,6 +40,8 @@ jobs:
3340
uses: shivammathur/setup-php@v2
3441
with:
3542
php-version: ${{ matrix.php-versions }}
43+
coverage: pcov
44+
ini-values: pcov.directory=.
3645

3746
- name: Setup SSH private key
3847
uses: webfactory/[email protected]
@@ -47,24 +56,41 @@ jobs:
4756
- name: Install dependencies
4857
run: composer install
4958

59+
- name: Validate composer.json
60+
run: |
61+
composer --verbose validate
62+
composer normalize --dry-run
63+
5064
- name: Check coding standards
5165
run: composer lint
66+
continue-on-error: ${{ vars.CI_LINT_IGNORE_FAILURE == '1' }}
5267

5368
- name: Run tests
54-
run: XDEBUG_MODE=coverage composer test
69+
run: composer test-coverage
70+
continue-on-error: ${{ vars.CI_TEST_IGNORE_FAILURE == '1' }}
5571

5672
- name: Upload coverage report as an artifact
5773
uses: actions/upload-artifact@v4
5874
with:
5975
name: ${{github.job}}-code-coverage-report-${{ matrix.php-versions }}
6076
path: ./.coverage-html
77+
include-hidden-files: true
78+
if-no-files-found: error
6179

6280
- name: Upload coverage report to Codecov
6381
uses: codecov/codecov-action@v5
82+
if: ${{ env.CODECOV_TOKEN != '' }}
6483
with:
6584
files: ./cobertura.xml
6685
fail_ci_if_error: true
6786
token: ${{ secrets.CODECOV_TOKEN }}
87+
env:
88+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
89+
90+
- name: Setup tmate session
91+
if: ${{ !cancelled() && github.event.inputs.enable_terminal }}
92+
uses: mxschmitt/action-tmate@v3
93+
timeout-minutes: 5
6894

6995
build-php:
7096
runs-on: ubuntu-latest

composer.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@
2929
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
3030
"drupal/coder": "^8.3",
3131
"ergebnis/composer-normalize": "^2.43",
32-
"phpmd/phpmd": "^2.15",
33-
"phpstan/phpstan": "^1.10",
32+
"phpstan/phpstan": "^2",
3433
"phpunit/phpunit": "^11",
35-
"rector/rector": "^1.0.0"
34+
"rector/rector": "^2"
3635
},
3736
"autoload": {
3837
"psr-4": {
@@ -63,14 +62,14 @@
6362
"lint": [
6463
"phpcs",
6564
"phpstan --memory-limit=-1",
66-
"phpmd --exclude vendor,vendor-bin,node_modules,TokenTest.php . text phpmd.xml",
6765
"rector --clear-cache --dry-run"
6866
],
6967
"lint-fix": [
7068
"rector --clear-cache",
7169
"phpcbf"
7270
],
73-
"reset": "rm -rf vendor vendor-bin composer.lock",
74-
"test": "phpunit"
71+
"reset": "rm -Rf vendor vendor-bin composer.lock",
72+
"test": "phpunit --no-coverage",
73+
"test-coverage": "phpunit"
7574
}
7675
}

phpmd.xml

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/Commands/ArtifactCommand.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@
1818

1919
/**
2020
* Artifact Command.
21-
*
22-
* @SuppressWarnings(PHPMD.TooManyMethods)
23-
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
24-
* @SuppressWarnings(PHPMD.TooManyFields)
25-
* @SuppressWarnings(PHPMD.ExcessiveClassLength)
2621
*/
2722
class ArtifactCommand extends Command {
2823

@@ -219,8 +214,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
219214

220215
/**
221216
* Assemble a code artifact from your codebase.
222-
*
223-
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
224217
*/
225218
protected function doExecute(): void {
226219
$error = NULL;

src/Git/ArtifactGitRepository.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
/**
1717
* Artifact git repository.
18-
*
19-
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
2018
*/
2119
class ArtifactGitRepository extends GitRepository {
2220

@@ -321,11 +319,9 @@ public function removeSubRepositories(): static {
321319
$dirs = iterator_to_array($dirs->directories());
322320

323321
foreach ($dirs as $dir) {
324-
if ($dir instanceof \SplFileInfo) {
325-
$dir = $dir->getPathname();
326-
$this->fs->remove($dir);
327-
$this->logger->debug(sprintf('Removing sub-repository "%s"', $this->fsGetAbsolutePath((string) $dir)));
328-
}
322+
$dir = $dir->getPathname();
323+
$this->fs->remove($dir);
324+
$this->logger->debug(sprintf('Removing sub-repository "%s"', $this->fsGetAbsolutePath((string) $dir)));
329325
}
330326

331327
// After removing sub-repositories, the files that were previously tracked

src/Traits/FilesystemTrait.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ protected function fsGetRootDir(): string {
6262
return $this->fsRootDir;
6363
}
6464

65-
if (isset($_SERVER['PWD'])) {
65+
if (isset($_SERVER['PWD']) && is_string($_SERVER['PWD']) && !empty($_SERVER['PWD'])) {
6666
return $_SERVER['PWD'];
6767
}
6868

@@ -191,9 +191,6 @@ protected function fsAssertPathsExist($paths, bool $strict = TRUE): bool {
191191
* Resolved path.
192192
*
193193
* @see https://stackoverflow.com/a/29372360/712666
194-
*
195-
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
196-
* @SuppressWarnings(PHPMD.NPathComplexity)
197194
*/
198195
protected function fsRealpath(string $path): string {
199196
// Whether $path is unix or not.

tests/phpunit/Functional/ForcePushModeTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
/**
1212
* Class ForcePushTest.
13-
*
14-
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
1513
*/
1614
#[CoversClass(ArtifactCommand::class)]
1715
#[CoversClass(ArtifactGitRepository::class)]

tests/phpunit/Traits/ConsoleTrait.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ protected function consoleInitApplicationTester(string|object $object_or_class,
5252

5353
$application->setAutoExit(FALSE);
5454
$application->setCatchExceptions(FALSE);
55-
if (method_exists($application, 'setCatchErrors')) {
56-
$application->setCatchErrors(FALSE);
57-
}
5855

5956
$this->appTester = new ApplicationTester($application);
6057
}
@@ -75,6 +72,7 @@ protected function consoleInitApplicationTester(string|object $object_or_class,
7572
protected function consoleApplicationRun(array $input = [], array $options = [], bool $expect_fail = FALSE): string {
7673
$options += ['capture_stderr_separately' => TRUE];
7774

75+
$output = '';
7876
try {
7977
$this->appTester->run($input, $options);
8078
$output = $this->appTester->getDisplay();

tests/phpunit/Traits/MockTrait.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
* Trait MockTrait.
1111
*
1212
* This trait provides a method to prepare class mock.
13+
*
14+
* @phpstan-ignore trait.unused
1315
*/
1416
trait MockTrait {
1517

@@ -28,13 +30,9 @@ trait MockTrait {
2830
*
2931
* @return \PHPUnit\Framework\MockObject\MockObject
3032
* Mocked class.
31-
*
32-
* @throws \ReflectionException
33-
*
34-
* @SuppressWarnings(CyclomaticComplexity)
3533
*/
3634
protected function prepareMock(string $class, array $methods = [], array|bool $args = []): MockObject {
37-
$methods = array_filter($methods, fn($value, $key): bool => is_string($key), ARRAY_FILTER_USE_BOTH);
35+
$methods = array_filter($methods, fn($value, $key): bool => !is_numeric($key), ARRAY_FILTER_USE_BOTH);
3836

3937
if (!class_exists($class)) {
4038
throw new \InvalidArgumentException(sprintf('Class %s does not exist', $class));
@@ -49,8 +47,11 @@ protected function prepareMock(string $class, array $methods = [], array|bool $a
4947
$builder->disableOriginalConstructor();
5048
}
5149

52-
$method_names = array_filter(array_keys($methods), fn($method): bool => is_string($method) && !empty($method));
53-
$mock = $builder->onlyMethods($method_names)->getMock();
50+
$method_names = array_values(array_filter(array_keys($methods), fn($method): bool => !empty($method)));
51+
if (!empty($method_names)) {
52+
$builder->onlyMethods($method_names);
53+
}
54+
$mock = $builder->getMock();
5455

5556
foreach ($methods as $method => $value) {
5657
// Handle callback value differently based on its type.

0 commit comments

Comments
 (0)