Check links in your Nette Framework applications using PHPStan.
- Validate parameters passed to
link()
,lazyLink()
,redirect()
,redirectPermanent()
,forward()
,isLinkCurrent()
andcanonicalize()
methods - Works for presenters, components and 'LinkGenerator' service
- Checks if passed destination is valid and points to existing presenter, action or signal
- Checks if passed link parameters are valid and match relevant
action*()
,render*()
orhandle*()
method signature - Checks also links to sub-components of known types (
createComponent*()
method must exists)
To use this extension, require it in Composer:
composer require --dev metisfw/phpstan-nette-links
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/metisfw/phpstan-nette-links/extension.neon
To perform framework-specific checks, include also this file:
- vendor/metisfw/phpstan-nette-links/rules.neon
Either applicationMapping
or containerLoader
(for automatically loading mappings from PresenterFactory
service in your app) must be set for link checking to work.
If you use non-standard PresenterFactory
this feature might not work because logic for mapping presenter name (e.g. MyModule:Homepage
) to presenter class (e.g. \App\Presenters\MyModule\HomepagePresenter
) and vice versa would work differently.
If you use containerLoader
you might solve this by implementing method unformatPresenterClass
in your custom PresenterFactory
class. This method should return presenter name for given presenter class.
Or you can create custom implementation overriding PHPStanNetteLinks\Nette\PresenterResolver
service and replace it in your PHPStan config:
services:
nettePresenterResolver:
class: MyCustom\PresenterResolver
Container loader can be used to create instance of Nette application DI container.
Example:
parameters:
netteLinks:
containerLoader: './containerLoader.php'
Example containerLoader.php
:
<?php
return App\Bootstrap::boot()->createContainer();
Application mapping is used to map presenter identfiers to classes in link checking.
Example:
parameters:
netteLinks:
applicationMapping:
*: App\Presenters\*\*Presenter