Skip to content

Closes #39 Add PHPCS and PHPStan static analysis to CI - #43

Merged
remyperona merged 2 commits into
developfrom
add/39-phpcs-phpstan-ci
Aug 13, 2026
Merged

Closes #39 Add PHPCS and PHPStan static analysis to CI#43
remyperona merged 2 commits into
developfrom
add/39-phpcs-phpstan-ci

Conversation

@remyperona

Copy link
Copy Markdown
Contributor

🤖 AI-generated — created by an automated pipeline. Review before acting on this.

Closes #39

Description

This wires PHPCS and PHPStan into CI for the wp-media/phpunit package, adding static analysis gatekeeping while maintaining a green build.

What was done

New CI workflows:

  • .github/workflows/phpcs.yml and .github/workflows/phpstan.yml — thin callers to the shared reusable workflows wp-media/workflows/.github/workflows/{phpcs,phpstan}.yml@main (pull_request + workflow_dispatch, with concurrency cancellation).

Configuration files:

  • phpcs.xml.dist — WP Media ruleset derived from wp-media/mcp-oauth, adapted for this package (no i18n text-domain rule since this is a test-utility library, PrefixAllGlobals prefix wpmedia, testVersion 7.4-). Scoped to Integration/HttpRequestTrait.php — the reference file that already meets the WP Media bar. Scope is intended to widen opportunistically as files are touched.
  • phpstan.neon.dist — level 5, scanning the root source files + Integration/, Unit/, Fixtures/, Tests/, with WordPress stubs. Generated phpstan-baseline.neon (76 pre-existing findings) keeps the gate green today while catching new issues going forward.

Composer updates:

  • Added dev deps: phpcs, phpstan toolchain, dealerdirect installer, phpcompatibility-wp, wordpress-tests-stubs, phpstan extensions, szepeviktor/phpstan-wordpress, wpcs.
  • Added allow-plugins configuration.
  • Added phpcs, phpcs:fix, and phpstan composer scripts.

Source changes:

  • Integration/HttpRequestTrait.php — added 3 missing method docblocks only (no logic change) to pass PHPCS cleanly as the reference file.
  • .gitignore — ignore phpcs-report.xml.

Verification: composer phpcs → 0 errors; composer phpstan → 0 errors (with baseline); full test suite green (unit 91 tests, integration 28, integration-admin 3). composer.lock is gitignored and intentionally not committed.

Type of change

  • New feature (static analysis CI workflows)
  • Enhancement to existing feature
  • Bug fix
  • Breaking change
  • Documentation update

Affected features & QA scope

  • CI pipeline (phpcs.yml, phpstan.yml)
  • Composer toolchain and scripts
  • Integration test utilities (HttpRequestTrait docblocks)

Technical description

The implementation wires in reusable workflows from wp-media/workflows to execute PHPCS and PHPStan, avoiding code duplication across wp-media projects. PHPCS is scoped to a single reference file initially to avoid a big-bang reformat; PHPStan level 5 runs on all test code and source with a baseline for pre-existing findings. This keeps CI green while establishing a foundation for gradual code quality improvement.

New dependencies

  • phpcs (PHPCS ruleset tool)
  • dealerdirect/composer-plugin-phpcodesniffer-standards-installer
  • phpcompatibility/php-compatibility
  • phpcompatibility/phpcompatibility-wp
  • wordpress/wordpress-tests-stubs
  • phpstan/phpstan
  • phpstan/extension-installer
  • phpstan/phpstan-mockery
  • phpstan/phpstan-phpunit
  • szepeviktor/phpstan-wordpress
  • wp-coding-standards/wpcs

Risks

None identified. Static analysis does not affect runtime behavior. The baseline ensures no new CI failures on existing code.

Wire in the reusable wp-media/workflows PHPCS and PHPStan workflows via
`uses:` rather than reimplementing them, and add the corresponding
composer scripts and dev dependencies.

To keep CI green without a big-bang rewrite of the ~19 pre-existing
source files:
- PHPStan (level 5) ships with a generated `phpstan-baseline.neon`
  covering the 76 pre-existing findings, so only new issues fail CI.
- PHPCS is scoped to `Integration/HttpRequestTrait.php` only, the file
  already adopted as the WP Media reference style (declare(strict_types=1),
  full docblocks). A job that only `uses:` a reusable workflow cannot
  carry `continue-on-error`, so scoping the ruleset is the simplest way
  to avoid failing the build on untouched files while leaving room to
  widen the ruleset as files are brought up to standard opportunistically.

HttpRequestTrait.php gets 3 missing method docblocks added (no logic
change) so it passes PHPCS cleanly as the reference file.

Co-Authored-By: Sonnet 5 <noreply@anthropic.com>
@remyperona remyperona self-assigned this Aug 13, 2026
Bump phpstan/phpstan to ^2.0 and the related packages
(phpstan-mockery, phpstan-phpunit, szepeviktor/phpstan-wordpress) to
their v2 releases; extension-installer to ^1.4.

Regenerate phpstan-baseline.neon under v2. The new phpunit.coversMethod
rule (enabled by bleedingEdge in phpstan-phpunit v2) flags pre-existing
@Covers annotations in the test fixtures; it is suppressed by identifier
in phpstan.neon.dist rather than baselined, because the v2 baseline
generator mangles @-leading messages (@@Covers) so they never re-match.

composer phpstan and composer phpcs both pass clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@remyperona
remyperona marked this pull request as ready for review August 13, 2026 20:31
@remyperona remyperona changed the title feat(ci): add PHPCS and PHPStan static analysis to CI (#39) Closes #39 Add PHPCS and PHPStan static analysis to CI Aug 13, 2026
@remyperona remyperona linked an issue Aug 13, 2026 that may be closed by this pull request
@remyperona
remyperona merged commit aacc9ca into develop Aug 13, 2026
9 checks passed
@remyperona
remyperona deleted the add/39-phpcs-phpstan-ci branch August 13, 2026 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add PHPCS + PHPStan to CI; standardize on strict_types

1 participant