From 5075731d2ec8862886c14cb87a1ba0b98bf28953 Mon Sep 17 00:00:00 2001 From: Jose Ortega Date: Tue, 23 May 2023 11:34:14 +0200 Subject: [PATCH] #100331 CR fixes - Added int value to return statements - Added disableNodeIdAddend to validator (to avoid using invalid node IDs) - Taken array_merge outside of the loop --- Console/Command/NodesValidatorCommand.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Console/Command/NodesValidatorCommand.php b/Console/Command/NodesValidatorCommand.php index 746b399f..04eab353 100644 --- a/Console/Command/NodesValidatorCommand.php +++ b/Console/Command/NodesValidatorCommand.php @@ -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; @@ -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, @@ -41,6 +43,7 @@ public function __construct( Validator $validator, ValidationAggregateError $validationAggregateError, State $state, + TreeTrace $treeTrace, string $name = null ) { $this->menuRepository = $menuRepository; @@ -49,6 +52,7 @@ public function __construct( $this->validator = $validator; $this->validationAggregateError = $validationAggregateError; $this->state = $state; + $this->treeTrace = $treeTrace; parent::__construct($name); } @@ -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 . '... Validating nodes for menu with ID: ' . $menu->getMenuId(). ' '); @@ -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 . 'Invalid nodes were NOT removed'); - return; + return 0; } $this->displayResults( @@ -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;