Skip to content

Replace PHPStan and PHP CS Fixer with Mago - #15

Merged
ruudk merged 3 commits into
mainfrom
ruudk/replace-phpstan-cs-fixer-mago-6c96e5
Nov 26, 2026
Merged

ruudk merged 3 commits into
mainfrom
ruudk/replace-phpstan-cs-fixer-mago-6c96e5

Conversation

@ruudk

@ruudk ruudk commented Nov 26, 2026

Copy link
Copy Markdown
Owner

What

Replaces PHPStan and PHP CS Fixer with Mago, which provides a formatter, linter and static analyzer in a single binary.

Three commits, best reviewed one by one:

  1. Replace PHPStan and PHP CS Fixer with Mago: swaps the six PHPStan/CS Fixer packages (including the TicketSwap configs) for carthage-software/mago, adds mago.toml, and updates CI and the Lefthook pre-commit hooks to run mago format, mago lint and mago analyze. The lock file diff only contains this swap; no other packages were updated.
  2. Format code with Mago: pure mago format output plus the README example sync. No behavioral changes.
  3. Fix Mago lint and analyzer issues: the fixes needed to get lint and analysis clean.

Things to look at

  • Code style changes: Mago has no option for the function foo() : void style used before, so the code now follows Mago's PER-like default (): void, !$x, A|B|null).
  • resolveIterable now only invokes closures (instanceof Closure instead of is_callable). An array of code lines that happens to look like a callable (e.g. ['Foo', 'bar']) is no longer called by accident. This is a small behavioral change, but I consider it a bug fix.
  • maybeIndent clamps the indentation level with max(0, $level), so a negative level no longer throws a ValueError from str_repeat.
  • joinFirstPair and suffixLast were simplified so their types are clear to the analyzer; output is unchanged.

Lint configuration

mago.toml disables a few rules, each with a reason:

  • Complexity metrics (too-many-methods, cyclomatic-complexity, halstead, kan-defect): CodeGenerator is a single entry point with many small helpers by design.
  • no-boolean-flag-parameter: the public API takes boolean flags; changing that would be a BC break.
  • no-else-clause: style preference, not worth the churn.

assertion-style is set to self to match the existing tests, and isset is allowed for array checks.

Verification

mago format --check, mago lint, mago analyze, composer validate --strict, composer normalize --dry-run, composer-dependency-analyser and the full PHPUnit suite (168 tests) all pass locally.

Mago bundles a formatter, linter and static analyzer in a single binary,
so it replaces both PHP CS Fixer and PHPStan (plus their TicketSwap
config packages). CI and the Lefthook pre-commit hooks now run
`mago format`, `mago lint` and `mago analyze`.
Pure formatter output of `mago format`; no behavioral changes.
- Resolve only closures in resolveIterable instead of any callable, so an
  array of code lines is never invoked as a callable
- Simplify joinFirstPair and suffixLast so their types are clear
- Make string casts explicit, drop redundant ones
- Use named arguments for literal arguments and static closures
- Guard str_repeat against a negative indentation level
@ruudk
ruudk merged commit bff6dd4 into main Nov 26, 2026
2 checks passed
@ruudk
ruudk deleted the ruudk/replace-phpstan-cs-fixer-mago-6c96e5 branch November 26, 2026 09:27
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