nette / phpstan-rules
🐘 PHPStan rules and type extensions for Nette libraries
Installs: 5
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
Open Issues: 0
Type:phpstan-extension
pkg:composer/nette/phpstan-rules
Requires
- php: 8.1 - 8.5
- phpstan/phpstan: ^2.1
Requires (Dev)
- nette/tester: ^2.6
This package is auto-updated.
Last update: 2026-02-10 17:33:12 UTC
README
PHPStan extensions for Nette libraries
Provides custom type extensions and error suppression rules used when analysing Nette libraries with PHPStan.
Installation
Install via Composer:
composer require --dev nette/phpstan-rules
Requirements: PHP 8.1 or higher and PHPStan 2.1+.
The extension is auto-registered via phpstan/extension-installer. No manual configuration needed.
What's Included
Narrow Return Types
Removes |false from return types of native PHP functions and methods where false is trivial or outdated. For example, getcwd() returns string|false, but on modern systems false is unrealistic. This extension narrows it to string.
Covered functions include getcwd, json_encode, preg_match, preg_split, hash, explode, array_combine, and many more.
// Without extension: string|false // With extension: non-empty-string $cwd = getcwd();
Type Validation Call Ignore
Suppresses expr.resultUnused for the runtime type validation pattern commonly used in Nette:
/** @param string[] $items */ public function setItems(array $items): void { (function (string ...$items) {})(...$items); }
PHPStan normally reports the closure call result as unused. This extension recognizes the pattern (empty closure body, all parameters variadic with type hints) and ignores the error.
Type Assertion Testing Helper
The package also provides Nette\PHPStan\Testing\TypeAssert for testing type inference in Nette packages using Nette Tester:
use Nette\PHPStan\Testing\TypeAssert; // Verify assertType() calls in a data file TypeAssert::assertTypes(__DIR__ . '/data/types.php', [__DIR__ . '/../extension.neon']); // Verify PHPStan reports no errors on a file TypeAssert::assertNoErrors(__DIR__ . '/data/clean.php', [__DIR__ . '/../extension.neon']);
The data file uses assertType() from PHPStan:
use function PHPStan\Testing\assertType; assertType('non-empty-string', getcwd()); assertType('string', Normalizer::normalize('foo'));
Support Me
Do you like Nette? Are you looking forward to the new features?
Thank you!