phpstan/phpstan-shim
Deprecated shim for PHPStan. Since PHPStan 0.12, the main phpstan/phpstan package ships as a PHAR, making phpstan/phpstan-shim unnecessary. Upgrade by switching composer dependency to phpstan/phpstan ^0.12 and reinstalling.
## Getting Started
### Minimal Steps
1. **Migrate to Modern PHPStan**:
Since `phpstan/phpstan-shim` is **obsolete** (replaced by `phpstan/phpstan` PHAR), uninstall it and upgrade to the latest `phpstan/phpstan` (v0.12+):
```bash
composer remove phpstan/phpstan-shim
composer require --dev phpstan/phpstan:^0.12
phpstan.phar) is now the default—no shim required.First Use Case: Run static analysis directly via the PHAR:
vendor/bin/phpstan analyse app --level=5
app with your target directory (e.g., app/Http).--level=5 for production-grade checks (adjust as needed).Verify PHAR Execution: Ensure the PHAR runs without shim dependencies:
php vendor/bin/phpstan --version
phpstan-baseline.neon for suppressing known issues (e.g., Laravel’s dynamic properties).PHAR-Based CI/CD:
Update your composer.json scripts to leverage the PHAR:
"scripts": {
"test": [
"@phpstan"
],
"phpstan": "phpstan analyse app --level=5 --memory=1G"
}
composer test in CI (GitHub Actions, etc.).vendor/ dependencies.Incremental Analysis with PHAR: Generate a baseline to suppress false positives:
vendor/bin/phpstan analyse app --level=5 --generate-baseline
phpstan-baseline.neon in .gitignore if shared across devs.Laravel-Specific Rules:
Extend PHPStan’s config (phpstan.neon) with Laravel extensions:
includes:
- vendor/phpstan/phpstan-doctrine/extension.neon
- vendor/phpstan/phpstan-laravel/extension.neon
phpstan/phpstan-laravel).// .phpstorm.meta.php
<?php
namespace PHPSTORM_META {
override(type(phpstan\Phar\PhpStan::class), map([
'$cli' => type('string')
]));
}
--parallel for large codebases (PHPStan 0.12+):
vendor/bin/phpstan analyse app --level=5 --parallel --temp-dir=/tmp/phpstan
phpstan.neon:
services:
- MyApp\Rules\CustomRule
PHAR Dependency Removal:
vendor/phpstan or phpstan-shim remnants exist.vendor/phpstan, vendor/bin/phpstan, and composer.lock).composer why-not phpstan/phpstan to confirm no conflicts.Legacy Config Incompatibility:
phpstan.neon files may use deprecated syntax (e.g., parameters instead of services).# Old (deprecated)
parameters:
level: 5
# New (0.12+)
level: 5
PHAR Path Issues:
phpstan.phar not found or permission errors.vendor/bin/phpstan is executable:
chmod +x vendor/bin/phpstan
./vendor/bin/phpstan analyse app --level=5
False Positives in Laravel:
$request->input()).__call, __get).@var annotations or @phpstan-ignore-line./** @var \Illuminate\Http\Request $request */
$request->input('key'); // No error
vendor/bin/phpstan analyse --verbose
ParameterShouldBeType). Resolve them via:
grep "ParameterShouldBeType" vendor/phpstan/phpstan/src/Rules/
phpstan-baseline.neon causes analysis to fail.PHAR Customization:
#!/bin/bash
php vendor/bin/phpstan analyse "$@" --memory=2G
custom-phpstan and use it in CI.Template Rules for Blade: Extend PHPStan to support Blade templates by creating a custom rule:
class BladeDynamicPropertyRule extends Rule
{
public function getNodeType(): string { return BladeDynamicProperty::class; }
// Implement logic to ignore Laravel's dynamic properties
}
phpstan.neon:
services:
- MyApp\Rules\BladeDynamicPropertyRule
Performance Optimization:
excludeFiles:
- tests/**
- vendor/**
- storage/**
vendor/bin/phpstan analyse --memory=4G
--cache-results to speed up repeated runs:
vendor/bin/phpstan analyse --cache-results --cache-results-dir=/tmp/phpstan-cache
NO_UPDATE_NEEDED was **not** applicable—this assessment was fully updated to reflect the PHAR migration and PHPStan 0.12 changes.
How can I help you explore Laravel packages today?