Skip to content
Esc
↑↓navigate↵open⌘Jpreview
On this page

Presets

Pick the rules each command runs with format presets, lint presets, Rector sets, and analyse presets.

Each command picks its rules with its own key: [format] preset, [lint] preset and sets, and [analyse] preset. A top-level preset sets all three at once. To see the full rule list of one choice, open its page under rule presets or Rector sets.

One preset for every command

preset = "recommended"

A top-level preset is essential, recommended, or strict. It becomes [lint] preset and [analyse] preset of the same name, and [format] preset = "laravel" when the Laravel extension is on, else psr12. A command’s own key wins over it.

preset = "strict"

[analyse]
preset = "recommended"

Format presets

Preset Rules
laravel Pint’s default rules. The default.
psr12 The PSR-12 rules
empty Only the rules you turn on

[format.rules] overrides the preset. Pint’s per is not a Pun preset: pun migrate expands it into rules over empty. Pun has no symfony preset, and pun migrate stops with an error on a pint.json that uses it.

Lint presets

Each preset includes the ones above it in this table.

Preset Turns on
essential Likely bugs and dead code, with safe fixes only
recommended Newer PHP syntax up to [php] version, the Laravel, Pest, and PHPUnit quality rules, and simpler equivalents. The default for pun init.
strict Added types, narrower visibility, early returns, coding style, and every rule whose fix is unsafe
[lint]
preset = "recommended"

Pun’s presets are its own picks, from Rector, PHP-CS-Fixer’s risky fixers, and Mago. Laravel, Pest, and PHPUnit rules also need their extension. To turn on a rule outside your preset, name the rule or its group. For precedence and path overrides, see [lint]. The lint preset pages list every rule.

Rector sets

To run exactly what a Rector set runs, name it in sets. Each is Rector’s own set, under its own name:

[lint]
sets = ["rector/dead-code", "rector/code-quality", "rector/php-sets"]
Sets From
rector/dead-code, rector/code-quality, rector/coding-style, rector/type-declaration, rector/privatization, rector/php84, … Rector
rector/php-sets Rector’s withPhpSets(): every PHP set up to [php] version
rector-laravel/laravel-code-quality, rector-laravel/laravel-130, … rector-laravel
rector-phpunit/phpunit-code-quality, … rector-phpunit
pest/coding-style Pest’s Rector plugin

Rector sets lists them all, with each one’s rules. pun migrate writes the sets your rector.php uses. A rule that Pun merged from several Rector rules runs only the rewrites of the set’s Rector rules. Rector rules that are format rules in Pun stay under [format]. A preset and sets work together: a rule runs when either turns it on.

Analyse presets

Each preset includes the ones above it in this table.

Preset PHPStan levels Adds
basic 0 and 1 Unknown classes, functions, and methods on $this, wrong argument counts, and undefined variables
essential 2 and 3 Unknown methods and properties on every expression, and PHPDoc, return, and property types
recommended 4 and 5 Dead code, constant conditions, and argument types. The default.
strict 6 to 8 Missing typehints, union types, and nullable values
max 9 and 10 Explicit and implicit mixed
[analyse]
preset = "strict"

Pun’s presets are its own picks. They also turn on a few checks that PHPStan leaves opt-in, such as uninitialized properties in basic and missing @throws in max.

PHPStan level presets

To run exactly what phpstan analyse --level N runs, use the level’s preset:

[analyse]
preset = "phpstan/level_5"
Preset Runs
phpstan/level_0 to phpstan/level_6 PHPStan’s rules of that level and every lower one
phpstan/level_7 Level 6, plus union-types
phpstan/level_8 Level 7, plus nullables
phpstan/level_9 Level 8, plus explicit-mixed
phpstan/level_10, phpstan/level_max Level 9, plus implicit-mixed

A level preset follows PHPStan’s defaults:

  • PHPStan’s opt-in checks stay off, such as checkUninitializedProperties and the missing @throws checks. Turn them on in [analyse.rules].
  • phpstan-strict-rules and phpstan-deprecation-rules are separate packages, not levels. Turn their rules on in [analyse.rules]. pun migrate does this for you.
  • Bleeding-edge checks run only with bleeding-edge = true, as with PHPStan’s bleedingEdge.neon.
  • With the laravel extension on, Larastan’s default rules run too.
  • Some PHPStan checks are lint rules in Pun, such as unreachable code at level 4. The preset turns them on in [lint] as well, so pun check reports what PHPStan reports. [lint.rules] can still turn them off.

PHPStan level presets lists what each level adds. Pun doesn’t match PHPStan on every case yet. See analysis limitations.

pun.toml doesn’t accept a numeric [analyse] level. pun migrate writes the PHPStan level preset of your level, plus the rules your phpstan.neon adds or removes.

Last updated on

Was this page helpful?