marick / laravel-strict
Fund package maintenance!
marickvantuil
Requires
- php: ^8.0|^8.1
Requires (Dev)
- orchestra/testbench: ^7.3
- pestphp/pest: ^1.21
This package is auto-updated.
Last update: 2024-10-23 15:37:35 UTC
README
Laravel offers some handy helpers out-of-the-box. But their return types can make it difficult to combine it with static code analysis like PHPStan:
echo strlen(config('app.name'));
Parameter #1 $string of function strlen expects string, mixed given
This happens because the helper can theoretically return any type:
/** * Get / set the specified configuration value. * * If an array is passed as the key, we will assume you want to set an array of values. * * @param array|string|null $key * @param mixed $default * @return mixed|\Illuminate\Config\Repository */ function config($key = null, $default = null)
This package wraps Laravel's helpers and adds nice methods that always expect a clear return type. If the method has a different return type, an exception will automatically be thrown, making it strict.
use function Marick\LaravelStrict\config; echo strlen(config('app.name')->string());
Or use the global helper:
echo strlen(strictConfig('app.name')); # Or in class form... Helper::config('app.name')->string();