Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Code Sniffer Laravel Package

php-collective/code-sniffer

A PHP_CodeSniffer ruleset that follows PSR-2 and PSR-12 with many extra fixers on top, plus a stricter PhpCollectiveStrict standard. Install via Composer, add it to phpcs.xml, and run phpcs/phpcbf or composer scripts to check and auto-fix code style.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture fit

  • The package is a ruleset distribution, not a framework or runtime library. It layers declarative PHP_CodeSniffer (phpcs/phpcbf) rules over PSR-2/PSR-12 and bundles ~251 sniffs across Generic, PSR1/2/12, Slevomat, and 88 PhpCollective-specific sniffs, with a stricter PhpCollectiveStrict variant.
  • Integration surface is intentionally narrow: a ruleset.xml reference in the project root, vendor/bin/ppcs invocations, and Composer require-dev. It has zero runtime coupling to application code, so architectural fit is essentially "fits any Composer-based PHP 8.1+ codebase."
  • The value proposition is opinionation, not novelty: it packages conventions (docblocks, type hints, array syntax, namespace/use ordering, test conventions) that would otherwise require hand-assembling PHPCS + Slevomat rules. For a Laravel shop, that is complementary to, not a replacement for, a formatter like Pint.
  • It appears descended from the CakePHP/PhpCollective sniffer lineage; the rule names (PhpCollective.*, PhpCollectiveStrict.*) confirm a house style rather than an ecosystem-neutral standard.
  • 0.6.9 does not change the architecture. It is a correctness release: three fixers in the Commenting and PHP namespaces were repaired. Fit assessment is unchanged.

Integration feasibility

  • High. composer require --dev php-collective/code-sniffer, add a phpcs.xml referencing vendor/php-collective/code-sniffer/PhpCollective/ruleset.xml, add cs-check/cs-fix Composer scripts, wire into CI. README also documents --config-set installed_paths/default_standard and PhpStorm external-tool setup, which lowers developer-adoption friction.
  • Two standards are shipped (PhpCollective and stricter PhpCollectiveStrict), enabling a phased rollout rather than a single big-bang gate.
  • Constraint to verify: PHP >= 8.1 and an implicit dependency on a compatible PHP_CodeSniffer major and the bundled Slevomat version. If the project already requires slevomat/coding-standard or squizlabs/php_codesniffer directly, version conflicts are plausible and must be checked before adoption.
  • The 0.6.9 release adds one behavior change that affects feasibility of a simple upgrade: PhpCollective.Commenting.DocBlockThrows now detects qualified relative exception names (throw new Sub\NestedException()) that it previously skipped, and resolves unimported names against the enclosing namespace (including files with multiple namespace blocks). An in-place version bump can therefore surface new violations on unchanged code, which means upgrades must be treated as ruleset changes, not routine dependency bumps.

Technical risk

  • Blast radius is low: dev-only dependency, no production runtime, reversible by removing one Composer entry and one XML file.
  • Auto-fix risk is now evidenced, not hypothetical. 0.6.9 fixes three phpcbf bugs that produced broken or wrong output: PreferCastOverFunction emitted a parse error on first-class callables (strval(...) → (string)(...)); DocBlockParamAllowDefaultValue appended a spurious |array to params already typed non-empty-array/non-empty-list/list; DocBlockThrows mis-resolved same-namespace exceptions as global (@throws \LocalException instead of @throws \App\LocalException). Two of the three were silent semantic corruption that would pass a "build is green" check and only surface in review or at runtime. This directly validates the earlier recommendation against unattended phpcbf in pre-commit hooks, and raises the bar: fixer output needs diff review, not just a passing exit code.
  • Maturity signal: pre-1.0, still settling. The 0.6.x line is being actively patched (0.6.8 → 0.6.9), which is good for abandonment risk but means fixer and sniff behavior is still moving. Patch releases here can change findings and fixer output; a ^0.6 constraint is not a safe build-stability posture.
  • Adoption evidence risk remains: still a single-maintainer/small-collective supply-chain dependency with essentially no external production evidence. 0.6.9's responsiveness to issue #84 is a positive governance datapoint — the maintainer is triaging correctness bugs and shipping fixes — but there is still no stated support policy or security process.
  • Convention churn: 251 sniffs is a large opinionated surface. The realistic near-term cost is not integration, it is the size of the first phpcbf diff and the review effort to accept or suppress rules the team disagrees with.
  • Upstream coupling: behavior is inherited from PHP_CodeSniffer and Slevomat; a PHPCS major upgrade can change rule behavior and break a previously green build independently of this package's release.
  • Governance: MIT license is fine; the absence of a stated support policy or security process is the gap a TPM should record in the risk register.

Key questions

  1. Do the three fixers corrected in 0.6.9 have regression tests, and is there a fixture-based test suite covering fixer output (not just sniff detection)? This is now the single highest-value question — silent autofix corruption is the only failure mode here with runtime consequences.
  2. What is the release cadence and is there a documented policy for behavior-changing patch releases (like the DocBlockThrows namespace-resolution change)? Release notes should flag "new findings on upgrade" explicitly if patch bumps can turn builds red.
  3. Is this a fork/continuation of cakephp/cakephp-codesniffer, and what is the divergence/commitment to track upstream?
  4. Which PHP_CodeSniffer and Slevomat versions are pinned, and what is the tested matrix across PHP 8.1–8.4 — specifically, is 0.6.9 validated against the PHPCS major we would pin?
  5. Does PhpCollectiveStrict gate on type hints in a way that conflicts with existing Larastan/PHPStan level-8 expectations?
  6. What is the intended relationship to Laravel Pint — replace, run alongside, or defer to Pint for formatting and use this only for semantic/docblock sniffs?
  7. Are there known false positives on Laravel idioms (facades, magic methods, blade/generated files, migration classes)?

Integration Approach

Stack fit

  • Laravel/PHP 8.1+ with Composer: native fit. It runs as a CI/lint step and an IDE action, with no service, queue, or deployment implications.
  • Overlap to resolve: Laravel ships Pint (PHP-CS-Fixer underneath). Running both against the same files invites conflicting auto-fixes. Recommended split — Pint owns formatting, this package owns semantic/docblock/test-convention sniffs — or pick one and document the choice. Running both without an ownership boundary is the most likely integration mistake.
  • Note that 0.6.9's fixes land squarely in the docblock/cast layer, i.e. exactly the territory you would assign to this package under the split above. That argues for giving it the semantic/docblock role and leaving whitespace and import ordering to Pint where they overlap.
  • Path hygiene: exclude vendor/, storage/, bootstrap/cache/, generated code, and migrations initially, or the first run will be dominated by noise.

Migration path

  1. Spike (1–2 days): install in a branch, pin to a specific 0.6.x patch, run phpcs read-only against app/ and tests/, capture violation counts by sniff and a sample of phpcbf diffs. This produces the real cost estimate.
  2. Validate the fixers before trusting them: run phpcbf over a representative sample (including first-class callables, generics-style array docblocks, and exceptions thrown across namespaces — the three areas 0.6.9 just repaired) and confirm the output parses and the semantics are unchanged. Cheap, and it is the only way to size the review burden of step 3.
  3. Baseline: adopt the non-strict PhpCollective ruleset, suppress sniffs the team rejects with explicit <exclude name="..."> entries and comments explaining why. Record decisions in the repo so they are reviewable.
  4. Fix forward, not backward: run phpcbf on one bounded module, review the diff, merge. Do not mass-fix the whole codebase in one commit.
  5. CI gate in warn mode: non-blocking job publishing violation counts for a sprint; use it to tune the ruleset before it can fail a build.
  6. CI gate in blocking mode on changed files first (phpcs against a diff), then repo-wide once the violation count is near zero.
  7. Escalation (optional): pilot PhpCollectiveStrict on new code only, via a separate ruleset scoped to a directory, before considering it for the whole repo.

Compatibility

  • Confirm no version conflict with directly required squizlabs/php_codesniffer, slevomat/coding-standard, or phpstan/phpstan before committing; if there is one, either drop the direct dev dependency and rely on the bundled version or pin both.
  • Pin an exact version ("php-collective/code-sniffer": "0.6.9") rather than a floating constraint. 0.6.9 demonstrates both halves of the risk: it fixes output corruption (a reason to take it) and it changes what gets reported (a reason not to take it implicitly on an unrelated PR).
  • Define an upgrade procedure, not just a pin. For each patch bump: read release notes for "new findings" and "behavior change" language, re-run against the current baseline in a throwaway branch, and diff the violation count. Treat any count change as a ruleset change that needs an owner's sign-off.
  • Verify against the oldest and newest PHP versions in the support matrix, including the CI image's PHP minor.

Sequencing

  • Week 1: spike + fixer validation + ruleset decision + Pint/PHPCS boundary documented.
  • Week 2: ruleset committed with the version pinned, warn-only CI job, IDE external tools published to the team.
  • Weeks 3–4: module-by-module phpcbf cleanup with reviewed diffs.
  • Week 5+: blocking gate on changed files; revisit repo-wide gate and strict standard quarterly.
  • Standing: a lightweight "dependency bump" checklist that includes baseline re-run, owned by the same person who owns the ruleset.

Operational Impact

Maintenance

  • Low steady-state effort: a pinned dev dependency plus one XML file. The recurring work is (a) periodic version bumps with a baseline re-run and diff review of rule changes, (b) curating the exclusion list as conventions evolve, and (c) re-checking the Pint/PHPCS boundary when either tool changes.
  • 0.6.9 raises the sophistication required for (a) slightly. A naive "bump the version, merge if CI is green" habit is now demonstrably unsafe: it would have shipped a parse error before this release, and it will occasionally surface new violations after it. The bump ritual needs to be explicit.
  • Assign a named owner (usually the platform/dev-experience engineer) for ruleset changes. Without ownership, the exclusion list accretes and the gate loses credibility.
  • Budget roughly 0.05–0.1 FTE ongoing, plus a one-off cleanup cost that is a direct function of existing violation count — measure it in the spike, don't guess.

Support

  • Community-only, no SLA, no vendor. External evidence remains thin: troubleshooting routes are the README, docs/sniffs.md, GitHub issues, and the upstream PHP_CodeSniffer wiki.
  • Positive datapoint from 0.6.9: correctness issues are being triaged and fixed, and the release notes are unusually good — they show before/after examples and explicitly flag the one behavior change. That materially improves the "can we operate this?" answer, and it is the kind of note a maintainer should be judged on.
  • Practical mitigation unchanged: keep the ruleset thin and documented so a future maintainer can reconstruct intent, and be prepared to fall back to cakephp/cakephp-codesniffer or a hand-rolled PHPCS + Slevomat ruleset if the package goes dormant. The exit cost is genuinely small, which is the main reason to accept the adoption risk.
  • Track upstream PHP_CodeSniffer and Slevomat releases independently, since most behavioral change arrives through them.

Scaling

  • Cost grows with lines of code and sniff count. Use PHPCS's parallel option, scope runs to changed files in PRs, run full-repo only on the default branch or nightly, and cache results where CI supports it.
  • The stricter standard roughly triples the semantic surface (type hints on parameters/properties/returns), so it should be scoped to new code or a single directory to avoid a repo-wide backlog.
  • Multi-repo organizations should ship the ruleset as a shared internal Composer package or a shared phpcs.xml template rather than asking each repo to copy XML — otherwise convention drift is guaranteed. If you do that, centralize the version pin and the bump checklist too, so one team owns fixer-correctness validation for everyone.

Failure modes

Failure Symptom Mitigation
Fixer emits invalid or wrong code Code parses in CI's lint but breaks at runtime; or a docblock/type annotation is silently wrong (cf. 0.6.9: strval(...), |array appended to non-empty-list, @throws \LocalException) Review phpcbf diffs; run php -l / test suite after bulk fixes; keep auto-fix off pre-commit hooks
Patch bump changes findings Green build turns red on an unrelated PR; new @throws findings on untouched files Pin exact version; re-run baseline on every bump; read release notes for behavior-change flags
Pint/PHPCS conflict Fixers overwrite each other; diffs oscillate Single owner per concern; disable overlapping sniffs
Unattended phpcbf Semantic changes in unrelated files, noisy PRs Fix only staged/changed files; review fixer diffs in CI
Rule overload Team adds blanket exclusions; gate becomes meaningless Start with non-strict standard; justify each exclusion
Upstream abandonment No releases; new PHP version unsupported Small exit cost; keep a fallback ruleset documented; reassess if cadence stalls
Performance CI lint step grows to minutes Parallel, diff-scoped, cached runs; exclude generated code

Ramp-up

  • Developer learning curve is low — phpcs/phpcbf are widely understood, and README provides Composer scripts and PhpStorm external-tool config, so a team can be productive in under a day.
  • The real ramp-up is convention alignment: developers must learn which PhpCollective rules are enforced and which are deliberately excluded, particularly around docblocks, type hints, and test conventions. A short internal README section plus IDE hotkeys covers most of it.
  • Add one specific piece of guidance: don't hand-edit to satisfy a fixer before confirming the fixer is right. The 0.6.9 bugs would have led developers to "fix" correct generics docblocks or first-class callables by hand in the wrong direction. Encourage reporting upstream and pinning forward instead.
  • Onboarding for maintainers is moderate: reading 251 sniff definitions is not realistic, so the internal documentation should enumerate only the ~20 sniffs that actually fire in this codebase, plus the bump checklist.

TPM recommendation

Treat as Trial, not Adopt, until the spike produces violation counts and a reviewed sample diff — the 0.6.9 release does not change that stance, it sharpens the conditions attached to it. On the positive side, the release is evidence of an actively maintained project that triages correctness bugs and writes genuinely useful release notes, which is better governance signal than the earlier snapshot showed. On the negative side, it confirms the assessment's central operational concern: phpcbf here can silently corrupt valid code, and the docblock/cast sniffs are exactly the layer this package would own under a Pint split. Two consequences: (1) pin the exact version and formalize a bump ritual that re-runs the baseline, because even a patch release can add findings; (2) never run phpcbf unattended — review the diff, and lint/test afterward. Take 0.6.9 over earlier 0.6.x for the three fixer corrections, keep it as the semantic-convention layer rather than a Pint replacement, gate it on changed files first, and revisit the Adopt decision once there is a full quarter of clean bump cycles and a measured violation baseline.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
htinlynn/genius-helper
maco-studios/hephaestus
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator