Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Phpstan Beberlei Assert

Phpstan Beberlei Assert Laravel Package

phpstan/phpstan-beberlei-assert

PHPStan extension for beberlei/assert. Adds improved static analysis and type inference for Assert::that and related assertions, helping PHPStan understand refined types after checks and reducing false positives in codebases using beberlei/assert.

View on GitHub
Deep Wiki
Context7

PHPStan beberlei/assert extension

Frequently asked questions about Phpstan Beberlei Assert
How do I install phpstan/phpstan-beberlei-assert for Laravel projects?
Run `composer require --dev phpstan/phpstan-beberlei-assert` in your project directory. Then, add `extensions: - phpstan/phpstan-beberlei-assert` to your `phpstan.neon` configuration file under the `[phpstan]` section. No additional setup is required.
Which Laravel versions does this PHPStan extension support?
This extension works with any Laravel version that supports PHPStan (typically PHP 7.4+). It focuses on static analysis, so Laravel-specific features don’t affect compatibility. Ensure your project’s PHPStan version is up-to-date for best results.
Will this extension break existing PHPStan rules or extensions?
No, it integrates seamlessly with existing PHPStan rules and other extensions. The extension only enhances type inference for `beberlei/assert` calls, so your current static analysis setup remains unchanged.
How does type narrowing work with Assert::nonEmpty() or Assert::numeric()?
After calling `Assert::nonEmpty($var)`, PHPStan will recognize `$var` as non-empty and adjust its type accordingly. For `Assert::numeric()`, it narrows the type to `int|float`. This reduces false positives by aligning analysis with the actual behavior of `beberlei/assert`.
Can I use this extension in production? Does it affect runtime performance?
This is a static analysis tool—it only runs during development (via PHPStan) and has zero runtime impact. Install it in `dev` dependencies only, as it’s purely for improving code quality and catching issues early.
What if beberlei/assert updates its API? Will this extension break?
The extension targets well-defined patterns in `beberlei/assert` (e.g., `Assert::*()` methods). While major API changes could require updates, the extension’s focus on common use cases minimizes risk. Monitor the package for updates if you rely on cutting-edge features.
Does this work with Laravel’s built-in validation or only beberlei/assert?
This extension is specifically for `beberlei/assert`. Laravel’s validation (e.g., `Validator` facade) uses a different pattern and isn’t supported. If you need static analysis for Laravel validation, consider other tools like `phpstan/phpstan-doctrine` or custom rules.
How do I test if the extension is working correctly?
Run `phpstan analyse` and check for reduced false positives in code using `beberlei/assert`. For example, after `Assert::nonEmpty($string)`, PHPStan should no longer flag `$string` as potentially null. Compare results before/after installation.
Are there alternatives to this extension for type-safe assertions?
For Laravel, alternatives include custom PHPStan rules or libraries like `spatie/laravel-assert`. However, this extension is the most direct solution for `beberlei/assert`, offering built-in support without extra configuration.
Can I use this with PHPStan’s level 5 (most strict) without issues?
Yes, this extension is designed to work with strict PHPStan levels. It reduces false positives by teaching PHPStan about `beberlei/assert`’s guarantees, making level 5 analysis more practical for projects using runtime assertions.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope