diff --git a/.github/workflows/cs.yml b/.github/workflows/cs.yml
index 00b6a01..554bc00 100644
--- a/.github/workflows/cs.yml
+++ b/.github/workflows/cs.yml
@@ -40,10 +40,26 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
+ - name: Determine the base branch for the file diff
+ id: base_branch
+ env:
+ BASE_REF: ${{ github.base_ref }}
+ run: |
+ if [ "${{ github.event_name }}" == "pull_request" ]; then
+ echo "NAME=$BASE_REF" >> $GITHUB_OUTPUT
+ echo "REF=origin/$BASE_REF" >> $GITHUB_OUTPUT
+ else
+ echo 'NAME=main' >> $GITHUB_OUTPUT
+ echo "REF=origin/main" >> $GITHUB_OUTPUT
+ fi
+
+ - name: Fetch base branch
+ run: git fetch --no-tags --depth=1 origin ${{ steps.base_branch.outputs.NAME }}
+
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
- php-version: '7.4'
+ php-version: 'latest'
coverage: none
tools: cs2pr
@@ -60,12 +76,18 @@ jobs:
# Bust the cache at least once a month - output format: YYYY-MM.
custom-cache-suffix: $(date -u "+%Y-%m")
- # Check the codestyle of the files.
- # The results of the CS check will be shown inline in the PR via the CS2PR tool.
+ # Check the codestyle of the files against a threshold of expected errors and warnings.
+ - name: Check PHP code style against the thresholds
+ run: composer check-cs-thresholds
+
+ # Check the codestyle only of the files which were changed in the current branch.
+ # This step will only be executed if the threshold check exited with a failure status.
+ # The results of this CS check will be shown inline in the PR via the CS2PR tool.
# @link https://github.com/staabm/annotate-pull-request-from-checkstyle/
- - name: Check PHP code style
+ - name: Check PHP code style for the changes made in the branch only
+ if: ${{ failure() }}
id: phpcs
- run: composer check-cs-warnings -- --no-cache --report-full --report-checkstyle=./phpcs-report.xml
+ run: composer check-branch-cs -- ${{ steps.base_branch.outputs.REF }}
- name: Show PHPCS results in PR
if: ${{ always() && steps.phpcs.outcome == 'failure' }}
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index ac6ef4d..e05c313 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -69,12 +69,9 @@ jobs:
coverage: ${{ matrix.coverage == true && 'xdebug' || 'none' }}
tools: cs2pr
- # YoastCS has a minimum PHP requirement of 5.4, so remove it and hard require Parallel Lint.
- - name: Adjust Composer dependencies (PHP 5.3)
- if: matrix.php_version == '5.3'
- run: |
- composer remove --dev --no-update --no-scripts yoast/yoastcs --no-interaction
- composer require --dev --no-update --no-scripts php-parallel-lint/php-parallel-lint --no-interaction
+ # 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
# Install dependencies and handle caching in one go.
# @link https://github.com/marketplace/actions/install-php-dependencies-with-composer
diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist
index 5c2d752..570f3b9 100644
--- a/.phpcs.xml.dist
+++ b/.phpcs.xml.dist
@@ -8,7 +8,7 @@
@@ -39,7 +39,7 @@
-
+
@@ -52,8 +52,12 @@
-
-
+
+
+
+
+
+
@@ -83,19 +87,23 @@
#############################################################################
-->
-
+
-
-
-
+
+
+
+ /tests/*\.php
-
+
-
-
+
+
+
+
+
@@ -118,15 +126,24 @@
/src/facades/wordpress\.php$
+
+
+ 0
+
+
+
+ /tests/Unit/Doubles/WPCoreFunctionsMock\.php$
+
-
+
5
@@ -154,12 +171,4 @@
/src/Whip_Host\.php$
-
-
- /tests/Unit/bootstrap\.php$
-
-
- /tests/Unit/WPMessageDismissListenerTest\.php$
-
-
diff --git a/composer.json b/composer.json
index 78e440c..c407e48 100644
--- a/composer.json
+++ b/composer.json
@@ -19,9 +19,11 @@
"php": ">=5.3"
},
"require-dev": {
+ "php-parallel-lint/php-console-highlighter": "^1.0.0",
+ "php-parallel-lint/php-parallel-lint": "^1.3.2",
"phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0",
"roave/security-advisories": "dev-master",
- "yoast/yoastcs": "^2.3.0"
+ "yoast/yoastcs": "^3.0"
},
"minimum-stability": "dev",
"prefer-stable": true,
@@ -54,7 +56,7 @@
"Yoast\\WHIP\\Config\\Composer\\Actions::check_coding_standards"
],
"check-cs-thresholds": [
- "@putenv YOASTCS_THRESHOLD_ERRORS=0",
+ "@putenv YOASTCS_THRESHOLD_ERRORS=8",
"@putenv YOASTCS_THRESHOLD_WARNINGS=0",
"Yoast\\WHIP\\Config\\Composer\\Actions::check_cs_thresholds"
],
diff --git a/config/composer/actions.php b/config/composer/actions.php
index 5e2d730..23cb96a 100644
--- a/config/composer/actions.php
+++ b/config/composer/actions.php
@@ -18,6 +18,8 @@ class Actions {
* Provides a coding standards option choice.
*
* @param Event $event Composer event.
+ *
+ * @return void
*/
public static function check_coding_standards( Event $event ) {
$io = $event->getIO();
diff --git a/tests/Unit/WPMessageDismissListenerTest.php b/tests/Unit/WPMessageDismissListenerTest.php
index c99b4b0..00ff2ae 100644
--- a/tests/Unit/WPMessageDismissListenerTest.php
+++ b/tests/Unit/WPMessageDismissListenerTest.php
@@ -8,6 +8,8 @@
* Message Dismiss Listener unit tests.
*
* @coversDefaultClass Whip_WPMessageDismissListener
+ *
+ * @phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded -- Acronym throws the count off.
*/
final class WPMessageDismissListenerTest extends TestCase {