yamadashy/phpstan-friendly-formatter

Simple error formatter for PHPStan that display code frame

Installs: 1 348

Dependents: 2

Suggesters: 0

Security: 0

Stars: 5

Watchers: 2

Forks: 0

Open Issues: 0

Type:phpstan-extension

v1.0.1 2023-06-19 14:40 UTC

This package is auto-updated.

Last update: 2024-04-24 15:06:56 UTC


README

A simple error formatter for PHPStan that display code frame.

Before PHPStan Example
After PHPStan Example

Test Status Latest Version License

Motivation

The default phpstan formatter displays the file path, line number, and error, but this does not allow us to instantly determine what is actually wrong.

This package aims to complement the default formatter by displaying the corresponding source code alongside the error information, making it easier to locate and address issues more

Getting Started

  1. You may use Composer to install this package as a development dependency.
composer require --dev yamadashy/phpstan-friendly-formatter
  1. Register error formatter into your phpstan.neon or phpstan.neon.dist:
includes:
    - ./vendor/yamadashy/phpstan-friendly-formatter/extension.neon
  1. Finaly, use phpstan console command with --error-format option:
./vendor/bin/phpstan analyze --error-format friendly

Optional

If you want to make it simpler, setting scripts in composer.json as follows:

{
    "scripts": {
        "analyze": "phpstan analyze --error-format friendly"
    }
}

You can run a short command like this:

composer analyze

Config

You can customize in your phpstan.neon:

parameters:
    friendly:
        # default is 3
        lineBefore: 3
        lineAfter: 3
        # default is null
        editorUrl: 'phpstorm://open?file=%%file%%&line=%%line%%'
  • lineBefore ... Number of lines to display before error line
  • lineAfter ... Number of lines to display after error line
  • editorUrl ... URL with placeholders like [table formatter config](URL for editor like table formatter)

Example

When you actually introduce it in GitHub Actions, it will be displayed as follows.

https://github.com/yamadashy/laravel-blade-minify-directive/actions/runs/4714024802/jobs/8360104870

License

Distributed under the MIT license.