大麦食品 / phpstan-nette-tester
v0.2.0
2019-12-05 09:14 UTC
Requires
- php: >=7.2
- nikic/php-parser: ^4.0
- phpstan/phpstan: ^0.12.0
Requires (Dev)
- damejidlo/coding-standard: ^1.1.0
- jakub-onderka/php-parallel-lint: ^1.0
- nette/tester: ^2.3.1
- phpstan/phpstan-phpunit: ^0.12
- phpstan/phpstan-strict-rules: ^0.12
- phpunit/phpunit: ^7.5.17
This package is auto-updated.
Last update: 2020-01-15 11:41:24 UTC
README
此扩展受到由 phpstan/phpstan/phpstan-webmozart-assert 开发的 Ondřej Mirtes 的启发。
描述
本扩展的主要目标是帮助 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 damejidlo/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/damejidlo/phpstan-nette-tester/extension.neon