Skip to content

Commit

Permalink
Updated PHPStan and Rector to v2.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk committed Jan 7, 2025
1 parent 9945829 commit 5c98dad
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 53 deletions.
30 changes: 28 additions & 2 deletions .github/workflows/test-php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@ on:
branches:
- main
- 'feature/**'
workflow_dispatch:
inputs:
enable_terminal:
type: boolean
description: 'Enable terminal session.'
required: false
default: false

jobs:
test-php:
runs-on: ubuntu-latest

strategy:
matrix:
php-versions: ['8.2', '8.3']
php-versions: ['8.2', '8.3', '8.4']

steps:
- name: Checkout code
Expand All @@ -33,6 +40,8 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
coverage: pcov
ini-values: pcov.directory=.

- name: Setup SSH private key
uses: webfactory/[email protected]
Expand All @@ -47,24 +56,41 @@ jobs:
- name: Install dependencies
run: composer install

- name: Validate composer.json
run: |
composer --verbose validate
composer normalize --dry-run
- name: Check coding standards
run: composer lint
continue-on-error: ${{ vars.CI_LINT_IGNORE_FAILURE == '1' }}

- name: Run tests
run: XDEBUG_MODE=coverage composer test
run: composer test-coverage
continue-on-error: ${{ vars.CI_TEST_IGNORE_FAILURE == '1' }}

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

- name: Upload coverage report to Codecov
uses: codecov/codecov-action@v5
if: ${{ env.CODECOV_TOKEN != '' }}
with:
files: ./cobertura.xml
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

- name: Setup tmate session
if: ${{ !cancelled() && github.event.inputs.enable_terminal }}
uses: mxschmitt/action-tmate@v3
timeout-minutes: 5

build-php:
runs-on: ubuntu-latest
Expand Down
11 changes: 5 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
"drupal/coder": "^8.3",
"ergebnis/composer-normalize": "^2.43",
"phpmd/phpmd": "^2.15",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan": "^2",
"phpunit/phpunit": "^11",
"rector/rector": "^1.0.0"
"rector/rector": "^2"
},
"autoload": {
"psr-4": {
Expand Down Expand Up @@ -63,14 +62,14 @@
"lint": [
"phpcs",
"phpstan --memory-limit=-1",
"phpmd --exclude vendor,vendor-bin,node_modules,TokenTest.php . text phpmd.xml",
"rector --clear-cache --dry-run"
],
"lint-fix": [
"rector --clear-cache",
"phpcbf"
],
"reset": "rm -rf vendor vendor-bin composer.lock",
"test": "phpunit"
"reset": "rm -Rf vendor vendor-bin composer.lock",
"test": "phpunit --no-coverage",
"test-coverage": "phpunit"
}
}
15 changes: 0 additions & 15 deletions phpmd.xml

This file was deleted.

7 changes: 0 additions & 7 deletions src/Commands/ArtifactCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@

/**
* Artifact Command.
*
* @SuppressWarnings(PHPMD.TooManyMethods)
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
* @SuppressWarnings(PHPMD.TooManyFields)
* @SuppressWarnings(PHPMD.ExcessiveClassLength)
*/
class ArtifactCommand extends Command {

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

/**
* Assemble a code artifact from your codebase.
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
protected function doExecute(): void {
$error = NULL;
Expand Down
10 changes: 3 additions & 7 deletions src/Git/ArtifactGitRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

/**
* Artifact git repository.
*
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class ArtifactGitRepository extends GitRepository {

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

foreach ($dirs as $dir) {
if ($dir instanceof \SplFileInfo) {
$dir = $dir->getPathname();
$this->fs->remove($dir);
$this->logger->debug(sprintf('Removing sub-repository "%s"', $this->fsGetAbsolutePath((string) $dir)));
}
$dir = $dir->getPathname();
$this->fs->remove($dir);
$this->logger->debug(sprintf('Removing sub-repository "%s"', $this->fsGetAbsolutePath((string) $dir)));
}

// After removing sub-repositories, the files that were previously tracked
Expand Down
5 changes: 1 addition & 4 deletions src/Traits/FilesystemTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected function fsGetRootDir(): string {
return $this->fsRootDir;
}

if (isset($_SERVER['PWD'])) {
if (isset($_SERVER['PWD']) && is_string($_SERVER['PWD']) && !empty($_SERVER['PWD'])) {
return $_SERVER['PWD'];
}

Expand Down Expand Up @@ -191,9 +191,6 @@ protected function fsAssertPathsExist($paths, bool $strict = TRUE): bool {
* Resolved path.
*
* @see https://stackoverflow.com/a/29372360/712666
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
protected function fsRealpath(string $path): string {
// Whether $path is unix or not.
Expand Down
2 changes: 0 additions & 2 deletions tests/phpunit/Functional/ForcePushModeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

/**
* Class ForcePushTest.
*
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
#[CoversClass(ArtifactCommand::class)]
#[CoversClass(ArtifactGitRepository::class)]
Expand Down
4 changes: 1 addition & 3 deletions tests/phpunit/Traits/ConsoleTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ protected function consoleInitApplicationTester(string|object $object_or_class,

$application->setAutoExit(FALSE);
$application->setCatchExceptions(FALSE);
if (method_exists($application, 'setCatchErrors')) {
$application->setCatchErrors(FALSE);
}

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

$output = '';
try {
$this->appTester->run($input, $options);
$output = $this->appTester->getDisplay();
Expand Down
15 changes: 8 additions & 7 deletions tests/phpunit/Traits/MockTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
* Trait MockTrait.
*
* This trait provides a method to prepare class mock.
*
* @phpstan-ignore trait.unused
*/
trait MockTrait {

Expand All @@ -28,13 +30,9 @@ trait MockTrait {
*
* @return \PHPUnit\Framework\MockObject\MockObject
* Mocked class.
*
* @throws \ReflectionException
*
* @SuppressWarnings(CyclomaticComplexity)
*/
protected function prepareMock(string $class, array $methods = [], array|bool $args = []): MockObject {
$methods = array_filter($methods, fn($value, $key): bool => is_string($key), ARRAY_FILTER_USE_BOTH);
$methods = array_filter($methods, fn($value, $key): bool => !is_numeric($key), ARRAY_FILTER_USE_BOTH);

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

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

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

0 comments on commit 5c98dad

Please sign in to comment.