From d42ef7f7e9624a68b3f4669b2dea91b43f0ee2d1 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 14 Dec 2023 22:03:53 +0100 Subject: [PATCH] Composer/PHPCS: update to YoastCS 3.0.0 YoastCS 3.0.0 has been released and is based on WordPressCS 3.0.0. This commit makes the necessary updates for that: * Composer: update the requirements. * PHPCS ruleset: - Exclude new WP specific rules which don't apply to this package. - Exclude code modernization sniffs which can't be applied to this package yet. - Enforce strict PSR-4 for both src and tests. - Add a few selective exclusions for specific situations. * GHA CS workflow: run the CS check on the latest PHP version. No need to run on PHP 7.4 any more as the deprecations previously encountered were all fixed. * Add one selective ignore annotation for a long closure (autoloader in the test bootstrap). While YoastCS 3.0.0 contains lots of goodies, it also has a downside: a minimum PHP requirement of PHP 7.2, which conflicts with the minimum supported PHP version of this package. This causes two issues: 1. A plain `composer install` will no longer work on PHP < 7.2. This means the YoastCS package will need to be removed for the CI linting and test workfows. 2. As the (Parallel) linting packages are "inherited" from YoastCS, removing YoastCS would break the linting command in CI, so we need to `require-dev` the Parallel Lint packages in PHPUnit Polyfills itself to allow the workflow to continue to work. With those two work-arounds in place, everything should work again. Refs: * https://github.com/Yoast/yoastcs/releases/tag/3.0.0 * https://github.com/WordPress/WordPress-Coding-Standards/releases/tag/3.0.0 --- .github/workflows/cs.yml | 2 +- .github/workflows/lint.yml | 4 +++ .github/workflows/test.yml | 4 +++ .phpcs.xml.dist | 56 +++++++++++++++++++++++++++++++------- composer.json | 4 ++- tests/bootstrap.php | 2 ++ 6 files changed, 60 insertions(+), 12 deletions(-) diff --git a/.github/workflows/cs.yml b/.github/workflows/cs.yml index 2fb7ee0..5224897 100644 --- a/.github/workflows/cs.yml +++ b/.github/workflows/cs.yml @@ -25,7 +25,7 @@ jobs: - name: Install PHP uses: shivammathur/setup-php@v2 with: - php-version: '7.4' + php-version: 'latest' coverage: none tools: cs2pr diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 8fe406d..fc1567b 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -37,6 +37,10 @@ jobs: ini-values: zend.assertions=1, error_reporting=-1, display_errors=On coverage: none + # YoastCS 3.0 has a PHP 7.2 minimum which conflicts with the requirements of this package. + - name: 'Composer: remove YoastCS' + run: composer remove --dev yoast/yoastcs --no-update --no-interaction + - name: 'Composer: remove PHPUnit (not needed for lint)' run: composer remove phpunit/phpunit --no-update --no-interaction diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0369226..28f9310 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -104,6 +104,10 @@ jobs: ini-values: zend.assertions=1, error_reporting=-1, display_errors=On coverage: ${{ matrix.coverage == true && 'xdebug' || 'none' }} + # YoastCS 3.0 has a PHP 7.2 minimum which conflicts with the requirements of this package. + - name: 'Composer: remove YoastCS' + run: composer remove --dev yoast/yoastcs --no-update --no-interaction + - name: 'Composer: set PHPUnit version for tests' if: ${{ matrix.phpunit != 'auto' }} run: composer require --no-update phpunit/phpunit:"${{ matrix.phpunit }}" --no-interaction diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist index 96089f1..df41f1b 100644 --- a/.phpcs.xml.dist +++ b/.phpcs.xml.dist @@ -5,7 +5,7 @@ @@ -49,8 +49,18 @@ - + + + + + + + + + + + - + + + *\.php + + + /src/Polyfills/AssertObjectProperty\.php$ + + + /src/Polyfills/AssertionRenames\.php$ + + /src/Helpers/ResourceHelper\.php$ - /src/Polyfills/AssertClosedResource*\.php$ /src/Helpers/ResourceHelper\.php$ - /src/Polyfills/AssertClosedResource*\.php$ @@ -136,11 +155,28 @@ /src/Polyfills/ExpectException\.php$ + + + + + /tests/*/Fixtures/*\.php$ + + + + + /tests/Polyfills/Fixtures/ValueObject*\.php$ + + /tests/*\.php$ + + + /tests/* + + /tests/TestCases/TestCaseTestTrait\.php$ diff --git a/composer.json b/composer.json index db826c7..b79266d 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,9 @@ "phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0" }, "require-dev": { - "yoast/yoastcs": "^2.3.0" + "php-parallel-lint/php-console-highlighter": "^1.0.0", + "php-parallel-lint/php-parallel-lint": "^1.3.2", + "yoast/yoastcs": "^3.0.0" }, "minimum-stability": "dev", "prefer-stable": true, diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 3ca3a3a..e4076ae 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -5,6 +5,7 @@ if ( \defined( '__PHPUNIT_PHAR__' ) ) { require_once \dirname( __DIR__ ) . '/phpunitpolyfills-autoload.php'; + // phpcs:disable Universal.FunctionDeclarations.NoLongClosures.ExceedsMaximum \spl_autoload_register( /** * Custom PSR-4 based autoloader for test helper files. @@ -32,6 +33,7 @@ static function ( $fqClassName ) { return false; } ); + // phpcs:enable } elseif ( \file_exists( \dirname( __DIR__ ) . '/vendor/autoload.php' ) ) { /*