Skip to content

Commit e3016fe

Browse files
committed
Allow gitlab error formatter to output to a specific file instead of stdout
Gitlab code quality report doesnt read from the logs, but expects a file. In order to use this with multiple error reporters, we want to be able to redirect its output
1 parent a7911ae commit e3016fe

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/Command/ErrorFormatter/GitlabErrorFormatter.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
final class GitlabErrorFormatter implements ErrorFormatter
1616
{
1717

18-
public function __construct(private RelativePathHelper $relativePathHelper)
18+
public function __construct(
19+
private RelativePathHelper $relativePathHelper,
20+
private ?string $fileLocation = null,
21+
)
1922
{
2023
}
2124

@@ -64,7 +67,11 @@ public function formatErrors(AnalysisResult $analysisResult, Output $output): in
6467

6568
$json = Json::encode($errorsArray, Json::PRETTY);
6669

67-
$output->writeRaw($json);
70+
if ($this->fileLocation !== null) {
71+
file_put_contents($this->fileLocation, $json);
72+
} else {
73+
$output->writeRaw($json);
74+
}
6875

6976
return $analysisResult->hasErrors() ? 1 : 0;
7077
}

0 commit comments

Comments
 (0)