jbboehr/phpstan-laravel-validation
Composer 安装命令:
composer require --dev jbboehr/phpstan-laravel-validation
包简介
Laravel Validation extension for PHPStan
关键字:
README 文档
README
Explanation
If the rules given to a laravel validator are a constant expression, then the shape of the array returned by \Illuminate\Validation\Validator::validated() is known at compile-time, and can be statically analyzed.
$request = new \Illuminate\Http\Request(); $data = \Illuminate\Support\Facades\Validator::make($request->all(), [ 'person.*.email' => 'required|email|unique:users', 'person.*.first_name' => 'required|string', 'person.*.age' => 'required|integer|string', ])->validated(); \PHPStan\dumpType($data); // array{person: array<int|string, array{email: non-empty-string, first_name: string, age: numeric-string}>} $data = $request->validate([ 'person.*.email' => 'required|email|unique:users', 'person.*.first_name' => 'required|string', 'person.*.age' => 'required|integer|string', ]); \PHPStan\dumpType($data); // array{person: array<int|string, array{email: non-empty-string, first_name: string, age: numeric-string}>}
If the input data does not match the rules array, an \Illuminate\Validation\ValidationException is thrown, thus preserving type safety.
Installation
To use this extension, require it in Composer:
composer require --dev jbboehr/phpstan-laravel-validation
If you also install phpstan/extension-installer then you're all set!
Manual installation
If you don't want to use phpstan/extension-installer, include extension.neon in your project's PHPStan config:
includes: - vendor/jbboehr/phpstan-laravel-validation/extension.neon
Caveats
- Laravel's validation does not cast anything, so, for example,
numericproduces the type unionint|float|numeric-string. If you know it will always be a string, you can refine the type by usingnumeric|stringand get a plainnumeric-string. - Wildcards must be indexed by integer and can't be mixed with non-wildcard rules.
- Custom validation rules, implicit rules, and enums are not currently supported.
License
This project is licensed under the AGPL v3+ License - see the LICENSE.md file for details.
统计信息
- 总下载量: 9.57k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: AGPL-3.0-or-later
- 更新时间: 2022-12-29