PHPackages                             metisfw/phpstan-nette-links - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. metisfw/phpstan-nette-links

ActivePhpstan-extension[Utility &amp; Helpers](/categories/utility)

metisfw/phpstan-nette-links
===========================

Nette Framework link checking extension for PHPStan

v0.3(9mo ago)21.7k1[1 PRs](https://github.com/MetisFW/phpstan-nette-links/pulls)MITPHPPHP ^7.4 || ^8.0CI passing

Since Nov 13Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/MetisFW/phpstan-nette-links)[ Packagist](https://packagist.org/packages/metisfw/phpstan-nette-links)[ RSS](/packages/metisfw-phpstan-nette-links/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (11)Versions (4)Used By (0)

Nette Framework link validation for PHPStan
===========================================

[](#nette-framework-link-validation-for-phpstan)

[![Build](https://github.com/metisfw/phpstan-nette-links/workflows/Build/badge.svg)](https://github.com/phpstan/phpstan-nette/actions)[![License](https://camo.githubusercontent.com/f9ae5ded59f770a8b8c4ac6a07ab4f0381261a43c45dea4f64b5e7d98974be98/68747470733a2f2f706f7365722e707567782e6f72672f7068707374616e2f7068707374616e2d6e657474652f6c6963656e7365)](https://packagist.org/packages/phpstan/phpstan-nette)

- [PHPStan](https://phpstan.org/)
- [Nette Framework](https://nette.org/)

Check links in your Nette Framework applications using PHPStan.

[![Preview](docs/preview.png)](docs/preview.png)

Features
--------

[](#features)

- Validate parameters passed to `link()`, `lazyLink()`, `redirect()`, `redirectPermanent()`, `forward()`, `isLinkCurrent()` and `canonicalize()` 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*()` or `handle*()` method signature
- Checks also links to sub-components of known types (`createComponent*()` method must exists)

Installation
------------

[](#installation)

To use this extension, require it in [Composer](https://getcomposer.org/):

```
composer require --dev metisfw/phpstan-nette-links

```

If you also install [phpstan/extension-installer](https://github.com/phpstan/extension-installer) then you're all set!

 Manual installationIf 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
-------------

[](#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

[](#containerloader)

Container loader can be used to create instance of Nette application DI container.

Example:

```
parameters:
    netteLinks:
        containerLoader: './containerLoader.php'
```

Example `containerLoader.php`:

```
