---
title: pun analyse
description: Report type errors without editing files.
---

`pun analyse` (alias `pun analyze`) reports type errors. It doesn't cover every PHPStan or Larastan check yet. The [rule reference](/docs/rules/analyse) lists the implemented ones.

```bash
pun analyse
pun analyse app tests
```

## Configuration

```toml pun.toml
[analyse]
preset = "strict"
paths = ["app", "tests"]

[analyse.rules]
"types/missing-return-type" = "off"
```

The five [analyse presets](/docs/configuration/presets#analyse-presets) group PHPStan levels. A rule takes `"on"` or `"off"`. Pun analyses at the highest PHPStan level among the enabled core rules and the preset's type switches.

`stubs`, `[[analyse.ignore]]`, and the rule options `pun migrate` writes work like PHPStan's `stubFiles`, `ignoreErrors`, and parameters. An ignore entry that matches nothing is an error, unless it sets `report-unmatched = false`. When you pass files on the command line, entries for other files and entries without a path aren't reported.

Larastan's rules are on when the `laravel` [extension](/docs/configuration/pun-toml#extensions) is on, unless the lock pins a Laravel that Larastan 3 doesn't support. Larastan 3 supports 11.44.2 and later 11.x, 12.4.1 and later 12.x, and 13.x.

Pun reads model properties from the migrations in `database/migrations` and the schema dumps in `database/schema`, as Larastan does. The `database-migrations-path`, `squashed-migrations-path`, `disable-migration-scan`, and `disable-schema-scan` options that `pun migrate` writes from Larastan's parameters change those directories. Pun doesn't support `enableMigrationCache`. Schema dumps are read with Larastan's MySQL-style parser.

Larastan boots your app to learn its macros. Pun doesn't run PHP, so it reads the `X::macro('name', ...)` and `X::mixin(new Mixin())` calls in your bootstrap files, in `app/Providers`, in the Laravel and package service providers, and in every analysed file. For `mixin()`, every public and protected method of the mixin class becomes a macro, typed by the native return type of the closure the method returns. Pun looks for the mixin class in the files it has already read, then in the analysed or scanned file named after the class. A macro registered in a `foreach` over a literal array, or over a class constant that holds one, gets one macro per string in the array: per value for the loop's value variable, per key for its key variable.

Pun misses these macros:

- A macro whose name is computed in any other way, such as a variable from a function call or a concatenation.
- A `mixin()` whose argument isn't `new` with a class name (such as `new self()` or a variable), and a mixin class Pun can't find.
- A macro that a vendor file outside those providers registers.

A closure macro's type is its native return type, so a closure without one gives `mixed`, as it does in Larastan.

`pun.toml` can't override `checkFunctionArgumentTypes`, `checkArgumentsPassedByReference`, or `checkThisOnly` on their own. `pun migrate` reports them as unsupported and keeps the level.

With every analyse rule off, `pun analyse` prints "No rules detected" and exits 2.

## Rule names

Human output uses Pun IDs such as `analyse/undefined/function`. Machine reports use PHPStan identifiers such as `function.notFound`. An [ignore comment](/docs/configuration/ignore-comments) suppresses an ignorable finding:

```php
legacy_hook(); // @pun-ignore analyse/undefined/function -- provided at runtime
```

## Syntax errors

If PHP can't parse a file, the run fails with a `parser-error` problem and reports only syntax errors. Fix them and run again to see the rest.

## Files

Path arguments replace `[analyse] paths`, which defaults to `[files] paths`, then the project root. Analysis skips Blade templates, `vendor/`, `bootstrap/cache`, `build`, `node_modules`, and `storage`. [`pun list-files --command analyse`](/docs/commands/list-files) shows the selection.

`[analyse] exclude` removes files from analysis and from the symbol scan. Pun still reads Composer dependencies for symbols.

Include checks resolve local files, `file://` URLs, and local `phar://` members of PHAR, ZIP, TAR, and gzip archives. They don't support bzip2, OpenSSL signatures, PHAR aliases and mounts, or runtime-registered wrappers. A `zip://` include is always reported missing.

## Baseline

```bash
pun analyse --generate-baseline
pun analyse --generate-baseline old.toml
```

The baseline goes to `[analyse] baseline`, or `pun-baseline.toml` when unset, and the run exits 0. Set `[analyse] baseline` to suppress its findings on later runs:

```toml
[analyse]
baseline = "pun-baseline.toml"
```

Entries match by file, rule, message, and count, not line number. Pun notes entries that no longer match. Pun doesn't read PHPStan baselines.

Non-ignorable errors, such as a duplicate parameter, stay visible even when an ignore comment or baseline entry matches. Generated baselines leave them out, and JSON reports mark them `"ignorable": false`.

## Options

| Flag | What it does |
| --- | --- |
| `--config <path>` | Read another `pun.toml`. |
| `--format`, `--error-format` | `table`, `raw`, `json`, `prettyJson`, `checkstyle`, `junit`, `gitlab`, `github`, or `teamcity`. |
| `--generate-baseline [<file>]` | Write every error to the baseline and exit 0. |
| `--concise` | One line per finding. |
| `-v` | Add identifiers to `raw` output. |
| `-q`, `--quiet` | Print nothing, also with `--format` or under a coding agent. The exit code still reports the result, as PHPStan does. |
| `--color=auto\|always\|never` | Color mode. |
| `--max-processes=N` | Cap worker threads. |
| `--memory-limit=<limit>` | Accepted and ignored, so `phpstan analyse --memory-limit=2G` scripts keep working. Pun has no PHP memory limit. |

`json` and `prettyJson` add `"fixable": true` to errors that PHPStan's `--fix` can fix. `table` marks them with 🔧 and counts them, plus ignored errors that `--fix-ignored` can fix. Pun doesn't fix them.

## Exit codes

| Code | Meaning |
| --- | --- |
| 0 | No errors |
| 1 | Errors |
| 2 | Pun could not run |
