php-standard-library/psalm-plugin
Psalm plugin for PHP Standard Library (PSL) that improves type inference for PSL Type specifications (e.g., shape/optional), producing more precise array shapes and safer analysis. Install via Composer and enable with psalm-plugin.
Validator) can be replaced or augmented with static type checking.composer require php-standard-library/psalm-plugin --dev) aligns with Laravel’s dependency management.psalm-plugin enable is straightforward.psalm.xml to include PSL types (e.g., psalm.parse_ini_files=false for Laravel’s .env files).psalm --init to auto-generate configs.| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| Psalm version conflicts | Medium | Pin Psalm version in composer.json (e.g., ^5.0) and test against Laravel’s Psalm setup. |
| Performance overhead | Low | Psalm runs in CI/dev; runtime impact is negligible. Benchmark with psalm --stats. |
| PSL learning curve | Medium | Provide internal docs/workshops on PSL shapes and Psalm integration. |
| Laravel-specific edge cases | Medium | Test with Laravel’s dynamic features (e.g., collect(), Str::of()) to identify gaps. |
| Plugin maintenance | Low | MIT-licensed; community-backed (25 stars, active releases). Monitor for breaking changes. |
phpunit.xml to include Psalm checks?Validator) for certain use cases?php artisan psalm:init command to auto-configure Psalm for Laravel.AppServiceProvider if not using global Composer autoloading.@psalm annotations to correlate test expectations with static types.| Phase | Actions | Dependencies | Outcome |
|---|---|---|---|
| Assessment | Audit codebase for PSL usage and Psalm compatibility. | Psalm installed (composer require vimeo/psalm). |
Inventory of PSL-heavy modules. |
| Pilot | Enable plugin in a single module (e.g., API contracts). | psalm-plugin enable php-standard-library/psalm-plugin. |
Validate type improvements and false positives. |
| CI Integration | Add Psalm to CI (e.g., GitHub Actions) with --strict flag. |
CI setup, Psalm config. | Block PRs with type errors. |
| IDE Setup | Configure PhpStorm/VSCode for Psalm type hints. | IDE plugins. | Developer productivity gains. |
| Gradual Rollout | Expand to additional modules (e.g., Eloquent models, services). | Module-specific Psalm configs. | Reduced runtime validation overhead. |
| Optimization | Tune Psalm config (e.g., suppress false positives for Laravel magic). | Community feedback, Psalm docs. | Minimal noise in static analysis. |
collect(), Str::of()) as "undefined." Mitigation:
@psalm-suppress annotations for known edge cases..env files (psalm.parse_ini_files=false).psalm-plugin enable php-standard-library/psalm-plugin.psalm.xml to include PSL types and suppress Laravel-specific noise.--strict flag.psalm.xml to suppress false positives (e.g., Laravel’s magic methods).composer.json to avoid unexpected updates.composer why-not to audit dependency conflicts.How can I help you explore Laravel packages today?