- How does this plugin improve Laravel validation beyond built-in Validator?
- This plugin enhances Psalm’s static analysis for PSL shapes, catching type mismatches at development time (e.g., incorrect array structures) before they reach Laravel’s runtime Validator. For example, it converts vague `array` types into precise shapes like `array{name: string, age: int}`, reducing redundant runtime checks and improving performance.
- Can I use this with Laravel 9/10 and Psalm 5?
- Yes, the plugin supports Psalm 5 and is compatible with Laravel 9/10. For PSL 2.x, use version `^2.1` of the plugin. Check the [compatibility table](https://github.com/php-standard-library/psalm-plugin#compatibility) for exact version mappings. Ensure your `composer.json` requires `psalm/psalm:^5.0` and `php-standard-library/psl:^2.0`.
- Will this break existing Laravel code or require refactoring?
- No breaking changes are introduced. The plugin operates as a static analysis layer—it won’t alter runtime behavior. However, it may expose type inconsistencies in your code (e.g., mismatched PSL shapes). Start with a pilot module (e.g., API contracts) to assess impact before full adoption.
- How do I configure it for CI/CD in Laravel?
- Add the plugin to your `composer.json` under `require-dev`, then enable it via `php vendor/bin/psalm-plugin enable php-standard-library/psalm-plugin`. In CI (e.g., GitHub Actions), run `./vendor/bin/psalm --init` to cache results and reduce runtime. Fail builds on critical errors by default, but suppress non-blocking issues with `@psalm-suppress` annotations.
- Does this work with PHPStorm or VSCode for autocompletion?
- Yes, the plugin integrates with Psalm’s IDE plugins (PHPStorm, VSCode) to provide autocompletion and error highlighting for PSL types. Ensure your IDE is configured to use the local Psalm installation (`./vendor/bin/psalm`). For PHPStorm, enable the Psalm plugin and point it to your project’s Psalm config file.
- What if Psalm flags false positives for PSL shapes?
- False positives are common when static analysis meets dynamic PSL types. Use `@psalm-suppress` annotations for known edge cases (e.g., `@psalm-suppress MixedAssignment`). Configure `psalm.ini` to adjust strictness (e.g., `suppress_errors=SomeLevel`) or suppress specific rules like `MixedAssignment`. Document suppressed issues in your codebase.
- How does this compare to `vimeo/psalm` for Laravel?
- While `vimeo/psalm` focuses on general PHP static analysis, this plugin specializes in PSL types, offering finer-grained array shape inference (e.g., `array{name: string}` vs. `array`). Use both: `vimeo/psalm` for broad type safety and this plugin for PSL-specific precision. They’re complementary, not alternatives.
- Can I enable this plugin incrementally in a large Laravel codebase?
- Absolutely. Start with high-impact modules (e.g., API request/response handlers or payment processing) where PSL shapes are critical. Use `psalm --init` to cache results and avoid slowing down CI. Gradually expand coverage while monitoring false positives. The plugin supports per-module configuration via Psalm’s project-level settings.
- What’s the performance impact of running this in CI?
- Static analysis adds CPU/memory overhead, but the impact is manageable. Run Psalm in parallel with other tests (e.g., using `php-parallel-lint`) and cache results with `psalm --init`. For Laravel, prioritize analyzing API contracts or data layers first, where PSL types are most valuable. Benchmark your CI pipeline to optimize.
- Who maintains this plugin, and how often are updates released?
- The plugin is maintained by the PHP Standard Library team, with updates aligned to PSL and Psalm version releases. Check the [GitHub repo](https://github.com/php-standard-library/psalm-plugin) for changelogs. For critical issues, open a GitHub issue or contribute via PRs. Monitor the [PSL roadmap](https://github.com/php-standard-library/psl) for future compatibility changes.