From 2a5fcbefa3235f00194ead3424ee644502218343 Mon Sep 17 00:00:00 2001 From: "K. Adam White" Date: Mon, 3 Aug 2026 15:42:54 -0400 Subject: [PATCH 1/3] Add PHPCS and HM Coding Standards to project --- composer.json | 14 +++++++++++++- phpcs.xml | 21 +++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 phpcs.xml diff --git a/composer.json b/composer.json index 599440d..531f32c 100644 --- a/composer.json +++ b/composer.json @@ -5,11 +5,23 @@ "require": { "composer/installers": "^1 || ^2" }, + "require-dev": { + "humanmade/coding-standards": "^2.3" + }, "license": "GPL-2.0-or-later", "authors": [ { "name": "Human Made Limited", "email": "engineering@humanmade.com" } - ] + ], + "scripts": { + "lint": "phpcs" + }, + "config": { + "allow-plugins": { + "composer/installers": true, + "dealerdirect/phpcodesniffer-composer-installer": true + } + } } diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..d8f25ae --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,21 @@ + + + PHPCS config for the HM Query Loop plugin + + + + + + + . + + /build/* + /src/* + /node_modules/* + /tests/* + /vendor/* + + + + + From 05b4198863e08a1b737029350edabca151a3bd0c Mon Sep 17 00:00:00 2001 From: "K. Adam White" Date: Mon, 3 Aug 2026 15:43:27 -0400 Subject: [PATCH 2/3] CI: Introduce PHPCS scan on pull request --- .github/workflows/php-standards.yml | 54 +++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 .github/workflows/php-standards.yml diff --git a/.github/workflows/php-standards.yml b/.github/workflows/php-standards.yml new file mode 100644 index 0000000..091d2b9 --- /dev/null +++ b/.github/workflows/php-standards.yml @@ -0,0 +1,54 @@ +name: PHP Code Quality + +on: + push: + branches: + - main + paths: + - '**.php' + - 'phpcs.xml' + - 'composer.json' + - 'composer.lock' + pull_request: + types: + - opened + - reopened + - synchronize + - ready_for_review + # Only run when PHP or the coding standards configuration change. + paths: + - '**.php' + - 'phpcs.xml' + - 'composer.json' + - 'composer.lock' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + phpcs: + name: PHPCS + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + + - name: Set up PHP + uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # 2.37.2 + with: + php-version: '8.2' + coverage: none + tools: cs2pr + + - name: Install Composer dependencies + run: composer install --no-progress --no-interaction --no-ansi + + - name: Run PHPCS + id: phpcs + run: composer lint -- --report-full --report-checkstyle=phpcs-report.xml + + - name: Annotate PR with PHPCS results + if: ${{ always() && steps.phpcs.outcome == 'failure' }} + run: cs2pr ./phpcs-report.xml From 26ce79e01b5b04e810f3fd97d33f7206b3f99252 Mon Sep 17 00:00:00 2001 From: "K. Adam White" Date: Mon, 3 Aug 2026 15:47:06 -0400 Subject: [PATCH 3/3] PHPCS: Escape name (slug) of query preset when logging doing-it-wrong notice --- inc/query-presets.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/query-presets.php b/inc/query-presets.php index c211bf0..fa28f0c 100644 --- a/inc/query-presets.php +++ b/inc/query-presets.php @@ -36,7 +36,7 @@ function register_query_preset( string $name, string $label, callable $callback sprintf( /* translators: %s: preset name */ esc_html__( 'Query preset "%s" is already registered.', 'hm-query-loop' ), - $name + esc_attr( $name ) ), '1.0.0' );