Docs/Guides/PHPStan Configuration Fixes

PHPStan Configuration Fixes

This document describes the PHPStan configuration issues that were resolved.

Issues Fixed

1. Missing Larastan Extension Include

Problem: The phpstan.neon configuration file was missing the Larastan extension include, which is required for PHPStan to properly analyze Laravel-specific code.

Solution: Added the following to the top of phpstan.neon:

includes:
    - vendor/larastan/larastan/extension.neon

This allows PHPStan to:

  • Understand Laravel facades and helpers
  • Recognize Illuminate framework classes and methods
  • Properly analyze Laravel-specific code patterns
  • Resolve Laravel service container bindings

2. Invalid excludePaths Syntax

Problem: The excludePaths section had invalid syntax: vendor (?)

Solution: Fixed to proper YAML syntax:

excludePaths:
    - vendor
    - tests/Pest.php
    - tests/Feature

Testing the Fix

To verify the fixes work correctly:

# Install dependencies
composer install


composer analyse

Expected Behavior

With these configuration fixes:

Before:

  • PHPStan reported 233 errors
  • Most errors were "unknown class" for Laravel framework classes
  • Unknown methods on Laravel components
  • Missing PSR interfaces

After:

  • Larastan extension loads Laravel-specific type information
  • Framework classes are properly recognized
  • Only actual code issues (if any) should be reported
  • Level 9 analysis runs successfully

Notes

  • The project uses PHP 8.3+ and Laravel Zero 12.x
  • PHPStan is configured at level 9 (maximum strictness)
  • Larastan 3.x is specified in composer.json as a dev dependency
  • All strict checking options are enabled in the configuration