Skip to content

Commit

Permalink
#100331 CR fixes
Browse files Browse the repository at this point in the history
- Added int value to return statements
- Added disableNodeIdAddend to validator (to avoid using invalid node IDs)
- Taken array_merge outside of the loop
  • Loading branch information
Jose Ortega committed May 23, 2023
1 parent a508e5f commit 5075731
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions Console/Command/NodesValidatorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Snowdog\Menu\Api\MenuRepositoryInterface;
use Snowdog\Menu\Api\NodeRepositoryInterface;
use Snowdog\Menu\Model\ImportExport\Processor\Import\Node\Validator;
use Snowdog\Menu\Model\ImportExport\Processor\Import\Node\Validator\TreeTrace;
use Snowdog\Menu\Model\ImportExport\Processor\Import\Validator\ValidationAggregateError;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -33,6 +34,7 @@ class NodesValidatorCommand extends Command
private Validator $validator;
private ValidationAggregateError $validationAggregateError;
private State $state;
private TreeTrace $treeTrace;

public function __construct(
MenuRepositoryInterface $menuRepository,
Expand All @@ -41,6 +43,7 @@ public function __construct(
Validator $validator,
ValidationAggregateError $validationAggregateError,
State $state,
TreeTrace $treeTrace,
string $name = null
) {
$this->menuRepository = $menuRepository;
Expand All @@ -49,6 +52,7 @@ public function __construct(
$this->validator = $validator;
$this->validationAggregateError = $validationAggregateError;
$this->state = $state;
$this->treeTrace = $treeTrace;

parent::__construct($name);
}
Expand All @@ -72,6 +76,7 @@ public function execute(InputInterface $input, OutputInterface $output)
{
$this->setAreaCode();
$invalidNodeIds = [];
$this->treeTrace->disableNodeIdAddend();

foreach ($this->getAllMenus() as $menu) {
$output->writeln(PHP_EOL . '<info>... Validating nodes for menu with ID: ' . $menu->getMenuId(). ' </info>');
Expand All @@ -93,18 +98,19 @@ public function execute(InputInterface $input, OutputInterface $output)
}
}

$invalidNodeIds = array_merge($invalidNodeIds, array_keys($menuInvalidNodes));
$invalidNodeIds[] = array_keys($menuInvalidNodes);
}

if (empty($invalidNodeIds) || !$input->isInteractive()) {
return;
return 0;
}

$invalidNodeIds = array_merge([], ...$invalidNodeIds);
$helper = $this->getHelper('question');

if (!$helper->ask($input, $output, $this->getConfirmationQuestion())) {
$output->writeln(PHP_EOL . '<info>Invalid nodes were NOT removed</info>');
return;
return 0;
}

$this->displayResults(
Expand Down Expand Up @@ -140,7 +146,10 @@ private function getInvalidNodes(array $nodes): array

/** @var NodeInterface $node */
foreach ($nodes as $node) {
$this->validator->validate([$node->getNodeId() => $node->getData()]);
$this->validator->validate(
[$node->getNodeId() => $node->getData()],
$this->treeTrace
);

if (empty($this->validationAggregateError->getErrors())) {
continue;
Expand Down

0 comments on commit 5075731

Please sign in to comment.