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:
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.
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:
and run
vendor/bin/phpstan analyzeit picks it up automatically.But when I run this on GitHub Actions, I have to run it with
--errorFormat=githubso that it uses thegithuberror formatter, but it decores thetableformatter. That means that the errors written to the output are in the oldtableformat.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:
Then when
errorFormatwas specified in the config, it would replace thePHPStan\Command\ErrorFormatter\ErrorFormatterservice 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\ErrorFormatterservice, that automatically resolves to the custom error format or falls back to thetableone.When CI is detected, it will pick
errorFormatter.githubthat decorates thePHPStan\Command\ErrorFormatter\ErrorFormatterservice. It should then also use the custom error format.Pro's:
errorFormat: customit will pick that error formatter--errorFormatargument, it will always use the CI detector, detect GitHub, use that one, and decorate using thecustomerror formatter too.--errorFormat=whateverif you don't want this to happen, and it will adhere to thaterrorFormatconfig is specified, it will be thetableformatter by default.