大麦食品/phpstan-nette-tester

此软件包已被废弃,不再维护。作者建议使用 nepada/phpstan-nette-tester 软件包。

PHPStan nette/tester 扩展

安装数: 47,983

依赖项: 1

建议者: 0

安全: 0

星标: 1

关注者: 6

分支: 0

公开问题: 0

类型:phpstan-extension

v0.2.0 2019-12-05 09:14 UTC

This package is auto-updated.

Last update: 2020-01-15 11:41:24 UTC


README

Build Status Downloads this Month Latest stable

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