# PHPStan

> Static analysis setup and configuration

---

Required: [PHPstan](https://phpstan.org/)

Static analysis is configured via `phpstan.neon` (Level 6, baseline in `phpstan-baseline.neon`).

### Run

```bash
composer analyse
```

The analysis requires a webtrees installation (for `app/` classes + `vendor/autoload.php`). Run it from the bind-mounted path:

```bash
cd /path/to/webtrees/modules_v4/linkenhancer
composer analyse
```

### Configuration

- **Level**: 6
- **Baseline**: `phpstan-baseline.neon` (known issues)
- **Bootstrap**: <a href="https://codeberg.org/bschwede/linkenhancer/src/branch/main/phpstan-bootstrap.php" target="_blank" rel="noopener"><code>phpstan-bootstrap.php</code></a>
 registers PSR-4 namespaces directly (bypasses the version-gated autoloader in [`wt-shared-libs`](../../wt-shared-libs))
- **Scan directories**: `../../app/` (webtrees core classes)
- **Exclude paths**: <a href="https://codeberg.org/bschwede/linkenhancer/src/branch/main/src/LinkEnhancerModuleExt.php" target="_blank" rel="noopener"><code>LinkEnhancerModuleExt.php</code></a>
 (use in conjunction with [Vesta modules](https://github.com/vesta-webtrees-2-custom-modules))
- **Memory limit**: 1G
- **Parallel**: disabled (single process, more reliable in CI)

### Key settings

- `treatPhpDocTypesAsCertain: false` — prevents false positives from `@var` assertions
- `ignoreErrors` for:
  - `AccessLevel` Enum (WT 2.3-only class, not available in 2.2 runtime)
  - `DB::prefix('')` — intentional (getting prefix without identifier)

### Regenerating the baseline

After intentional changes that introduce new (acceptable) errors:

```bash
vendor/bin/phpstan analyse -c phpstan.neon --memory-limit=1G --generate-baseline=phpstan-baseline.neon
```

> **Note:** Run this via the direct `vendor/bin/phpstan` call — the `composer` script wrapper does not forward extra arguments.
