Skip to content

Commit c42190a

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

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-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: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace PHPStan\Command\ErrorFormatter;
4+
5+
use PHPStan\Command\AnalysisResult;
6+
use PHPStan\Command\Output;
7+
8+
/**
9+
* @api
10+
*/
11+
final class ChainErrorFormatter implements ErrorFormatter
12+
{
13+
14+
/**
15+
* @param list<ErrorFormatter> $formatters
16+
*/
17+
public function __construct(
18+
private array $formatters,
19+
)
20+
{
21+
}
22+
23+
public function formatErrors(AnalysisResult $analysisResult, Output $output): int
24+
{
25+
foreach ($this->formatters as $errorFormatter) {
26+
$errorFormatter->formatErrors($analysisResult, $output);
27+
}
28+
29+
return $analysisResult->hasErrors() ? 1 : 0;
30+
}
31+
32+
}

0 commit comments

Comments
 (0)