phpstan/phpstan-beberlei-assert
Composer 安装命令:
composer require --dev phpstan/phpstan-beberlei-assert
包简介
PHPStan beberlei/assert extension
README 文档
README
Description
The main scope of this extension is to help PHPStan to detect the type of object after the Assert\Assertion validation.
<?php declare(strict_types = 1); use Assert\Assertion; function demo(?int $a) { // ... Assertion::integer($a); // PHPStan is now aware that $a can no longer be `null` at this point return ($a === 10); }
Supported Assertions
This extension understands the following Assertion static methods and narrows types accordingly:
integer, string, float, numeric, boolean, scalar, objectOrClass, isResource, isCallable, isArray, isInstanceOf, notIsInstanceOf, true, false, null, notNull, same, notSame, subclassOf, integerish, keyExists, keyNotExists, propertyExists, methodExists, classExists, interfaceExists, notBlank, isJsonString
nullOr* Prefix
Every supported assertion can be prefixed with nullOr to accept null in addition to the asserted type:
Assertion::nullOrString($value); // $value is string|null
all* Prefix
Every supported assertion can be prefixed with all to narrow the item type of arrays and iterables:
/** @var mixed[] $values */ Assertion::allInteger($values); // $values is array<int>
The allNot* prefix is also supported for allNotNull, allNotIsInstanceOf, allNotSame, and allNotBlank.
Fluent Chain API
The extension supports Assert::that() chains including ->nullOr() and ->all() modifiers:
Assert::that($value)->string(); Assert::that($value)->nullOr()->string(); // string|null Assert::thatNullOr($value)->string(); // string|null Assert::that($values)->all()->string(); // array<string> Assert::thatAll($values)->string(); // array<string>
The function-style API (Assert\that(), Assert\thatNullOr(), Assert\thatAll()) is also supported.
Installation
To use this extension, require it in Composer:
composer require --dev phpstan/phpstan-beberlei-assert
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/phpstan/phpstan-beberlei-assert/extension.neon
phpstan/phpstan-beberlei-assert 适用场景与选型建议
phpstan/phpstan-beberlei-assert 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.66M 次下载、GitHub Stars 达 43, 最近一次更新时间为 2018 年 04 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 phpstan/phpstan-beberlei-assert 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 phpstan/phpstan-beberlei-assert 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 6.66M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 44
- 点击次数: 22
- 依赖项目数: 121
- 推荐数: 2
其他信息
- 授权协议: MIT
- 更新时间: 2018-04-18