metisfw/phpstan-nette-links

Nette Framework link checking extension for PHPStan

Installs: 699

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 1

Forks: 1

Open Issues: 0

Type:phpstan-extension

v0.2 2023-11-15 12:05 UTC

This package is auto-updated.

Last update: 2024-10-11 14:14:11 UTC


README

Build License

Check links in your Nette Framework applications using PHPStan.

Preview

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

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