Skip to content

Commit a7911ae

Browse files
committed
Introduce the 'multiple' error formatter
Allows using multiple error formatters with just configuration
1 parent a0e007a commit a7911ae

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

conf/config.neon

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2174,3 +2174,9 @@ services:
21742174
class: PHPStan\Command\ErrorFormatter\TeamcityErrorFormatter
21752175
arguments:
21762176
relativePathHelper: @simpleRelativePathHelper
2177+
2178+
errorFormatter.multiple:
2179+
class: PHPStan\Command\ErrorFormatter\ChainErrorFormatter
2180+
arguments:
2181+
formatters:
2182+
- @errorFormatter.table
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace PHPStan\Command\ErrorFormatter;
4+
5+
use PHPStan\Command\AnalysisResult;
6+
use PHPStan\Command\Output;
7+
8+
/**
9+
* @api
10+
* @final
11+
*/
12+
class ChainErrorFormatter implements ErrorFormatter
13+
{
14+
/**
15+
* @param list<ErrorFormatter> $formatters
16+
*/
17+
public function __construct(
18+
private array $formatters,
19+
) {
20+
}
21+
22+
public function formatErrors(AnalysisResult $analysisResult, Output $output): int
23+
{
24+
foreach ($this->formatters as $errorFormatter) {
25+
$errorFormatter->formatErrors($analysisResult, $output);
26+
}
27+
28+
return $analysisResult->hasErrors() ? 1 : 0;
29+
}
30+
}

0 commit comments

Comments
 (0)