phpstan/phpstan-nette

Nette Framework class reflection extension for PHPStan

Maintainers

👁 ondrejmirtes

Package info

github.com/phpstan/phpstan-nette

Type:phpstan-extension

pkg:composer/phpstan/phpstan-nette

Statistics

Installs: 10 484 137

Dependents: 622

Suggesters: 3

Stars: 118

Open Issues: 15

2.0.10 2026-06-04 10:10 UTC

Requires

Suggests

None

Provides

None

Conflicts

Replaces

None

MIT 26e6253fff54b6ffbcc964016633dd09249f97a7


README

👁 Build
👁 Latest Stable Version
👁 License

This extension provides following features:

  • Nette\ComponentModel\Container::getComponent() knows type of the component because it reads the return type on createComponent* (this works best in presenters and controls)
  • Array access on components ($component['name']) resolves types via createComponent* methods
  • Nette\DI\Container::getByType and createInstance return type based on first parameter (Foo::class).
  • Nette\Forms\Container::getValues return type based on $asArray parameter.
  • Nette\Forms\Container::getUntrustedValues return type based on mapping class parameter.
  • Nette\Forms\Controls\BaseControl fluent methods return static instead of BaseControl.
  • Nette\ComponentModel\Component::lookup return type based on $throw parameter.
  • Nette\Application\UI\Component::getPresenter return type based on $throw parameter.
  • Nette\Application\UI\Presenter::getSession returns Session or SessionSection based on arguments.
  • Dynamic methods of Nette\Utils\Html
  • Magic Nette\Object and Nette\SmartObject properties
  • Event listeners through the on* properties
  • Presenter @inject properties are treated as initialized.
  • Defines early terminating method calls for Presenter methods to prevent Undefined variable errors
  • Understand the exact array shape coming from Nette\Utils\Strings::match() and Nette\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\Strings methods

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!