-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e5be674
commit 7780aac
Showing
11 changed files
with
198 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace TwigCsFixer\Report\Reporter; | ||
|
||
use Symfony\Component\Console\Output\OutputInterface; | ||
use TwigCsFixer\Report\Report; | ||
|
||
/** | ||
* Reporter without output. | ||
*/ | ||
final class NullReporter implements ReporterInterface | ||
{ | ||
public const NAME = 'null'; | ||
|
||
public function display(OutputInterface $output, Report $report, ?string $level = null): void | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace TwigCsFixer\Report\Reporter; | ||
|
||
use Symfony\Component\Console\Output\OutputInterface; | ||
use TwigCsFixer\Report\Report; | ||
|
||
interface ReporterInterface | ||
{ | ||
public function display(OutputInterface $output, Report $report, ?string $level = null): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TwigCsFixer\Report; | ||
|
||
use InvalidArgumentException; | ||
use TwigCsFixer\Report\Reporter\NullReporter; | ||
use TwigCsFixer\Report\Reporter\ReporterInterface; | ||
use TwigCsFixer\Report\Reporter\TextReporter; | ||
|
||
final class ReporterFactory | ||
{ | ||
public function getReporter(?string $format = TextReporter::NAME): ReporterInterface | ||
{ | ||
return match ($format) { | ||
NullReporter::NAME => new NullReporter(), | ||
TextReporter::NAME => new TextReporter(), | ||
default => throw new InvalidArgumentException( | ||
sprintf('No reporter supports the format "%s".', $format) | ||
), | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TwigCsFixer\Tests\Report\Formatter; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use SplFileInfo; | ||
use Symfony\Component\Console\Output\BufferedOutput; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use TwigCsFixer\Report\Reporter\NullReporter; | ||
use TwigCsFixer\Report\Report; | ||
use TwigCsFixer\Report\SniffViolation; | ||
|
||
final class NullReporterTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider displayDataProvider | ||
*/ | ||
public function testDisplayErrors(?string $level): void | ||
{ | ||
$textFormatter = new NullReporter(); | ||
|
||
$file = __DIR__.'/Fixtures/file.twig'; | ||
$report = new Report([new SplFileInfo($file)]); | ||
|
||
$violation0 = new SniffViolation(SniffViolation::LEVEL_NOTICE, 'Notice', $file, 1); | ||
$report->addMessage($violation0); | ||
$violation1 = new SniffViolation(SniffViolation::LEVEL_WARNING, 'Warning', $file, 2); | ||
$report->addMessage($violation1); | ||
$violation2 = new SniffViolation(SniffViolation::LEVEL_ERROR, 'Error', $file, 3); | ||
$report->addMessage($violation2); | ||
$violation3 = new SniffViolation(SniffViolation::LEVEL_FATAL, 'Fatal', $file); | ||
$report->addMessage($violation3); | ||
|
||
$output = new BufferedOutput(OutputInterface::VERBOSITY_NORMAL, true); | ||
$textFormatter->display($output, $report, $level); | ||
|
||
$text = $output->fetch(); | ||
static::assertSame('', $text); | ||
} | ||
|
||
/** | ||
* @return iterable<array-key, array{string|null}> | ||
*/ | ||
public static function displayDataProvider(): iterable | ||
{ | ||
yield [null]; | ||
yield [Report::MESSAGE_TYPE_NOTICE]; | ||
yield [Report::MESSAGE_TYPE_WARNING]; | ||
yield [Report::MESSAGE_TYPE_ERROR]; | ||
yield [Report::MESSAGE_TYPE_FATAL]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.