Skip to content

Commit 061d1a7

Browse files
committed
Add CI: lint, coding standards and PHP compatibility
The repository is the canonical source for framework files copied into every plugin, but had no checks of its own — its PHP was only ever linted by hand using another plugin's phpcbf. Adds a composer.json carrying the dev tooling and three workflows running php -l across 7.4-8.5, PHPCS against the existing ruleset, and PHPCompatibility for 7.4-8.6.
1 parent 563e21d commit 061d1a7

8 files changed

Lines changed: 636 additions & 2 deletions

File tree

‎.github/workflows/cs.yml‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Coding Standards
2+
3+
on:
4+
# Run on all pushes and on all pull requests.
5+
push:
6+
pull_request:
7+
# Allow manually triggering the workflow.
8+
workflow_dispatch:
9+
10+
jobs:
11+
checkcs:
12+
name: 'PHPCS check'
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v6
18+
19+
- name: Install PHP
20+
uses: shivammathur/setup-php@v2
21+
with:
22+
php-version: '8.0'
23+
tools: cs2pr
24+
coverage: none
25+
26+
# Install dependencies and handle caching in one go.
27+
# @link https://github.com/marketplace/actions/install-composer-dependencies
28+
- name: Install Composer dependencies
29+
uses: "ramsey/composer-install@v4"
30+
31+
# Check the code-style consistency of the PHP files.
32+
- name: Check PHP code style
33+
continue-on-error: true
34+
run: vendor/bin/phpcs --report-full --report-checkstyle=./phpcs-report.xml
35+
36+
- name: Show PHPCS results in PR
37+
run: cs2pr --graceful-warnings ./phpcs-report.xml

‎.github/workflows/lint.yml‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Lint
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
8+
jobs:
9+
lint:
10+
name: 'PHP Lint (${{ matrix.php }})'
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
# Oldest supported, the version PHPCS runs on, current stable and newest.
17+
php: ['7.4', '8.0', '8.3', '8.5']
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v6
22+
23+
- name: Install PHP
24+
uses: shivammathur/setup-php@v2
25+
with:
26+
php-version: ${{ matrix.php }}
27+
coverage: none
28+
29+
# These files are copied into plugins that support PHP 7.4 and up, so
30+
# every one of them has to parse on every supported version.
31+
- name: Check PHP syntax
32+
run: |
33+
find . -name '*.php' \
34+
-not -path './vendor/*' \
35+
-not -path './_site/*' \
36+
-print0 | xargs -0 -n1 -P4 php -l

‎.github/workflows/phpcompat.yml‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: PHP Compatibility
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch: {}
7+
8+
jobs:
9+
phpcompat:
10+
name: 'PHP Compatibility Check'
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v6
16+
17+
- name: Install PHP
18+
uses: shivammathur/setup-php@v2
19+
with:
20+
php-version: '8.0'
21+
coverage: none
22+
23+
# Create isolated environment for PHPCompatibility with PHPCS 4.x
24+
- name: Setup PHPCompatibility
25+
run: |
26+
mkdir phpcompat-tools
27+
cd phpcompat-tools
28+
composer init --name="temp/phpcompat" --type=project --no-interaction
29+
composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
30+
composer require --dev \
31+
squizlabs/php_codesniffer:"^4.0" \
32+
phpcompatibility/php-compatibility:"dev-develop" \
33+
dealerdirect/phpcodesniffer-composer-installer:"^1.0" \
34+
--no-interaction
35+
36+
# Check PHP 7.4 through 8.6 compatibility
37+
- name: Check PHP Compatibility (7.4-8.6)
38+
run: |
39+
cd phpcompat-tools
40+
./vendor/bin/phpcs -p \
41+
--standard=PHPCompatibility \
42+
--runtime-set testVersion 7.4-8.6 \
43+
--extensions=php \
44+
--ignore=*/vendor/*,*/node_modules/*,*/_site/* \
45+
../ || exit_code=$?
46+
47+
# Exit with the phpcs exit code (if set)
48+
exit ${exit_code:-0}

‎.gitignore‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
/build/
44
.commandcode/
55

6+
# Composer
7+
/vendor/
8+
/phpcompat-tools/
9+
/phpcs-report.xml
10+
611
.devin/
712

813
# Testing

‎AGENTS.md‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,20 @@ Not a standalone WordPress plugin — no WordPress.org listing or webberzone.com
2020

2121
WebberZone Settings API is a reusable PHP library wrapping the native WordPress Settings API, powering admin interfaces across WebberZone plugins (Better Search, Contextual Related Posts, Knowledge Base, etc.). Not distributed as a Composer package — consuming plugins copy the files into their own source tree, adjusting namespace, prefix, and option key.
2222

23-
No `composer.json`, `package.json`, or build system. CSS/JS assets are committed as both source and pre-minified files. No automated tests.
23+
No `package.json` or build system. CSS/JS assets are committed as both source and pre-minified files. There are no unit tests — the library has no bootstrappable runtime of its own, so CI verifies it statically instead.
24+
25+
## Commands
26+
27+
```bash
28+
composer install # dev tooling only; nothing ships from vendor/
29+
composer test # lint + phpcs + phpcompat — the full check
30+
composer phpcbf # auto-fix code style; run before committing PHP
31+
composer phpcs
32+
composer lint # php -l across every PHP file
33+
composer phpcompat # PHP 7.4-8.6 compatibility
34+
```
35+
36+
CI runs the same three checks on every push and pull request (`.github/workflows/`). PHPStan is deliberately absent: `get_taxonomies( $args, 'objects' )` is typed `array<int, WP_Taxonomy>` in `php-stubs/wordpress-stubs` when WordPress actually returns a string-keyed array, which makes the `public_taxonomies` loop in `class-settings.php` report six cascading false positives.
2437

2538
## Repository structure
2639

‎CLAUDE.md‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,20 @@ Not a standalone WordPress plugin — no WordPress.org listing or webberzone.com
2020

2121
WebberZone Settings API is a reusable PHP library wrapping the native WordPress Settings API, powering admin interfaces across WebberZone plugins (Better Search, Contextual Related Posts, Knowledge Base, etc.). Not distributed as a Composer package — consuming plugins copy the files into their own source tree, adjusting namespace, prefix, and option key.
2222

23-
No `composer.json`, `package.json`, or build system. CSS/JS assets are committed as both source and pre-minified files. No automated tests.
23+
No `package.json` or build system. CSS/JS assets are committed as both source and pre-minified files. There are no unit tests — the library has no bootstrappable runtime of its own, so CI verifies it statically instead.
24+
25+
## Commands
26+
27+
```bash
28+
composer install # dev tooling only; nothing ships from vendor/
29+
composer test # lint + phpcs + phpcompat — the full check
30+
composer phpcbf # auto-fix code style; run before committing PHP
31+
composer phpcs
32+
composer lint # php -l across every PHP file
33+
composer phpcompat # PHP 7.4-8.6 compatibility
34+
```
35+
36+
CI runs the same three checks on every push and pull request (`.github/workflows/`). PHPStan is deliberately absent: `get_taxonomies( $args, 'objects' )` is typed `array<int, WP_Taxonomy>` in `php-stubs/wordpress-stubs` when WordPress actually returns a string-keyed array, which makes the `public_taxonomies` loop in `class-settings.php` report six cascading false positives.
2437

2538
## Repository structure
2639

‎composer.json‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"name": "webberzone/settings-api",
3+
"description": "Reusable settings framework wrapping the WordPress Settings API, shared across WebberZone plugins.",
4+
"type": "library",
5+
"license": "gpl-2.0-or-later",
6+
"authors": [
7+
{
8+
"name": "Ajay D'Souza",
9+
"homepage": "https://webberzone.com"
10+
}
11+
],
12+
"require": {
13+
"php": ">=7.4"
14+
},
15+
"require-dev": {
16+
"wp-coding-standards/wpcs": "^3",
17+
"dealerdirect/phpcodesniffer-composer-installer": "^1"
18+
},
19+
"config": {
20+
"allow-plugins": {
21+
"dealerdirect/phpcodesniffer-composer-installer": true
22+
}
23+
},
24+
"scripts": {
25+
"phpcs": "vendor/bin/phpcs -p -s --standard=phpcs.xml.dist",
26+
"phpcbf": "vendor/bin/phpcbf -p -s --standard=phpcs.xml.dist",
27+
"lint": "find . -name '*.php' -not -path './vendor/*' -not -path './phpcompat-tools/*' -not -path './_site/*' -print0 | xargs -0 -n1 -P8 php -l > /dev/null",
28+
"phpcompat:setup": [
29+
"@php -r \"if (!is_dir('phpcompat-tools')) { mkdir('phpcompat-tools'); }\"",
30+
"@php -r \"if (!file_exists('phpcompat-tools/composer.json')) { file_put_contents('phpcompat-tools/composer.json', '{\\\"name\\\":\\\"temp/phpcompat\\\",\\\"type\\\":\\\"project\\\"}'); }\"",
31+
"@composer config --working-dir=phpcompat-tools allow-plugins.dealerdirect/phpcodesniffer-composer-installer true",
32+
"@composer require --working-dir=phpcompat-tools --dev --quiet --no-interaction squizlabs/php_codesniffer:^4.0 phpcompatibility/php-compatibility:dev-develop dealerdirect/phpcodesniffer-composer-installer:^1.0"
33+
],
34+
"phpcompat": [
35+
"@phpcompat:setup",
36+
"phpcompat-tools/vendor/bin/phpcs -p --standard=PHPCompatibility --runtime-set testVersion 7.4-8.6 --extensions=php --ignore=*/vendor/*,*/node_modules/*,*/phpcompat-tools/*,*/_site/* ."
37+
],
38+
"phpcompat:clean": "rm -rf phpcompat-tools",
39+
"test": [
40+
"@lint",
41+
"@phpcs",
42+
"@phpcompat"
43+
]
44+
}
45+
}

0 commit comments

Comments
 (0)