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 that adds type inference for beberlei/assert, helping static analysis understand assertion-based checks. Improves accuracy of reported types after Assert::that(), Assert::string(), Assert::notNull(), and similar calls in your code.

Deep Wiki
Context7

phpstan/phpstan-beberlei-assert is a PHPStan extension that teaches the analyzer how to interpret beberlei/assert runtime assertions. It maps common Assert::* calls to smarter type information, so PHPStan can refine variables after assertions and surface fewer false positives.

Use it to improve static analysis in codebases that rely on Assert for input validation and invariants, while keeping checks at runtime.

  • Adds type refinement based on Assert method calls
  • Improves detection of impossible code paths after failed assertions
  • Reduces false positives when narrowing scalars, arrays, and objects
  • Seamless drop-in: install and enable in phpstan.neon
  • Works alongside existing PHPStan rules and extensions
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 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.
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport