diff --git a/src/N98/Magento/Command/AbstractMagentoCommand.php b/src/N98/Magento/Command/AbstractMagentoCommand.php index 610d87f1e..e6048019a 100644 --- a/src/N98/Magento/Command/AbstractMagentoCommand.php +++ b/src/N98/Magento/Command/AbstractMagentoCommand.php @@ -112,7 +112,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int if ($this instanceof CommandFormatable) { $this->detectMagento($output, static::$detectMagentoSilent); - if ($input->getOption(static::COMMAND_OPTION_FORMAT) === null) { + $formatOption = $input->getOption(static::COMMAND_OPTION_FORMAT); + + if ($formatOption === null) { $this->writeSection($output, $this->getSectionTitle($input, $output)); } @@ -120,9 +122,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int return Command::FAILURE; } + $data = $this->getListData($input, $output); + if ($formatOption === null && $data === []) { + $output->writeln(sprintf( + 'No entry found for "%s" ', + $this->getSectionTitle($input, $output)) + ); + } + $this->getTableHelper() ->setHeaders($this->getListHeader($input, $output)) - ->renderByFormat($output, $this->getListData($input, $output), $input->getOption(self::COMMAND_OPTION_FORMAT)); + ->renderByFormat($output, $data, $input->getOption(self::COMMAND_OPTION_FORMAT)); return Command::SUCCESS; } diff --git a/src/N98/Magento/Command/Admin/User/ListCommand.php b/src/N98/Magento/Command/Admin/User/ListCommand.php index 296269caf..27c0a4e69 100644 --- a/src/N98/Magento/Command/Admin/User/ListCommand.php +++ b/src/N98/Magento/Command/Admin/User/ListCommand.php @@ -47,10 +47,10 @@ public function getListHeader(InputInterface $input, OutputInterface $output): a */ public function getListData(InputInterface $input, OutputInterface $output): array { - /** @var Mage_Admin_Model_User $userModel */ $userModel = $this->getUserModel(); $userList = $userModel->getCollection(); $table = []; + /** @var Mage_Admin_Model_User $user */ foreach ($userList as $user) { $table[] = [ $user->getId(), diff --git a/src/N98/Magento/Command/System/Store/ListCommand.php b/src/N98/Magento/Command/System/Store/ListCommand.php index f85affabf..124f6c943 100644 --- a/src/N98/Magento/Command/System/Store/ListCommand.php +++ b/src/N98/Magento/Command/System/Store/ListCommand.php @@ -10,6 +10,8 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use function ksort; + /** * List stores command * @@ -50,7 +52,11 @@ public function getListData(InputInterface $input, OutputInterface $output): arr { $table = []; foreach (Mage::app()->getStores() as $store) { - $table[$store->getId()] = [$store->getId(), $store->getCode()]; + $storeId = $store->getId(); + $table[$storeId] = [ + $storeId, + $store->getCode() + ]; } ksort($table); diff --git a/src/N98/Magento/Command/System/Website/ListCommand.php b/src/N98/Magento/Command/System/Website/ListCommand.php index 21e092a9c..8ed16cdd4 100644 --- a/src/N98/Magento/Command/System/Website/ListCommand.php +++ b/src/N98/Magento/Command/System/Website/ListCommand.php @@ -10,6 +10,8 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use function ksort; + /** * List websites command * @@ -49,10 +51,11 @@ public function getListHeader(InputInterface $input, OutputInterface $output): a public function getListData(InputInterface $input, OutputInterface $output): array { $table = []; - foreach (Mage::app()->getWebsites() as $store) { - $table[$store->getId()] = [ - $store->getId(), - $store->getCode() + foreach (Mage::app()->getWebsites() as $website) { + $websiteId = $website->getId(); + $table[$websiteId] = [ + $websiteId, + $website->getCode() ]; }