Skip to content

Commit

Permalink
Moved helpers to AbstractMagentoCommand (#1454)
Browse files Browse the repository at this point in the history
  • Loading branch information
sreichel authored Aug 5, 2024
1 parent ee28176 commit 9e55ff2
Show file tree
Hide file tree
Showing 68 changed files with 126 additions and 259 deletions.
38 changes: 31 additions & 7 deletions src/N98/Magento/Command/AbstractMagentoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
use N98\Magento\Application;
use N98\Magento\Command\SubCommand\ConfigBag;
use N98\Magento\Command\SubCommand\SubCommandFactory;
use N98\Util\Console\Helper\DatabaseHelper;
use N98\Util\Console\Helper\IoHelper;
use N98\Util\Console\Helper\MagentoHelper;
use N98\Util\Console\Helper\ParameterHelper;
use N98\Util\Console\Helper\Table\Renderer\RendererFactory;
use N98\Util\Console\Helper\TableHelper;
use N98\Util\OperatingSystem;
use N98\Util\StringTyped;
use RuntimeException;
Expand Down Expand Up @@ -554,8 +556,7 @@ protected function chooseInstallationFolder(InputInterface $input, OutputInterfa
if (($installationFolder = $input->getOption('installationFolder')) == null) {
$defaultFolder = './magento';

/* @var QuestionHelper $dialog */
$dialog = $this->getHelper('question');
$dialog = $this->getQuestionHelper();
$questionObj = new Question(
'<question>Enter installation folder:</question> [<comment>' . $defaultFolder . '</comment>]',
$defaultFolder
Expand Down Expand Up @@ -595,8 +596,7 @@ protected function getOrAskForArgument($argument, InputInterface $input, OutputI
if ($inputArgument === null) {
$message = $this->getArgumentMessage($argument, $message);

/* @var QuestionHelper $dialog */
$dialog = $this->getHelper('question');
$dialog = $this->getQuestionHelper();
return $dialog->ask($input, $output, new Question($message));
}

Expand All @@ -620,8 +620,7 @@ protected function askForArrayEntry(array $entries, InputInterface $input, Outpu
return $typeInput;
};

/* @var QuestionHelper $dialog */
$dialog = $this->getHelper('question');
$dialog = $this->getQuestionHelper();
$question = new ChoiceQuestion(
"<question>{$question}</question>",
$entries
Expand Down Expand Up @@ -683,7 +682,7 @@ protected function createSubCommandFactory(
*
* @return $this
*/
public function addFormatOption(): AbstractMagentoCommand
public function addFormatOption(): self
{
$this->addOption(
'format',
Expand All @@ -694,18 +693,43 @@ public function addFormatOption(): AbstractMagentoCommand
return $this;
}

/**
* @return DatabaseHelper
*/
public function getDatabaseHelper(): DatabaseHelper
{
return $this->getHelper('database');
}

/**
* @return IoHelper
*/
public function getIoHelper(): IoHelper
{
return $this->getHelper('io');
}

/**
* @return ParameterHelper
*/
public function getParameterHelper(): ParameterHelper
{
return $this->getHelper('parameter');
}

/**
* @return QuestionHelper
*/
public function getQuestionHelper(): QuestionHelper
{
return $this->getHelper('question');
}

/**
* @return TableHelper
*/
public function getTableHelper(): TableHelper
{
return $this->getHelper('table');
}
}
4 changes: 1 addition & 3 deletions src/N98/Magento/Command/Admin/User/ChangePasswordCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Exception;
use RuntimeException;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -40,8 +39,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 0;
}

/* @var QuestionHelper $dialog */
$dialog = $this->getHelper('question');
$dialog = $this->getQuestionHelper();

// Username
if (($username = $input->getArgument('username')) == null) {
Expand Down
3 changes: 1 addition & 2 deletions src/N98/Magento/Command/Admin/User/CreateUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$username = $this->getOrAskForArgument('username', $input, $output);
$email = $this->getOrAskForArgument('email', $input, $output);
if (($password = $input->getArgument('password')) === null) {
/* @var QuestionHelper $dialog */
$dialog = $this->getHelper('question');
$dialog = $this->getQuestionHelper();
$question = new Question('<question>Password:</question> ');
$question->setHidden(true);
$password = $dialog->ask($input, $output, $question);
Expand Down
3 changes: 1 addition & 2 deletions src/N98/Magento/Command/Admin/User/DeleteUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 0;
}

/* @var QuestionHelper $dialog */
$dialog = $this->getHelper('question');
$dialog = $this->getQuestionHelper();

// Username
$id = $this->getOrAskForArgument('id', $input, $output, 'Username or Email');
Expand Down
4 changes: 1 addition & 3 deletions src/N98/Magento/Command/Admin/User/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace N98\Magento\Command\Admin\User;

use N98\Util\Console\Helper\TableHelper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

Expand Down Expand Up @@ -43,8 +42,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$table[] = [$user->getId(), $user->getUsername(), $user->getEmail(), $user->getIsActive() ? 'active' : 'inactive'];
}

/* @var TableHelper $tableHelper */
$tableHelper = $this->getHelper('table');
$tableHelper = $this->getTableHelper();
$tableHelper
->setHeaders(['id', 'username', 'email', 'status'])
->renderByFormat($output, $table, $input->getOption('format'));
Expand Down
4 changes: 1 addition & 3 deletions src/N98/Magento/Command/Cache/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace N98\Magento\Command\Cache;

use N98\Util\Console\Helper\TableHelper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

Expand Down Expand Up @@ -40,8 +39,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$table[] = [$cacheCode, $cacheInfo['status'] ? 'enabled' : 'disabled'];
}

/* @var TableHelper $tableHelper */
$tableHelper = $this->getHelper('table');
$tableHelper = $this->getTableHelper();
$tableHelper
->setHeaders(['code', 'status'])
->renderByFormat($output, $table, $input->getOption('format'));
Expand Down
4 changes: 1 addition & 3 deletions src/N98/Magento/Command/Cache/ReportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Enterprise_PageCache_Model_Cache;
use Mage;
use N98\Util\Console\Helper\TableHelper;
use RuntimeException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand Down Expand Up @@ -98,8 +97,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$headers[] = 'TAGS';
}

/* @var TableHelper $tableHelper */
$tableHelper = $this->getHelper('table');
$tableHelper = $this->getTableHelper();
$tableHelper
->setHeaders($headers)
->renderByFormat($output, $table, $input->getOption('format'));
Expand Down
4 changes: 1 addition & 3 deletions src/N98/Magento/Command/Category/Create/DummyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Mage_Catalog_Model_Category;
use N98\Magento\Command\AbstractMagentoCommand;
use RuntimeException;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -138,8 +137,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
*/
private function askForArguments($input, $output)
{
/* @var QuestionHelper $dialog */
$dialog = $this->getHelper('question');
$dialog = $this->getQuestionHelper();
$_argument = [];

// Store ID
Expand Down
4 changes: 1 addition & 3 deletions src/N98/Magento/Command/Cms/Block/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace N98\Magento\Command\Cms\Block;

use N98\Magento\Command\AbstractMagentoCommand;
use N98\Util\Console\Helper\TableHelper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

Expand Down Expand Up @@ -63,8 +62,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$table[] = [$cmsBlock->getData('block_id'), $cmsBlock->getData('identifier'), $cmsBlock->getData('title'), $cmsBlock->getData('is_active') ? 'active' : 'inactive', $storeIds];
}

/* @var TableHelper $tableHelper */
$tableHelper = $this->getHelper('table');
$tableHelper = $this->getTableHelper();
$tableHelper
->setHeaders(['block_id', 'identifier', 'title', 'is_active', 'store_ids'])
->renderByFormat($output, $table, $input->getOption('format'));
Expand Down
4 changes: 1 addition & 3 deletions src/N98/Magento/Command/Config/DeleteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace N98\Magento\Command\Config;

use Mage;
use N98\Util\Console\Helper\TableHelper;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand Down Expand Up @@ -84,8 +83,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

if (count($deleted) > 0) {
/* @var TableHelper $tableHelper */
$tableHelper = $this->getHelper('table');
$tableHelper = $this->getTableHelper();
$tableHelper
->setHeaders(['Deleted Path', 'Scope', 'Scope-ID'])
->setRows($deleted)
Expand Down
4 changes: 1 addition & 3 deletions src/N98/Magento/Command/Config/GetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace N98\Magento\Command\Config;

use N98\Util\Console\Helper\TableHelper;
use Path;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -138,8 +137,7 @@ protected function renderAsTable(OutputInterface $output, $table, $format)
$formattedTable[] = [$row['path'], $row['scope'], $row['scope_id'], $this->renderTableValue($row['value'], $format)];
}

/* @var TableHelper $tableHelper */
$tableHelper = $this->getHelper('table');
$tableHelper = $this->getTableHelper();
$tableHelper
->setHeaders([Path::class, 'Scope', 'Scope-ID', 'Value'])
->setRows($formattedTable)
Expand Down
8 changes: 2 additions & 6 deletions src/N98/Magento/Command/Customer/ChangePasswordCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
namespace N98\Magento\Command\Customer;

use Exception;
use N98\Util\Console\Helper\ParameterHelper;
use RuntimeException;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -54,15 +52,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int

// Password
if (($password = $input->getArgument('password')) == null) {
/* @var QuestionHelper $dialog */
$dialog = $this->getHelper('question');
$dialog = $this->getQuestionHelper();
$question = new Question('<question>Password:</question> ');
$question->setHidden(true);
$password = $dialog->ask($input, $output, $question);
}

/** @var ParameterHelper $parameterHelper */
$parameterHelper = $this->getHelper('parameter');
$parameterHelper = $this->getParameterHelper();

$email = $parameterHelper->askEmail($input, $output);
$website = $parameterHelper->askWebsite($input, $output);
Expand Down
12 changes: 3 additions & 9 deletions src/N98/Magento/Command/Customer/CreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

namespace N98\Magento\Command\Customer;

use N98\Util\Console\Helper\ParameterHelper;
use N98\Util\Console\Helper\TableHelper;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -43,8 +40,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 0;
}

/* @var QuestionHelper $dialog */
$dialog = $this->getHelper('question');
$dialog = $this->getQuestionHelper();

// Password
if (($password = $input->getArgument('password')) == null) {
Expand All @@ -63,8 +59,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$lastname = $dialog->ask($input, $output, new Question('<question>Lastname:</question> '));
}

/** @var ParameterHelper $parameterHelper */
$parameterHelper = $this->getHelper('parameter');
$parameterHelper = $this->getParameterHelper();

// Email
$email = $parameterHelper->askEmail($input, $output);
Expand Down Expand Up @@ -102,8 +97,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

if (!$outputPlain) {
/* @var TableHelper $tableHelper */
$tableHelper = $this->getHelper('table');
$tableHelper = $this->getTableHelper();
$tableHelper
->setHeaders(['email', 'password', 'firstname', 'lastname'])
->renderByFormat($output, $table, $input->getOption('format'));
Expand Down
8 changes: 2 additions & 6 deletions src/N98/Magento/Command/Customer/CreateDummyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

use Faker\Factory;
use Locale;
use N98\Util\Console\Helper\ParameterHelper;
use N98\Util\Console\Helper\TableHelper;
use N98\Util\Faker\Provider\Internet;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -80,8 +78,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$faker = Factory::create($input->getArgument('locale'));
$faker->addProvider(new Internet($faker));

/** @var ParameterHelper $parameterHelper */
$parameterHelper = $this->getHelper('parameter');
$parameterHelper = $this->getParameterHelper();

$website = $parameterHelper->askWebsite($input, $output);

Expand Down Expand Up @@ -136,8 +133,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$res->commit();

if (!$outputPlain) {
/* @var TableHelper $tableHelper */
$tableHelper = $this->getHelper('table');
$tableHelper = $this->getTableHelper();
$tableHelper
->setHeaders(['email', 'password', 'firstname', 'lastname'])
->renderByFormat($output, $table, $input->getOption('format'));
Expand Down
6 changes: 2 additions & 4 deletions src/N98/Magento/Command/Customer/DeleteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Mage_Customer_Model_Customer;
use Mage_Customer_Model_Entity_Customer_Collection;
use Mage_Customer_Model_Resource_Customer_Collection;
use N98\Util\Console\Helper\ParameterHelper;
use RuntimeException;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputArgument;
Expand Down Expand Up @@ -209,8 +208,7 @@ protected function getCustomer($id)
/** @var \Mage_Customer_Model_Customer $customer */
$customer = $this->getCustomerModel()->load($id);
if (!$customer->getId()) {
/** @var ParameterHelper $parameterHelper */
$parameterHelper = $this->getHelper('parameter');
$parameterHelper = $this->getParameterHelper();
$website = $parameterHelper->askWebsite($this->input, $this->output);
$customer = $this->getCustomerModel()
->setWebsiteId($website->getId())
Expand Down Expand Up @@ -279,7 +277,7 @@ public function validateInt($answer)
* @param string $message
* @param string $default [optional]
*
* @return \Symfony\Component\Console\Question\Question
* @return Question
*/
private function getQuestion($message, $default = null)
{
Expand Down
Loading

0 comments on commit 9e55ff2

Please sign in to comment.