From 4d6d59f5c2b90fcf6f18cd77ed064ade606fdb33 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 12 Dec 2021 03:24:08 +0100 Subject: [PATCH 1/3] PHPCS: use PHP-Code-Style 2.0 * Composer: require `php-parallel-lint/php-code-style` at 2.0 or higher. * Composer: remove the requirement for PHPCS. This will now be inherited from the code style repo. * GH Actions, test workflow: adjust the removal of the PHPCS dependency to match. --- .github/workflows/test.yml | 4 ++-- composer.json | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4be6154..4f4c881 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -40,10 +40,10 @@ jobs: coverage: none tools: cs2pr - # Remove PHPCS as it has a minimum PHP requirements of PHP 5.4 and would block install on PHP 5.3. + # Remove the PHPCS standard as it has a minimum PHP requirements of PHP 5.4 and would block install on PHP 5.3. - name: 'Composer: remove PHPCS' if: ${{ matrix.php < 5.4 }} - run: composer remove --dev squizlabs/php_codesniffer --no-update + run: composer remove --dev php-parallel-lint/php-code-style --no-update # Install dependencies and handle caching in one go. # @link https://github.com/marketplace/actions/install-composer-dependencies diff --git a/composer.json b/composer.json index 26ffde8..a9098b0 100644 --- a/composer.json +++ b/composer.json @@ -21,8 +21,7 @@ "phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0", "php-parallel-lint/php-parallel-lint": "^1.0", "php-parallel-lint/php-var-dump-check": "0.*", - "squizlabs/php_codesniffer": "3.*", - "php-parallel-lint/php-code-style": "1.0" + "php-parallel-lint/php-code-style": "^2.0" }, "replace": { "jakub-onderka/php-console-color": "*" From 6ecc4f395fa0b4f7e596641f4fc7b4cd2fb7a365 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 12 Dec 2021 03:26:55 +0100 Subject: [PATCH 2/3] Ruleset: various tweaks for PHP-Code-Style 2.0 * Scan all PHP files, not just the file in `src` for improved consistency across the code base, but exclude the `vendor` and the `build` (code coverage) directories. * Enable parallel scanning for faster results. * Use the ruleset from PHP-Code-Style by name. * Set the `testVersion` for use with PHPCompatibility. * Include minimal documentation in the ruleset. --- phpcs.xml.dist | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index eec5d27..e4e75a8 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -1,8 +1,20 @@ - + A coding standard for Jakub Onderka's projects. - ./src/ + + + + . + + + */build/* + */vendor/* @@ -13,6 +25,19 @@ - + + + + + + + + + + From a9f4652251a41ab67fbcc6716806ba1781932be1 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 12 Dec 2021 03:28:16 +0100 Subject: [PATCH 3/3] CS: various minor fixes Fix up the issues which will be flagged by PHP-Code-Style 2.0 and explicitly ignore a couple of (non-)issues. Includes no longer allowing warnings in the GH Actions build. --- .github/workflows/cs.yml | 2 +- example.php | 1 + src/ConsoleColor.php | 6 +++++- src/InvalidStyleException.php | 3 ++- tests/ConsoleColorTest.php | 2 +- tests/Fixtures/ConsoleColorWithForceSupport.php | 1 + 6 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/cs.yml b/.github/workflows/cs.yml index c63eeac..7bc8296 100644 --- a/.github/workflows/cs.yml +++ b/.github/workflows/cs.yml @@ -38,4 +38,4 @@ jobs: run: vendor/bin/phpcs --report-full --report-checkstyle=./checkstyle.xml - name: Show PHPCS results in PR - run: cs2pr ./checkstyle.xml --graceful-warnings + run: cs2pr ./checkstyle.xml diff --git a/example.php b/example.php index 3ac1b2d..5432e32 100644 --- a/example.php +++ b/example.php @@ -1,4 +1,5 @@ themes[$s])) { $sequences = array_merge($sequences, $this->themeSequence($s)); - } else if ($this->isValidStyle($s)) { + } elseif ($this->isValidStyle($s)) { $sequences[] = $this->styleSequence($s); } else { throw new InvalidStyleException($s); @@ -203,6 +204,7 @@ public function removeTheme($name) public function isSupported() { if (DIRECTORY_SEPARATOR === '\\') { + // phpcs:ignore Generic.PHP.NoSilencedErrors,PHPCompatibility.FunctionUse.NewFunctions.sapi_windows_vt100_supportFound if (function_exists('sapi_windows_vt100_support') && @sapi_windows_vt100_support(STDOUT)) { return true; } elseif (getenv('ANSICON') !== false || getenv('ConEmuANSI') === 'ON') { @@ -210,6 +212,7 @@ public function isSupported() } return false; } else { + // phpcs:ignore Generic.PHP.NoSilencedErrors return function_exists('posix_isatty') && @posix_isatty(STDOUT); } } @@ -222,6 +225,7 @@ public function isSupported() public function are256ColorsSupported() { if (DIRECTORY_SEPARATOR === '\\') { + // phpcs:ignore Generic.PHP.NoSilencedErrors,PHPCompatibility.FunctionUse.NewFunctions.sapi_windows_vt100_supportFound return function_exists('sapi_windows_vt100_support') && @sapi_windows_vt100_support(STDOUT); } else { return strpos(getenv('TERM'), '256color') !== false; diff --git a/src/InvalidStyleException.php b/src/InvalidStyleException.php index c8d71b0..b06501e 100644 --- a/src/InvalidStyleException.php +++ b/src/InvalidStyleException.php @@ -1,4 +1,5 @@