tzmfreedom / phpstan-extensions
PHPStan extensions
Installs: 13
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Type:phpstan-extension
Requires
- phpstan/phpstan: ^1.10
Requires (Dev)
- phpunit/phpunit: ^10.5
README
VisibleForTestingRule
PHPStan custom rules to ensure that VisibleForTesting annotated public methods are called in private/protected scopes outside of the test environment, inspired by @VisibleForTesting annotation on Flutter, Java (Guava)
In following code, this extension report error outside of the test environment.
<?php use Tzmfreedom\Attributes\VisibleForTesting; class Foo { #[VisibleForTesting] public function exampleWithAttribute() {} /** * @visibleForTesting */ public function exampleWithPhpdoc() {} } (new Foo)->exampleWithAttribute(); // error: VisibleForTesting annotated method Foo::visibleForTestingWithAttribute should be called in private scope outside of the test environment
UnusedReturnRule
<?php class Foo { public function getString(): string { return ''; } } (new Foo)->getString(); // error: Return value on Method Foo::getString() is unused $_ = (new Foo)->getString(); // OK
OverwriteVariableRule
<?php $var = null; $var = 'hoge'; // OK, changing from null to any $var = 'fuga'; // NG
OverwriteDifferentTypeVariableRule
<?php $var = null; $var = 'hoge'; // OK, changing from null to any $var = 1; // NG, changing from string to integer $var = 1.0; // OK, changing from integer to float $var = 1; // OK, changeing from float to integer $var = new \stdClass(); // NG $var = new class extends \stdClass{}; // OK $var = new \stdClass(); // OK
Installation
$ composer require --dev tzmfreedom/phpstan-extensions
phpstan.neon
rules: - Tzmfreedom\PHPStan\Rules\VisibleForTestingRule - Tzmfreedom\PHPStan\Rules\UnusedReturnRule