---
title: "Static analysis (PHPStan) — Package Toolkit for Laravel | Roundly"
description: "A bundled PHPStan extension declares the schema and query macros, so Larastan never reports them as undefined methods."
url: https://roundly-consulting.com/open-source/docs/package-toolkit-for-laravel/static-analysis
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Package Toolkit for Laravel](https://roundly-consulting.com/open-source/docs/package-toolkit-for-laravel.md)

# Static analysis (PHPStan)

A macro only exists once a service provider has booted — which PHPStan never does — so $table->morphKey(...) would otherwise be an “undefined method” error under Larastan. The toolkit ships a PHPStan extension that declares the macros statically:

- stubs/BlueprintMacros.stub — the four Blueprint macros.
- RoundlyConsulting\\PackageToolkit\\PHPStan\\QueryMacrosExtension — the whereLikeEscaped() macro on the query and Eloquent builders. Both builder classes are already described by Larastan’s own stub files, and only one stub per class is used, so these are contributed by reflection instead.

Both are registered in extension.neon, which phpstan/extension-installer picks up automatically — nothing to configure. Without the installer, include it by hand:

```yaml
includes:
    - vendor/roundly-consulting/package-toolkit-for-laravel/extension.neon
```

For reference, this is what extension.neon registers:

```yaml
parameters:
    stubFiles:
        - stubs/BlueprintMacros.stub

services:
    -
        class: RoundlyConsulting\PackageToolkit\PHPStan\QueryMacrosExtension
        tags:
            - phpstan.broker.methodsClassReflectionExtension
```

## Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

[More ways to support, including crypto](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/package-toolkit-for-laravel.md)
