Skip to content

Commit

Permalink
fix static
Browse files Browse the repository at this point in the history
  • Loading branch information
engcom-Charlie committed Jul 30, 2020
1 parent 46f74af commit 1d81ca2
Showing 1 changed file with 47 additions and 24 deletions.
71 changes: 47 additions & 24 deletions setup/src/Magento/Setup/Console/Command/ModuleStatusCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,25 @@

namespace Magento\Setup\Console\Command;

use Magento\Framework\Console\Cli;
use Magento\Framework\Module\FullModuleList;
use Magento\Framework\Module\ModuleList;
use Magento\Setup\Model\ObjectManagerProvider;
use Magento\Framework\Console\Cli;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;

/**
* Command for displaying status of modules
*/
class ModuleStatusCommand extends AbstractSetupCommand
{
/**
* Object manager provider
*
* @var ObjectManagerProvider
*/
private $objectManagerProvider;

/**
* Inject dependencies
*
* @param ObjectManagerProvider $objectManagerProvider
*/
public function __construct(ObjectManagerProvider $objectManagerProvider)
Expand All @@ -40,28 +36,33 @@ public function __construct(ObjectManagerProvider $objectManagerProvider)
}

/**
* {@inheritdoc}
* @inheritdoc
*/
protected function configure()
{
$this->setName('module:status')
->setDescription('Displays status of modules')
->addArgument('module-names', InputArgument::OPTIONAL | InputArgument::IS_ARRAY , 'Optional module name')
->addArgument(
'module-names',
InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
'Optional module name'
)
->addOption('enabled', null, null, 'Print only enabled modules')
->addOption('disabled', null, null, 'Print only disabled modules');
parent::configure();
}

/**
* {@inheritdoc}
* @inheritdoc
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$moduleNames = $input->getArgument('module-names');
if (!empty($moduleNames)) {
foreach($moduleNames as $moduleName)
foreach ($moduleNames as $moduleName) {
$this->showSpecificModule($moduleName, $output);
return;
}
return 0;
}

$onlyEnabled = $input->getOption('enabled');
Expand All @@ -81,34 +82,42 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln("<info>List of disabled modules:</info>");
$this->showDisabledModules($output);
$output->writeln('');

return 0;
}

/**
* Specific module show
*
* @param string $moduleName
* @param OutputInterface $output
* @return int
*/
private function showSpecificModule(string $moduleName, OutputInterface $output)
private function showSpecificModule(string $moduleName, OutputInterface $output): int
{
$allModules = $this->getAllModules();
if (!in_array($moduleName, $allModules->getNames())) {
$output->writeln($moduleName.' : <error>Module does not exist</error>');
if (!in_array($moduleName, $allModules->getNames(), true)) {
$output->writeln($moduleName . ' : <error>Module does not exist</error>');
return Cli::RETURN_FAILURE;
}

$enabledModules = $this->getEnabledModules();
if (in_array($moduleName, $enabledModules->getNames())) {
$output->writeln($moduleName.' : <info>Module is enabled</info>');
if (in_array($moduleName, $enabledModules->getNames(), true)) {
$output->writeln($moduleName . ' : <info>Module is enabled</info>');
return Cli::RETURN_FAILURE;
}

$output->writeln($moduleName.' : <info> Module is disabled</info>');
return \Magento\Framework\Console\Cli::RETURN_SUCCESS;
$output->writeln($moduleName . ' : <info> Module is disabled</info>');
return Cli::RETURN_SUCCESS;
}

/**
* Enable modules show
*
* @param OutputInterface $output
* @return int
*/
private function showEnabledModules(OutputInterface $output)
private function showEnabledModules(OutputInterface $output): int
{
$enabledModules = $this->getEnabledModules();
$enabledModuleNames = $enabledModules->getNames();
Expand All @@ -118,13 +127,17 @@ private function showEnabledModules(OutputInterface $output)
}

$output->writeln(join("\n", $enabledModuleNames));
return \Magento\Framework\Console\Cli::RETURN_SUCCESS;

return Cli::RETURN_SUCCESS;
}

/**
* Disabled modules show
*
* @param OutputInterface $output
* @return int
*/
private function showDisabledModules(OutputInterface $output)
private function showDisabledModules(OutputInterface $output): int
{
$disabledModuleNames = $this->getDisabledModuleNames();
if (count($disabledModuleNames) === 0) {
Expand All @@ -133,32 +146,42 @@ private function showDisabledModules(OutputInterface $output)
}

$output->writeln(join("\n", $disabledModuleNames));
return \Magento\Framework\Console\Cli::RETURN_SUCCESS;

return Cli::RETURN_SUCCESS;
}

/**
* Returns all modules
*
* @return FullModuleList
*/
private function getAllModules(): FullModuleList
{
return $this->objectManagerProvider->get()->create(FullModuleList::class);
return $this->objectManagerProvider->get()
->create(FullModuleList::class);
}

/**
* Returns enabled modules
*
* @return ModuleList
*/
private function getEnabledModules(): ModuleList
{
return $this->objectManagerProvider->get()->create(ModuleList::class);
return $this->objectManagerProvider->get()
->create(ModuleList::class);
}

/**
* Returns disabled module names
*
* @return array
*/
private function getDisabledModuleNames(): array
{
$fullModuleList = $this->getAllModules();
$enabledModules = $this->getEnabledModules();

return array_diff($fullModuleList->getNames(), $enabledModules->getNames());
}
}

0 comments on commit 1d81ca2

Please sign in to comment.