Skip to content

Implement PsrAutoloading in blink - #200

Merged
TomasVotruba merged 1 commit into
mainfrom
blink-psr-autoloading
Oct 10, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
blink-psr-autoloading

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Ports PHP-CS-Fixer's PsrAutoloadingFixer to blink, the only ECS rule previously unported. It was blocked because blink fixers receive just a token stream, while this rule needs the file path to derive the expected class name.

Threading the path

  • tokens.Stream gains a path field with SetPath/Path.
  • The runner sets it per file in fixFile, so the Fixer interface stays unchanged and no other rule is affected.

The fixer

PsrAutoloading renames the single class/interface/trait/enum in a file so its name matches the file basename, and with the dir option corrects namespace casing to the path. It mirrors the upstream logic: skips non-php files, invalid-identifier basenames and stub/fixture paths, bails on more than one namespace or named classy declaration, and ignores anonymous classes and ::class constants.

Set membership

It is opt-in only, matching ECS: not part of psr12/common/default, and explicitly excluded from the per-cs set (which otherwise runs every fixer), so parity corpora are unaffected. It resolves by name for --ecs-config.

Tests and counts

  • Unit tests cover rename, interface/trait/enum, no-op, skip conditions, the ::class and anonymous-class cases, and the dir namespace-casing branch.
  • bin/rule-counts.sh now reports 0 missing rules (blink 210).
  • ecs-rules.txt updated; its stale "NOT YET IMPLEMENTED" list (every entry was already implemented) is cleared.

@TomasVotruba
TomasVotruba enabled auto-merge (squash) October 10, 2026 16:09
@TomasVotruba
TomasVotruba force-pushed the blink-psr-autoloading branch from 55d0bac to 440c4d6 Compare October 10, 2026 16:13
@TomasVotruba
TomasVotruba merged commit f894dfb into main Oct 10, 2026
20 checks passed
@TomasVotruba
TomasVotruba deleted the blink-psr-autoloading branch October 10, 2026 16:15
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