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
1 change: 0 additions & 1 deletion build/target-repository/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ We currently provide formatters for:

- `console`: Human-oriented printing à la PHP CS Fixer.
- `json`: A custom JSON blob for arbitrary tooling.
- `junit`: JUnit format to be used in different CI environments.
- `checkstyle`: Useful for Github Action Reports.
- `gitlab`: For Gitlab code quality reports or Code Climate tooling.

Expand Down
104 changes: 0 additions & 104 deletions src/Console/Output/JUnitOutputFormatter.php

This file was deleted.

24 changes: 23 additions & 1 deletion src/Console/Output/OutputFormatterCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,21 @@

namespace Symplify\EasyCodingStandard\Console\Output;

use Symplify\EasyCodingStandard\Console\Style\EasyCodingStandardStyle;
use Symplify\EasyCodingStandard\Contract\Console\Output\OutputFormatterInterface;
use Symplify\EasyCodingStandard\Exception\Configuration\OutputFormatterNotFoundException;

final class OutputFormatterCollector
{
/**
* Formats dropped as ECS is a fixer, not a static analyzer; each maps to a still-supported fallback.
*
* @var array<string, string>
*/
private const array REMOVED_FORMATS = [
'junit' => ConsoleOutputFormatter::NAME,
];

/**
* @var array<string, OutputFormatterInterface>
*/
Expand All @@ -18,7 +28,8 @@ final class OutputFormatterCollector
* @param OutputFormatterInterface[] $outputFormatters
*/
public function __construct(
array $outputFormatters
array $outputFormatters,
private readonly EasyCodingStandardStyle $easyCodingStandardStyle
) {
foreach ($outputFormatters as $outputFormatter) {
$this->outputFormatters[$outputFormatter->getName()] = $outputFormatter;
Expand All @@ -31,6 +42,17 @@ public function getByName(string $name): OutputFormatterInterface
return $this->outputFormatters[$name];
}

if (isset(self::REMOVED_FORMATS[$name])) {
$fallback = self::REMOVED_FORMATS[$name];
$this->easyCodingStandardStyle->warning(sprintf(
'The "%s" output format was removed, as ECS is a fixer, not a static analyzer. Falling back to "%s".',
$name,
$fallback
));

return $this->outputFormatters[$fallback];
}

$outputFormatterKeys = array_keys($this->outputFormatters);

$errorMessage = sprintf(
Expand Down
1 change: 0 additions & 1 deletion tests/Console/Output/Fixture/expected_junit_output.xml

This file was deleted.

61 changes: 0 additions & 61 deletions tests/Console/Output/JUnitOutputFormatterTest.php

This file was deleted.

13 changes: 8 additions & 5 deletions tests/Console/Output/OutputFormatterCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Symplify\EasyCodingStandard\Console\Output\ConsoleOutputFormatter;
use Symplify\EasyCodingStandard\Console\Output\GitlabOutputFormatter;
use Symplify\EasyCodingStandard\Console\Output\JsonOutputFormatter;
use Symplify\EasyCodingStandard\Console\Output\JUnitOutputFormatter;
use Symplify\EasyCodingStandard\Console\Output\OutputFormatterCollector;
use Symplify\EasyCodingStandard\Testing\PHPUnit\AbstractTestCase;

Expand All @@ -33,10 +32,6 @@ public function test(): void
JsonOutputFormatter::class,
$this->outputFormatterCollector->getByName(JsonOutputFormatter::getName())
);
$this->assertInstanceOf(
JUnitOutputFormatter::class,
$this->outputFormatterCollector->getByName(JUnitOutputFormatter::getName())
);
$this->assertInstanceOf(
GitlabOutputFormatter::class,
$this->outputFormatterCollector->getByName(GitlabOutputFormatter::getName())
Expand All @@ -46,4 +41,12 @@ public function test(): void
$this->outputFormatterCollector->getByName(CheckstyleOutputFormatter::getName())
);
}

public function testRemovedJUnitFormatFallsBackToConsole(): void
{
$this->assertInstanceOf(
ConsoleOutputFormatter::class,
$this->outputFormatterCollector->getByName('junit')
);
}
}
Loading