Skip to content

Commit 0d2a028

Browse files
committed
Implement RawTextErrorFormatter
1 parent 76dbaef commit 0d2a028

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace CodeLts\CliTools\ErrorFormatter;
6+
7+
use CodeLts\CliTools\AnalysisResult;
8+
use CodeLts\CliTools\Output;
9+
10+
class RawTextErrorFormatter implements ErrorFormatter
11+
{
12+
13+
public function formatErrors(
14+
AnalysisResult $analysisResult,
15+
Output $output
16+
): int
17+
{
18+
foreach ($analysisResult->getNotFileSpecificErrors() as $notFileSpecificError) {
19+
$output->writeRaw('<fg=red>ERROR</>: ');
20+
$output->writeRaw($notFileSpecificError);
21+
}
22+
23+
foreach ($analysisResult->getFileSpecificErrors() as $error) {
24+
$output->writeRaw('<fg=red>ERROR</>: ');
25+
$output->writeRaw(
26+
sprintf('%s in %s:%d', $error->getMessage(), $error->getFile() ?? '', $error->getLine())
27+
);
28+
}
29+
30+
foreach ($analysisResult->getWarnings() as $warning) {
31+
$output->writeRaw('<fg=yellow>WARNING</>: ');
32+
$output->writeRaw($warning);
33+
}
34+
35+
36+
return $analysisResult->hasErrors() ? 1 : 0;
37+
}
38+
39+
}

0 commit comments

Comments
 (0)