Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions extension.neon
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,28 @@ parameters:
editorUrl: null

services:
errorFormatter.github:
class: PHPStan\Command\ErrorFormatter\GithubErrorFormatter
arguments:
relativePathHelper: @relativePathHelper

errorFormatter.teamcity:
class: PHPStan\Command\ErrorFormatter\TeamcityErrorFormatter
arguments:
relativePathHelper: @relativePathHelper

errorFormatter.ciDetected:
class: PHPStan\Command\ErrorFormatter\CiDetectedErrorFormatter
arguments:
githubErrorFormatter: @errorFormatter.github
teamcityErrorFormatter: @errorFormatter.teamcity

errorFormatter.friendly:
class: Yamadashy\PhpStanFriendlyFormatter\FriendlyErrorFormatter
arguments:
relativePathHelper: @relativePathHelper
simpleRelativePathHelper: @simpleRelativePathHelper
ciDetectedErrorFormatter: @errorFormatter.ciDetected
lineBefore: %friendly.lineBefore%
lineAfter: %friendly.lineAfter%
editorUrl: %friendly.editorUrl%
8 changes: 8 additions & 0 deletions src/FriendlyErrorFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PHPStan\Analyser\Error;
use PHPStan\Command\AnalysisResult;
use PHPStan\Command\ErrorFormatter\CiDetectedErrorFormatter;
use PHPStan\Command\ErrorFormatter\ErrorFormatter;
use PHPStan\Command\Output;
use PHPStan\File\RelativePathHelper;
Expand All @@ -20,18 +21,23 @@ class FriendlyErrorFormatter implements ErrorFormatter
/** @var SimpleRelativePathHelper */
private $simpleRelativePathHelper;

/** @var CiDetectedErrorFormatter */
private $ciDetectedErrorFormatter;

/** @var FriendlyFormatterConfig */
private $config;

public function __construct(
RelativePathHelper $relativePathHelper,
SimpleRelativePathHelper $simpleRelativePathHelper,
CiDetectedErrorFormatter $ciDetectedErrorFormatter,
int $lineBefore,
int $lineAfter,
?string $editorUrl
) {
$this->relativePathHelper = $relativePathHelper;
$this->simpleRelativePathHelper = $simpleRelativePathHelper;
$this->ciDetectedErrorFormatter = $ciDetectedErrorFormatter;
$this->config = new FriendlyFormatterConfig(
$lineBefore,
$lineAfter,
Expand All @@ -48,6 +54,8 @@ public function formatErrors(AnalysisResult $analysisResult, Output $output): in
return $this->handleNoErrors($output);
}

$this->ciDetectedErrorFormatter->formatErrors($analysisResult, $output);

$output->writeLineFormatted('');

$errorWriter = new ErrorWriter($this->relativePathHelper, $this->simpleRelativePathHelper, $this->config);
Expand Down
9 changes: 7 additions & 2 deletions tests/FriendlyErrorFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use PHPStan\Analyser\Error;
use PHPStan\Command\AnalysisResult;
use PHPStan\Command\ErrorFormatter\CiDetectedErrorFormatter;
use PHPStan\Command\ErrorFormatter\GithubErrorFormatter;
use PHPStan\Command\ErrorFormatter\TeamcityErrorFormatter;
use PHPStan\File\FuzzyRelativePathHelper;
use PHPStan\File\NullRelativePathHelper;
use PHPStan\File\SimpleRelativePathHelper;
Expand Down Expand Up @@ -33,7 +36,8 @@ public function testFormatErrors(
): void {
$relativePathHelper = new FuzzyRelativePathHelper(new NullRelativePathHelper(), '', [], '/');
$simpleRelativePathHelper = new SimpleRelativePathHelper((string) getcwd());
$formatter = new FriendlyErrorFormatter($relativePathHelper, $simpleRelativePathHelper, 3, 3, null);
$ciDetectedErrorFormatter = new CiDetectedErrorFormatter(new GithubErrorFormatter($relativePathHelper), new TeamcityErrorFormatter($relativePathHelper));
$formatter = new FriendlyErrorFormatter($relativePathHelper, $simpleRelativePathHelper, $ciDetectedErrorFormatter, 3, 3, null);
$dummyAnalysisResult = $this->getDummyAnalysisResult($numFileErrors, $numGenericErrors, $numWarnings);

$exitCode = $formatter->formatErrors($dummyAnalysisResult, $this->getOutput());
Expand Down Expand Up @@ -202,7 +206,8 @@ public function testSummaryShowsSpecialIdentifierNotes(): void
{
$relativePathHelper = new FuzzyRelativePathHelper(new NullRelativePathHelper(), '', [], '/');
$simpleRelativePathHelper = new SimpleRelativePathHelper((string) getcwd());
$formatter = new FriendlyErrorFormatter($relativePathHelper, $simpleRelativePathHelper, 3, 3, null);
$ciDetectedErrorFormatter = new CiDetectedErrorFormatter(new GithubErrorFormatter($relativePathHelper), new TeamcityErrorFormatter($relativePathHelper));
$formatter = new FriendlyErrorFormatter($relativePathHelper, $simpleRelativePathHelper, $ciDetectedErrorFormatter, 3, 3, null);

$fileErrors = [
new Error('Ignore unmatched', __DIR__.'/data/AnalysisTargetFoo.php', 13, true, null, null, null, null, null, 'ignore.unmatched'),
Expand Down