phpstan/php-8-stubs
Stub files for PHP 8 built-in functions, classes, and extensions, maintained for PHPStan. Improves static analysis and type inference by providing accurate signatures and phpDoc where native reflection is incomplete or inconsistent.
stdClass, DateTime, Exception), which are heavily used in Laravel’s ecosystem (e.g., Eloquent models, request handling, and service containers). This enables Laravel’s strict_types=1 directive to work effectively with static analysis tools like PHPStan.nunomaduro/phpinsights or custom configurations) makes this package a natural fit. It bridges the gap between Laravel’s dynamic features (e.g., magic methods, dynamic properties) and stricter type checking.__get(), __call(), dynamic properties) may trigger false positives or negatives. For example:
phpstan/extension-installer to add Laravel-specific rules.--generate-baseline) and run analysis in parallel (--parallel). Exclude tests or third-party code from strict checks.composer.json.phpstan.neon rules, severity levels)?phpstan.neon configuration?Illuminate\Support\Collection, Illuminate\Http\Request, and Illuminate\Database\Eloquent\Model.spatie/laravel-permission, laravel/breeze).spatie/fork for PHP 7.x).phpstan.neon) for Laravel-specific rules or exclusions.Request, Collection).composer.json:
"require-dev": {
"phpstan/php-8-stubs": "^1.0",
"phpstan/extension-installer": "^1.0" // Optional: for Laravel-specific rules
}
Update phpstan.neon to include stubs:
includes:
- vendor/phpstan/php-8-stubs/stubs/
phpstan/extension-installer to add Laravel rules (e.g., for magic methods):
vendor/bin/phpstan-extensions install --symfony --laravel
Configure PHPStan to ignore dynamic properties or handle Laravel’s magic methods:
arguments:
dynamicPropertyAccess:
- allowMagicPropertyAccess: true
__get(), __call()), dynamic properties, or reflection-heavy code.laravel/ide-helper) may need updates.phpstan/laravel) are already in use.phpstan/laravel for Laravel-specific rules.phpstan/extension-installer for Symfony/Laravel compatibility.phpstan/auto-import).How can I help you explore Laravel packages today?