- How do I install phpstan/phpstan-beberlei-assert for Laravel projects?
- Run `composer require --dev phpstan/phpstan-beberlei-assert` in your Laravel project’s root directory. The package is designed as a PHPStan extension, so no additional Laravel-specific setup is needed beyond configuring PHPStan itself.
- Does this extension work with Laravel’s built-in validation or only beberlei/assert?
- This extension specifically enhances PHPStan’s understanding of **beberlei/assert** (e.g., `Assert::that()` or `Assert::*()` methods). Laravel’s native validation (e.g., `Validator` facade) is unaffected and requires separate static analysis tools like PHPStan’s built-in Laravel extensions.
- Will this reduce false positives in my Laravel app’s strict type checks?
- Yes. The extension improves type inference for `beberlei/assert` validations, helping PHPStan recognize validated values as their correct types (e.g., `string`, `array`, or custom objects) instead of treating them as `mixed`, which reduces false positives in strict mode.
- What Laravel versions are compatible with this PHPStan extension?
- This extension works with any Laravel version that supports PHPStan (typically Laravel 8+). Compatibility depends on PHPStan’s version requirements, not Laravel itself, as the extension operates at the PHPStan level rather than the framework level.
- Do I need to modify my existing PHPStan configuration (phpstan.neon) to use this?
- Yes. Add the extension to your `phpstan.neon` under the `[phpstan]` section: `extensions = phpstan/phpstan-beberlei-assert`. No other changes are required unless you’re using custom PHPStan rules or levels.
- Can I use this extension in CI/CD pipelines for Laravel projects?
- Absolutely. Install it as a dev dependency (`--dev` flag) and run PHPStan in your CI pipeline. The extension adds minimal overhead and is safe for production-like static analysis, though it won’t affect runtime behavior.
- What happens if beberlei/assert updates its API in a future version?
- The extension aims to support stable `beberlei/assert` patterns, but breaking changes (e.g., renamed methods or signatures) could require updates. Monitor the package’s GitHub issues or check for new releases to ensure compatibility.
- Are there alternatives to this extension for stricter Laravel validation analysis?
- For Laravel-specific validation, consider PHPStan’s built-in Laravel extension (`phpstan/extension-installer`) or custom rules. However, this extension is the **only** dedicated tool for `beberlei/assert` type inference in PHPStan.
- Does this extension support custom Assert classes or only the core beberlei/assert methods?
- The extension primarily targets core `beberlei/assert` methods like `Assert::that()` and `Assert::*()`. Custom Assert classes may require additional configuration or manual type hints unless they follow the same patterns.
- How do I test if the extension is working correctly in my Laravel project?
- Run PHPStan with `--level=strict` and check for reduced false positives in validation-heavy files. For example, `Assert::that($userInput, StringType::class)` should no longer trigger `mixed` type warnings if the extension is active.