nepada/phpstan-nette-tester

PHPStan nette/tester 扩展

安装量: 265,409

依赖者: 27

建议者: 0

安全: 0

星星: 3

关注者: 3

分支: 1

开放问题: 0

类型:phpstan-extension

v1.2.0 2024-04-06 07:09 UTC

README

Build Status Coverage Status Downloads this Month Latest stable

此扩展深受 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