nepada / phpstan-nette-tester
PHPStan nette/tester 扩展
v1.2.0
2024-04-06 07:09 UTC
Requires
- php: >=7.4 <8.4
- nikic/php-parser: ^4.13.2 || ^v5.0.2
- phpstan/phpstan: ^1.8.11
Requires (Dev)
- nepada/coding-standard: 7.14.0
- nette/tester: ^2.4
- php-parallel-lint/php-parallel-lint: 1.4.0
- phpstan/phpstan-phpunit: 1.3.16
- phpstan/phpstan-strict-rules: 1.5.2
- phpunit/phpunit: ^9.6.19
- shipmonk/phpstan-rules: 2.11.3
- spaze/phpstan-disallowed-calls: 3.1.2
README
此扩展深受 phpstan/phpstan/phpstan-webmozart-assert 启发,由 Ondřej Mirtes 开发。
最初由 damejidlo 组织 开发和发布。
描述
此扩展的主要范围是帮助 phpstan 在 Tester\Assert
验证后检测对象的类型。
<?php declare(strict_types = 1); use Tester\Assert; function runTest(?int $a) { // ... Assert::notNull($a); // phpstan is now aware that $a can no longer be `null` at this point return ($a === 10); }
此扩展指定传递给以下函数的值的类型
Assert::null()
Assert::notNull()
Assert::true()
Assert::false()
Assert::truthy()
Assert::falsey()
Assert::nan()
Assert::same()
Assert::notSame()
Assert::type()
Assert::count()
安装
要使用此扩展,请在 Composer 中要求它
composer require --dev nepada/phpstan-nette-tester
如果您还安装了 phpstan/extension-installer,那么您就设置好了!
如果您已启用 checkAlwaysTrueCheckTypeFunctionCall: true
,则需要添加一些忽略的错误
parameters:
ignoreErrors:
- '~Call to static method Tester\\Assert::(type|count|same|notSame)\(\) with .* and .* will always evaluate to true\.~'
- '~Call to static method Tester\\Assert::(null|notNull|true|false|truthy|falsey|nan)\(\) with .* will always evaluate to true\.~'
手动安装
如果您不想使用 phpstan/extension-installer
,请将 extension.neon 包含在您的项目 PHPStan 配置中
includes:
- vendor/nepada/phpstan-nette-tester/extension.neon