Skip to content

Add violation remediation to the PHP standards skill - #5

Open
svandragt wants to merge 1 commit into
mainfrom
php-standards-fixing-violations
Open

svandragt wants to merge 1 commit into
mainfrom
php-standards-fixing-violations

Conversation

@svandragt

@svandragt svandragt commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Stacked on #4 — please merge that one first. Both touch skills/php-standards/SKILL.md, and this branch is based on #4, so the diff here will only read correctly once #4 lands. Happy to rebase if #4 changes in review.

The skill covers conventions — the bootstrap pattern, file naming, type hints, the HM-Minimum ruleset — but stops at the point where they are most useful: the moment PHPCS reports a failure and you have two hundred of them to work through.

This adds the sniffs that fire most on HM WordPress projects and the fix each one wants, drawn from putting a plugin through the standards from scratch.

What is in it

  • Fix patterns for the seven sniffs that account for most of a first clean-up run: MissingShort, FunctionComment.Missing, MissingParamTag, LongNotCapital, MissingUnslash, InputNotSanitized, MissingNamespace.
  • The phpcs:ignore placement trap. An ignore between the docblock and the declaration breaks the association, so the sniff reports the docblock as missing and the obvious fix — adding a docblock that is already there — does nothing. Costs an hour the first time.
  • The snake_case rename cascade. Hook callbacks, Mockery expectations and named arguments pass the method name as a string, so no static analysis catches them and a missed one is a fatal error at runtime.

Exclusions: discipline, not a template

The obvious thing to contribute here is a ready-made phpcs.xml. I have deliberately not done that.

A shared ruleset of exclusions turns one team's judgement into everyone's default, minus the reasoning that justified it.

So this frames exclusions as a practice — every <exclude> carries a comment saying why, security sniffs take a per-line phpcs:ignore with a reason instead — and presents only two as genuinely unavoidable:

  • WordPress.WP.I18n, which crashes on PHP 8.x with WPCS 2.x from a trim(null) deprecation inside the sniff.
  • The PSR-4 versus hyphenated-lower filename conflict, which no project using Composer autoloading can satisfy.

What is not in it

No linting pipeline. run-linters already covers discovering and running the tools, and duplicating it here would give two places to update. This assumes you have a failing run and need to fix it.

How we checked

Documentation only — no code, nothing to execute. Every example is generic: no project names, file paths or client integrations. The sniff names were taken from real runs against the HM ruleset rather than from memory.

@svandragt svandragt self-assigned this Sep 21, 2026
Base automatically changed from describe-skills-by-what-users-ask to main September 21, 2026 14:07
The skill covered conventions — the bootstrap pattern, file naming, type
hints — but not what to do when PHPCS reports a failure. This adds the
sniffs that fire most often on HM WordPress projects and the fix each one
wants, the phpcs:ignore placement gotcha that makes a docblock look
missing, and the snake_case rename cascade.

Exclusions are framed as a discipline rather than a template: every
exclude carries a reason, anything security-related takes a per-line
phpcs:ignore instead of a project-wide exclude, and only the WPCS I18n
crash and the PSR-4 filename conflict are presented as unavoidable.

Co-Authored-By: Claude <noreply@anthropic.com>
@svandragt
svandragt force-pushed the php-standards-fixing-violations branch from 1f3ed43 to cdf1155 Compare September 21, 2026 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant