Componette

Componette

nepada

nepada / phpstan-nette-tester v2.0.0

PHPStan nette/tester extension

download-cloud-line composer require nepada/phpstan-nette-tester

PHPStan nette/tester extension

Build Status Coverage Status Downloads this Month Latest stable

This extension was heavily inspired by phpstan/phpstan/phpstan-webmozart-assert developed by Ondřej Mirtes.

It was originally developed and published under damejidlo organization.

Description

The main scope of this extension is to help phpstan to detect the type of object after the Tester\Assert validation.

<?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);
}

This extension specifies types of values passed to:

  • Assert::null()
  • Assert::notNull()
  • Assert::true()
  • Assert::false()
  • Assert::truthy()
  • Assert::falsey()
  • Assert::nan()
  • Assert::same()
  • Assert::notSame()
  • Assert::type()
  • Assert::count()

Installation

To use this extension, require it in Composer:

composer require --dev nepada/phpstan-nette-tester

If you also install phpstan/extension-installer then you're all set!

If you have enabled checkAlwaysTrueCheckTypeFunctionCall: true, you will need to add some ignored errors:

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\.~'

Manual installation

If you don't want to use phpstan/extension-installer, include extension.neon in your project's PHPStan config:

includes:
    - vendor/nepada/phpstan-nette-tester/extension.neon
  • v2.0.0 2.0.0

    • Support & require PHPStan 2.0
  • v1.3.0 1.3.0

    • Minimal required PHPStan version bumped to 1.12
    • Add support for multiple possible constant string values in Assert::type()
    • Add support for assert list type
  • v1.2.1 1.2.1

    • PHP 8.4 compatibility
  • v1.2.0 1.2.0

    • Allow nikic/php-parser 5.x
  • v1.1.0 1.1.0

    • PHP 8.3 compatibility
    • Requires PHPStan >=1.8
  • v1.0.0 1.0.0

    • Drop support for PHP <7.4
    • Add support for PHP 8.2
  • v0.4.0 0.4.0

    • PHPStan 1.0 support.
  • v0.3.2 0.3.2

    • Fixed compatibility with latest nikic/php-parser on PHP 8.1.
  • v0.3.1 0.3.1

    • PHP 8.0 support.
  • v0.3.0 0.3.0

    • First release under the new name. Functionally equivalent to original damejidlo/phpstan-nette-tester 0.2.0
Componette Componette felix@nette.org