pun analyse
Find bugs. Never edits files.
Find bugs with types, like PHPStan. It never edits files. Also runs as pun analyze.
Usage
pun analyse [paths] [options]
pun analyse # whole project
pun analyse app tests # some folders
pun analyse --generate-baseline # accept current errors
Options
| Option | Description |
|---|---|
--generate-baseline [<file>] |
Save every current error to a baseline and exit 0. |
--config <path> |
Use this pun.toml. |
--format=<fmt> |
Report as raw, json, checkstyle, junit, gitlab, github or teamcity. Alias: --error-format. |
--concise |
One line per error. |
--max-processes=<n> |
Limit threads. Default: one per core. |
--color=<when> |
auto, always or never. |
-v |
Add identifiers to raw output. |
-q |
Print nothing. The exit code gives the result. |
What happens
- Reads the
[analyse]preset and rules frompun.toml. - Checks the files in
[analyse] paths, or[files] paths, or the whole project. - Reads
vendor/for classes and functions, but never reports on it. - Hides errors listed in the baseline (
[analyse] baseline). - With the
laravelextension on, also runs Larastan’s checks. - If a file has a syntax error, reports only syntax errors.
[analyse]
preset = "strict"
paths = ["app", "tests"]
baseline = "pun-baseline.toml"
[analyse.rules]
"types/missing-return-type" = "off"
To ignore one line, add // @pun-ignore <rule> -- <reason>. See ignore comments. The rule reference lists every check.
Limitations
Pun doesn’t run every PHPStan or Larastan check yet. The rule reference marks the missing ones as Planned.
Config
pun.tomltakes a preset, not a numeric PHPStan level. Usepreset = "phpstan/level_<n>"for PHPStan’s exact rule set. Pun still differs from PHPStan on some cases at each level, and six rules aren’t ported yet.checkFunctionArgumentTypes,checkArgumentsPassedByReferenceandcheckThisOnlycan’t be set on their own.pun migratereports them as unsupported.- PHPStan baselines are not read. Make a new one with
--generate-baseline. - No
tableorprettyJsonoutput formats. jsonmarks errors as"fixable", but Pun doesn’t fix them.
Laravel
- Larastan rules are off when the lock pins a Laravel version that Larastan 3 doesn’t support. Larastan 3 supports 11.44.2+, 12.4.1+ and 13.x.
enableMigrationCacheis not supported. Schema dumps are read with Larastan’s MySQL-style parser.- Pun doesn’t run PHP, so it finds macros by reading
X::macro()andX::mixin()calls in your bootstrap files,app/Providers, Laravel and package service providers, and analysed files. - It misses macros with computed names, mixins that aren’t
new ClassName(), mixin classes it can’t find, and macros registered by other vendor files. - A closure macro without a native return type is
mixed. - Class aliases from service providers, dynamic config,
AliasLoadercalls, custom bootstrap, config, cache or vendor paths, and real-timeFacades\...classes are not supported. - Method forwarding to container services through an alias is not supported.
Includes
- Include checks don’t support bzip2, OpenSSL signatures, PHAR aliases and mounts, or runtime stream wrappers.
- A
zip://include is always reported as missing.
Exit codes
| Code | Meaning |
|---|---|
| 0 | No errors. |
| 1 | Errors. |
| 2 | Pun could not run, or every rule is off. |