Skip to content

[1.7] New errorFormat config should register default ErrorFormatter service that is then used by CI formatters #7305

@ruudk

Description

@ruudk

Feature request

I created this PR that shipped with PHPStan 1.7:

Now that I want to use it, I think it's not the right approach.

When I add this to my config:

errorFormat: custom

and run vendor/bin/phpstan analyze it picks it up automatically.

But when I run this on GitHub Actions, I have to run it with --errorFormat=github so that it uses the github error formatter, but it decores the table formatter. That means that the errors written to the output are in the old table format.

This is because of this:
https://github.com/phpstan/phpstan-src/blob/855d37fd48a3c7ef917550e75205b96f6d6cd8d1/conf/config.neon#L1927-L1931

I'm not sure if Nette DI supports this but in Symfony DI I could alias an interface to an actual implementation service.

For example:

PHPStan\Command\ErrorFormatter\ErrorFormatter: @errorFormatter.table

Then when errorFormat was specified in the config, it would replace the PHPStan\Command\ErrorFormatter\ErrorFormatter service with @errorFormatter.%errorFormat%

We then remove this:
https://github.com/phpstan/phpstan-src/blob/855d37fd48a3c7ef917550e75205b96f6d6cd8d1/src/Command/AnalyseCommand.php#L180-L182

And just inject the default PHPStan\Command\ErrorFormatter\ErrorFormatter service, that automatically resolves to the custom error format or falls back to the table one.

When CI is detected, it will pick errorFormatter.github that decorates the PHPStan\Command\ErrorFormatter\ErrorFormatter service. It should then also use the custom error format.

Pro's:

  • When running with errorFormat: custom it will pick that error formatter
  • When on CI, and running without --errorFormat argument, it will always use the CI detector, detect GitHub, use that one, and decorate using the custom error formatter too.
  • When on CI, you can specify --errorFormat=whatever if you don't want this to happen, and it will adhere to that
  • When no errorFormat config is specified, it will be the table formatter by default.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions