From 6faf4339c50826c3f627b2adb06fc8277197009a Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Mon, 16 Dec 2024 02:20:08 +0100 Subject: [PATCH] last fixes --- src/N98/Magento/Command/AbstractMagentoCommand.php | 2 +- .../Developer/Module/Dependencies/OnCommand.php | 2 +- .../Command/System/Setup/AbstractSetupCommand.php | 11 ++++++----- src/N98/Magento/Command/System/Url/ListCommand.php | 4 ++-- src/N98/Magento/DbSettings.php | 11 +++++++++-- src/N98/Magento/Initialiser.php | 4 +++- src/N98/Util/Console/Helper/DatabaseHelper.php | 6 +++--- .../Console/Helper/Table/Renderer/RendererFactory.php | 4 ++-- 8 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/N98/Magento/Command/AbstractMagentoCommand.php b/src/N98/Magento/Command/AbstractMagentoCommand.php index f1a1a6b6c..0b10eb789 100644 --- a/src/N98/Magento/Command/AbstractMagentoCommand.php +++ b/src/N98/Magento/Command/AbstractMagentoCommand.php @@ -442,7 +442,7 @@ protected function isSourceTypeRepository(string $type): bool return in_array($type, ['git', 'hg']); } - protected function getOrAskForArgument(string $argument, InputInterface $input, OutputInterface $output, ?string $message = null): string + protected function getOrAskForArgument(string $argument, InputInterface $input, OutputInterface $output, ?string $message = null): ?string { $inputArgument = $input->getArgument($argument); if ($inputArgument === null) { diff --git a/src/N98/Magento/Command/Developer/Module/Dependencies/OnCommand.php b/src/N98/Magento/Command/Developer/Module/Dependencies/OnCommand.php index 1cceab964..690264862 100644 --- a/src/N98/Magento/Command/Developer/Module/Dependencies/OnCommand.php +++ b/src/N98/Magento/Command/Developer/Module/Dependencies/OnCommand.php @@ -21,7 +21,7 @@ */ class OnCommand extends AbstractMagentoCommand { - private ?array $modules; + private ?array $modules = null; protected function configure(): void { diff --git a/src/N98/Magento/Command/System/Setup/AbstractSetupCommand.php b/src/N98/Magento/Command/System/Setup/AbstractSetupCommand.php index f1154f0b4..f142223de 100644 --- a/src/N98/Magento/Command/System/Setup/AbstractSetupCommand.php +++ b/src/N98/Magento/Command/System/Setup/AbstractSetupCommand.php @@ -43,13 +43,14 @@ public function getModule(InputInterface $input): string { $config = Mage::app()->getConfig(); - /** @var Mage_Core_Model_Config_Element $modules */ $modules = $config->getNode('modules'); - foreach ($modules->asArray() as $moduleName => $data) { - if (strtolower($moduleName) === strtolower($input->getArgument('module'))) { - return $moduleName; + if ($modules) { + foreach ($modules->asArray() as $moduleName => $data) { + if (strtolower($moduleName) === strtolower($input->getArgument('module'))) { + return $moduleName; + } } - } + } throw new InvalidArgumentException(sprintf('No module found with name: "%s"', $input->getArgument('module'))); } diff --git a/src/N98/Magento/Command/System/Url/ListCommand.php b/src/N98/Magento/Command/System/Url/ListCommand.php index 8ca16e7bf..b65bd57d8 100644 --- a/src/N98/Magento/Command/System/Url/ListCommand.php +++ b/src/N98/Magento/Command/System/Url/ListCommand.php @@ -83,12 +83,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int $input->setOption('add-cmspages', true); } - $stores = explode(',', $input->getArgument('stores') ?? ''); + $stores = explode(',', (string) $input->getArgument('stores') ?? ''); $urls = []; + /** @var Mage_Core_Model_Store $currentStore */ foreach ($stores as $store) { - /** @var Mage_Core_Model_Store $currentStore */ $currentStore = Mage::app()->getStore($store); // base url diff --git a/src/N98/Magento/DbSettings.php b/src/N98/Magento/DbSettings.php index d5ca5029c..8e2235dbe 100644 --- a/src/N98/Magento/DbSettings.php +++ b/src/N98/Magento/DbSettings.php @@ -103,11 +103,18 @@ public function setFile(string $file): void private function parseResources(SimpleXMLElement $resources): void { // default values - $config = ['host' => null, 'port' => null, 'unix_socket' => null, 'dbname' => null, 'username' => null, 'password' => null]; + $config = [ + 'host' => null, + 'port' => null, + 'unix_socket' => null, + 'dbname' => null, + 'username' => null, + 'password' => null, + ]; $connectionNode = $this->connectionNode; /** @var string[] $config */ - $config = array_merge($config, (array) $resources->$connectionNode->connection); + $config = array_merge($config, array_map('strval', (array) $resources->$connectionNode->connection)); $config['prefix'] = (string) $resources->db->table_prefix; // known parameters: host, port, unix_socket, dbname, username, password, options, charset, persistent, diff --git a/src/N98/Magento/Initialiser.php b/src/N98/Magento/Initialiser.php index f97a08b65..def531b66 100644 --- a/src/N98/Magento/Initialiser.php +++ b/src/N98/Magento/Initialiser.php @@ -67,7 +67,9 @@ public function requireMage(): void $this->requireOnce(); - throw new RuntimeException(sprintf('Failed to load definition of "%s" class', self::CLASS_MAGE)); + if (!class_exists(self::CLASS_MAGE, false)) { + throw new RuntimeException(sprintf('Failed to load definition of "%s" class', self::CLASS_MAGE)); + } } /** diff --git a/src/N98/Util/Console/Helper/DatabaseHelper.php b/src/N98/Util/Console/Helper/DatabaseHelper.php index 1d229dd82..8a1ed6d7d 100644 --- a/src/N98/Util/Console/Helper/DatabaseHelper.php +++ b/src/N98/Util/Console/Helper/DatabaseHelper.php @@ -22,16 +22,16 @@ */ class DatabaseHelper extends AbstractHelper { - protected ?DbSettings $dbSettings; + protected ?DbSettings $dbSettings = null; /** * @deprecated since 1.97.9, use $dbSettings->isSocketConnect() */ protected bool $isSocketConnect = false; - protected ?PDO $_connection; + protected ?PDO $_connection = null; - protected ?array $_tables; + protected ?array $_tables = null; public function detectDbSettings(OutputInterface $output, ?string $connectionNode = null): void { diff --git a/src/N98/Util/Console/Helper/Table/Renderer/RendererFactory.php b/src/N98/Util/Console/Helper/Table/Renderer/RendererFactory.php index 2e8d7ff58..ec4b90c0b 100644 --- a/src/N98/Util/Console/Helper/Table/Renderer/RendererFactory.php +++ b/src/N98/Util/Console/Helper/Table/Renderer/RendererFactory.php @@ -21,9 +21,9 @@ class RendererFactory 'xml' => XmlRenderer::class, ]; - public function create(string $format): ?RendererInterface + public function create(?string $format): ?RendererInterface { - $format = strtolower($format); + $format = is_null($format) ? $format : strtolower($format); if (isset(self::$formats[$format])) { $rendererClass = self::$formats[$format]; /** @var RendererInterface $renderer */