Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Phpstan Nette Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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').

Implementation Patterns

  • Presenters & Controls: Leverage getComponent() with precise return types based on createComponent*() signatures — no more @phpstan-return workarounds.
  • Forms: Use getValues() with typed return (array<string, mixed> or shape-aware types based on $asArray) and getUntrustedValues() infering type from the mapping class.
  • DI Container: Trust getByType(Foo::class) to resolve to Foo (or ?Foo if nullable), reducing need for casts.
  • Strings: Analyze 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.
  • Magic Properties: @inject properties and SmartObject magic getters/setters are understood out-of-the-box — no false positives.
  • Event Handling: on* property event signatures are inferred for type-safe event listening.

Gotchas and Tips

  • Version Compatibility: Ensure your Nette and PHP versions match the extension’s requirements (v2 requires PHP ≥8.1 and Nette ≥3.0 or 4.x). Mismatched versions cause missing type inference or crashes.
  • Enable Rules Explicitly: Framework-specific rules (e.g., DoNotExtendNetteObjectRule, RethrowExceptionRule, RegularExpressionPatternRule) live in rules.neon — remember to include it for linting best practices.
  • Registry Component Types: For custom Container::getComponent() types, define return types on createComponent*() methods explicitly — missing or overly generic signatures (: Component) reduce precision.
  • Form Value Inference: getValues(false) returns typed objects; ensure your mapping classes have proper types — otherwise PHPStan falls back to mixed.
  • Debugging Failures: Use --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)).
  • Stubs Matter: The extension relies on precise method stubs — upgrade phpstan/phpstan-nette alongside Nette to keep them aligned (especially for Html, FileUpload::getImageSize(), and Strings utilities).
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport