phpstan / phpstan-nette
Nette Framework class reflection extension for PHPStan
Package info
github.com/phpstan/phpstan-nette
Type:phpstan-extension
pkg:composer/phpstan/phpstan-nette
2.0.10
2026-06-04 10:10 UTC
Requires
- php: ^7.4 || ^8.0
- phpstan/phpstan: ^2.2.2
Requires (Dev)
- nette/application: ^3.0
- nette/di: ^3.0
- nette/forms: ^3.0
- nette/utils: ^2.3.0 || ^3.0.0 || ^4.0
- php-parallel-lint/php-parallel-lint: ^1.2
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0.8
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^9.6
- shipmonk/name-collision-detector: ^2.1
Conflicts
- nette/application: <2.3.0
- nette/component-model: <2.3.0
- nette/di: <2.3.0
- nette/forms: <2.3.0
- nette/http: <2.3.0
- nette/utils: <2.3.0
This package is auto-updated.
Last update: 2026-06-10 12:22:04 UTC
README
This extension provides following features:
Nette\ComponentModel\Container::getComponent()knows type of the component because it reads the return type oncreateComponent*(this works best in presenters and controls)- Array access on components (
$component['name']) resolves types viacreateComponent*methods Nette\DI\Container::getByTypeandcreateInstancereturn type based on first parameter (Foo::class).Nette\Forms\Container::getValuesreturn type based on$asArrayparameter.Nette\Forms\Container::getUntrustedValuesreturn type based on mapping class parameter.Nette\Forms\Controls\BaseControlfluent methods returnstaticinstead ofBaseControl.Nette\ComponentModel\Component::lookupreturn type based on$throwparameter.Nette\Application\UI\Component::getPresenterreturn type based on$throwparameter.Nette\Application\UI\Presenter::getSessionreturnsSessionorSessionSectionbased on arguments.- Dynamic methods of Nette\Utils\Html
- Magic Nette\Object and Nette\SmartObject properties
- Event listeners through the
on*properties - Presenter
@injectproperties are treated as initialized. - Defines early terminating method calls for Presenter methods to prevent
Undefined variableerrors - Understand the exact array shape coming from
Nette\Utils\Strings::match()andNette\Utils\Strings::matchAll()based on pattern Nette\Utils\Strings::replace()callback closure parameter type inferred from regex pattern
It also contains these framework-specific rules (can be enabled separately):
- Do not extend Nette\Object, use Nette\SmartObject trait instead
- Rethrow exceptions that are always meant to be rethrown (like
AbortException) - Validate regex patterns passed to
Nette\Utils\Stringsmethods
Installation
To use this extension, require it in Composer:
composer require --dev phpstan/phpstan-nette
If you also install phpstan/extension-installer then you're all set!
Manual installation
If you don't want to use phpstan/extension-installer, include extension.neon in your project's PHPStan config:
includes:
- vendor/phpstan/phpstan-nette/extension.neon
To perform framework-specific checks, include also this file:
- vendor/phpstan/phpstan-nette/rules.neon