-
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.
* add --json to output data in json * add json output
- Loading branch information
1 parent
0eb9bd7
commit 37ad1e7
Showing
9 changed files
with
203 additions
and
40 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 was deleted.
Oops, something went wrong.
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,46 @@ | ||
<?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 = $this->createRawData($bodyscanResult); | ||
|
||
$jsonOutput = json_encode($rawData, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR); | ||
$this->symfonyStyle->writeln($jsonOutput); | ||
} | ||
|
||
/** | ||
* @return mixed[] | ||
*/ | ||
private function createRawData(BodyscanResult $bodyscanResult): array | ||
{ | ||
$rawData = []; | ||
|
||
foreach ($bodyscanResult->getLevelResults() as $levelResult) { | ||
$rawData[] = [ | ||
'level' => $levelResult->getLevel(), | ||
'error_count' => $levelResult->getErrorCount(), | ||
]; | ||
} | ||
|
||
return $rawData; | ||
} | ||
} |
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,49 @@ | ||
<?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 = $this->createRawData($bodyscanResult); | ||
|
||
$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(); | ||
} | ||
|
||
/** | ||
* @return mixed[] | ||
*/ | ||
private function createRawData(BodyscanResult $bodyscanResult): array | ||
{ | ||
$tableRows = []; | ||
foreach ($bodyscanResult->getLevelResults() as $levelResult) { | ||
$tableRows[] = [$levelResult->getLevel(), $levelResult->getErrorCount()]; | ||
} | ||
|
||
return $tableRows; | ||
} | ||
} |
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