Repository navigation
Replace PHPStan and PHP CS Fixer with Mago - #15
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
carthage-software/mago, addsmago.toml, and updates CI and the Lefthook pre-commit hooks to runmago format,mago lintandmago analyze. The lock file diff only contains this swap; no other packages were updated.mago formatoutput plus the README example sync. No behavioral changes.Things to look at
function foo() : voidstyle used before, so the code now follows Mago's PER-like default (): void,!$x,A|B|null).resolveIterablenow only invokes closures (instanceof Closureinstead ofis_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.maybeIndentclamps the indentation level withmax(0, $level), so a negative level no longer throws aValueErrorfromstr_repeat.joinFirstPairandsuffixLastwere simplified so their types are clear to the analyzer; output is unchanged.Lint configuration
mago.tomldisables a few rules, each with a reason:too-many-methods,cyclomatic-complexity,halstead,kan-defect):CodeGeneratoris 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-styleis set toselfto match the existing tests, andissetis allowed for array checks.Verification
mago format --check,mago lint,mago analyze,composer validate --strict,composer normalize --dry-run,composer-dependency-analyserand the full PHPUnit suite (168 tests) all pass locally.