|
|
@@ -4,7 +4,6 @@
|
|
|
|
|
|
namespace App\Commands\Doctrine;
|
|
|
|
|
|
-use App\Service\Doctrine\SchemaValidation\Difference;
|
|
|
use App\Service\Doctrine\SchemaValidation\DiffTypeEnum;
|
|
|
use App\Service\Doctrine\SchemaValidation\SchemaSnippetsMaker;
|
|
|
use App\Service\Doctrine\SchemaValidation\SchemaValidationService;
|
|
|
@@ -27,7 +26,7 @@ class SchemaValidateCommand extends Command
|
|
|
{
|
|
|
public function __construct(
|
|
|
private readonly SchemaValidationService $schemaValidationService,
|
|
|
- private readonly SchemaSnippetsMaker $schemaSnippetsMaker
|
|
|
+ private readonly SchemaSnippetsMaker $schemaSnippetsMaker,
|
|
|
) {
|
|
|
parent::__construct();
|
|
|
}
|
|
|
@@ -43,12 +42,6 @@ class SchemaValidateCommand extends Command
|
|
|
InputOption::VALUE_OPTIONAL,
|
|
|
"Filter the type of difference to display (ex: 'MISSING_PROPERTY')."
|
|
|
);
|
|
|
- $this->addOption(
|
|
|
- 'csv',
|
|
|
- null,
|
|
|
- InputOption::VALUE_NONE,
|
|
|
- "Print the result in CSV format."
|
|
|
- );
|
|
|
$this->addOption(
|
|
|
'snippets',
|
|
|
null,
|
|
|
@@ -63,29 +56,19 @@ class SchemaValidateCommand extends Command
|
|
|
|
|
|
$diff = $this->schemaValidationService->validateSchema($filter);
|
|
|
|
|
|
- foreach ($diff as $entity => $value) {
|
|
|
- if (empty($value)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
+ $csv = $this->schemaValidationService->formatToCsv($diff);
|
|
|
|
|
|
- if ($input->getOption('csv')) {
|
|
|
- $this->printCsv($output, $entity, $value);
|
|
|
- } else {
|
|
|
- $this->printVerbose($output, $entity, $value);
|
|
|
- }
|
|
|
+ if (empty($csv)) {
|
|
|
+ $output->writeln("No difference found");
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
- if ($diff) {
|
|
|
- $count = 0;
|
|
|
- foreach ($diff as $entity => $value) {
|
|
|
- $count += (is_array($value) ? count($value) : 1);
|
|
|
- }
|
|
|
-
|
|
|
- $output->writeln($count . " differences found");
|
|
|
- } else {
|
|
|
- $output->writeln("No difference found");
|
|
|
+ foreach ($csv as $line) {
|
|
|
+ $output->writeln($line);
|
|
|
}
|
|
|
|
|
|
+ $output->writeln(count($csv) . " differences found");
|
|
|
+
|
|
|
if ($input->getOption('snippets')) {
|
|
|
$this->schemaSnippetsMaker->makeSnippets($diff);
|
|
|
$output->writeln("Snippets generated");
|
|
|
@@ -93,40 +76,4 @@ class SchemaValidateCommand extends Command
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * @param OutputInterface $output
|
|
|
- * @param string $entity
|
|
|
- * @param Difference|array<Difference> $differences
|
|
|
- * @return void
|
|
|
- */
|
|
|
- protected function printVerbose(OutputInterface $output, string $entity, Difference | array $differences): void {
|
|
|
- $output->writeln($entity);
|
|
|
-
|
|
|
- if (!is_array($differences)) {
|
|
|
- $output->writeln($differences->getType()->value . " : " . $differences->getMessage());
|
|
|
- } else {
|
|
|
- foreach ($differences as $field => $difference) {
|
|
|
- $output->writeln(" * " . $field . " - " . $difference->getType()->value . " : " . $difference->getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- $output->writeln("\n");
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @param OutputInterface $output
|
|
|
- * @param string $entity
|
|
|
- * @param Difference|array<Difference> $differences
|
|
|
- * @return void
|
|
|
- */
|
|
|
- protected function printCsv(OutputInterface $output, string $entity, Difference | array $differences): void {
|
|
|
- if (!is_array($differences)) {
|
|
|
- $output->writeln(implode(';', [$entity, '', $differences->getType()->value]));
|
|
|
- } else {
|
|
|
- foreach ($differences as $field => $difference) {
|
|
|
- $output->writeln(implode(';', [$entity, $field, $difference->getType()->value]));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
}
|