phpstan/phpstan-nette
PHPStan extension for Nette Framework. Improves type inference for components, DI container, forms, presenters/sessions, Html dynamic methods, SmartObject magic properties, events, and regex-based Strings utilities. Includes optional Nette-specific rules.
Install the package via Composer as a development dependency:
composer require --dev phpstan/phpstan-nette
If you use phpstan/extension-installer, it will auto-register. Otherwise, manually include extension.neon (and optionally rules.neon for additional framework-specific checks) in your phpstan.neon or phpstan.dist.neon. Start by running PHPStan on your project — you’ll immediately benefit from improved type inference in Nette presenters, controls, forms, and services. A first-use case: try analyzing a presenter with createComponent* methods — PHPStan will now correctly infer the types returned by $this->getComponent('foo').
getComponent() with precise return types based on createComponent*() signatures — no more @phpstan-return workarounds.getValues() with typed return (array<string, mixed> or shape-aware types based on $asArray) and getUntrustedValues() infering type from the mapping class.getByType(Foo::class) to resolve to Foo (or ?Foo if nullable), reducing need for casts.Strings::match()/matchAll() patterns with exact array shapes inferred (e.g., named captures become associative keys); Strings::replace()’s callback parameter types are inferred from regex groups.@inject properties and SmartObject magic getters/setters are understood out-of-the-box — no false positives.on* property event signatures are inferred for type-safe event listening.DoNotExtendNetteObjectRule, RethrowExceptionRule, RegularExpressionPatternRule) live in rules.neon — remember to include it for linting best practices.Container::getComponent() types, define return types on createComponent*() methods explicitly — missing or overly generic signatures (: Component) reduce precision.getValues(false) returns typed objects; ensure your mapping classes have proper types — otherwise PHPStan falls back to mixed.--level=max with --debug to trace missing type inference. Common culprits: missing @template in generic classes (e.g., Multiplier, Selection), or dynamic component names (e.g., $this->getComponent($dynamicName)).phpstan/phpstan-nette alongside Nette to keep them aligned (especially for Html, FileUpload::getImageSize(), and Strings utilities).How can I help you explore Laravel packages today?