metisfw / phpstan-nette-links
Nette Framework link checking extension for PHPStan
Installs: 803
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 1
Open Issues: 0
Type:phpstan-extension
Requires
- php: ^7.2 || ^8.0
- phpstan/phpstan: ^1.10
- phpstan/phpstan-nette: ^1.2.9
Requires (Dev)
- nette/application: ^3.0
- nette/di: ^2.3.0 || ^3.0.0
- nette/forms: ^3.0
- nette/utils: ^2.3.0 || ^3.0.0
- nikic/php-parser: ^4.13.2
- php-parallel-lint/php-parallel-lint: ^1.2
- phpstan/phpstan-php-parser: ^1.1
- phpstan/phpstan-phpunit: ^1.0
- phpstan/phpstan-strict-rules: ^1.0
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-12-11 14:32:33 UTC
README
Check links in your Nette Framework applications using PHPStan.
Features
- 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)
Installation
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
Configuration
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
containerLoader
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();
applicationMapping
Application mapping is used to map presenter identfiers to classes in link checking.
Example:
parameters: netteLinks: applicationMapping: *: App\Presenters\*\*Presenter