-
Notifications
You must be signed in to change notification settings - Fork 10
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
c58c597
commit c10fcf1
Showing
8 changed files
with
142 additions
and
51 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
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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TomasVotruba\PHPStanBodyscan\Contract; | ||
|
||
use TomasVotruba\PHPStanBodyscan\ValueObject\BodyscanResult; | ||
|
||
interface OutputFormatterInterface | ||
{ | ||
public function outputResult(BodyscanResult $bodyscanResult): 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,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TomasVotruba\PHPStanBodyscan\OutputFormatter; | ||
|
||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
use TomasVotruba\PHPStanBodyscan\Contract\OutputFormatterInterface; | ||
use TomasVotruba\PHPStanBodyscan\ValueObject\BodyscanResult; | ||
|
||
final readonly class JsonOutputFormatter implements OutputFormatterInterface | ||
{ | ||
public function __construct( | ||
private SymfonyStyle $symfonyStyle | ||
) { | ||
} | ||
|
||
public function outputResult(BodyscanResult $bodyscanResult): void | ||
{ | ||
// restore verbosity | ||
$this->symfonyStyle->setVerbosity(OutputInterface::VERBOSITY_NORMAL); | ||
|
||
$rawData = []; | ||
|
||
foreach ($bodyscanResult->getLevelResults() as $levelResult) { | ||
$rawData[] = [ | ||
'level' => $levelResult->getLevel(), | ||
'error_count' => $levelResult->getErrorCount(), | ||
]; | ||
} | ||
|
||
$jsonOutput = json_encode($rawData, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR); | ||
$this->symfonyStyle->writeln($jsonOutput); | ||
} | ||
} |
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,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TomasVotruba\PHPStanBodyscan\OutputFormatter; | ||
|
||
use Symfony\Component\Console\Helper\TableStyle; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
use TomasVotruba\PHPStanBodyscan\Contract\OutputFormatterInterface; | ||
use TomasVotruba\PHPStanBodyscan\ValueObject\BodyscanResult; | ||
|
||
final readonly class TableOutputFormatter implements OutputFormatterInterface | ||
{ | ||
public function __construct( | ||
private SymfonyStyle $symfonyStyle, | ||
) { | ||
} | ||
|
||
public function outputResult(BodyscanResult $bodyscanResult): void | ||
{ | ||
// convert to symfony table data | ||
$tableRows = []; | ||
foreach ($bodyscanResult->getLevelResults() as $levelResult) { | ||
$tableRows[] = [$levelResult->getLevel(), $levelResult->getErrorCount()]; | ||
} | ||
|
||
$tableStyle = new TableStyle(); | ||
$tableStyle->setPadType(STR_PAD_LEFT); | ||
|
||
$this->symfonyStyle->newLine(2); | ||
|
||
$this->symfonyStyle->createTable() | ||
->setHeaders(['Level', 'Error count']) | ||
->setRows($tableRows) | ||
// align right | ||
->setStyle($tableStyle) | ||
->render(); | ||
} | ||
} |
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 TomasVotruba\PHPStanBodyscan\ValueObject; | ||
|
||
final readonly class BodyscanResult | ||
{ | ||
/** | ||
* @param LevelResult[] $levelResults | ||
*/ | ||
public function __construct( | ||
private array $levelResults, | ||
) { | ||
} | ||
|
||
/** | ||
* @return LevelResult[] | ||
*/ | ||
public function getLevelResults(): array | ||
{ | ||
return $this->levelResults; | ||
} | ||
} |
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