ChangeVersionCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 3
c 2
b 1
f 1
lcom 1
cbo 2
dl 0
loc 52
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 12 1
B execute() 0 28 2
1
<?php
2
3
namespace N98\Magento\Command\System\Setup;
4
5
use Symfony\Component\Console\Input\InputArgument;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
9
class ChangeVersionCommand extends AbstractSetupCommand
10
{
11
    /**
12
     * Setup
13
     */
14
    protected function configure()
15
    {
16
        $this
17
            ->setName('sys:setup:change-version')
18
            ->addArgument('module', InputArgument::REQUIRED, 'Module name')
19
            ->addArgument('version', InputArgument::REQUIRED, 'New version value')
20
            ->setDescription('Change module resource version');
21
        $help = <<<HELP
22
Change a module's resource version
23
HELP;
24
        $this->setHelp($help);
25
    }
26
27
    /**
28
     * @param InputInterface $input
29
     * @param OutputInterface $output
30
     * @return int|null|void
31
     */
32
    protected function execute(InputInterface $input, OutputInterface $output)
33
    {
34
        $this->detectMagento($output, true);
35
36
        if (!$this->initMagento()) {
37
            return;
38
        }
39
40
        $moduleVersion = $input->getArgument('version');
41
        $moduleName    = $this->getMagentoModuleName($input->getArgument('module'));
42
43
        /** @var \Magento\Framework\Module\ResourceInterface $resource */
44
        $resource = $this->getMagentoModuleResource();
45
46
        $originalVersion = $resource->getDbVersion($moduleName);
47
48
        $resource->setDbVersion($moduleName, $moduleVersion);
49
        $resource->setDataVersion($moduleName, $moduleVersion);
50
51
        $output->writeln(
52
            sprintf(
53
                '<info>Successfully updated: "%s" from version "%s" to version: "%s"</info>',
54
                $moduleName,
55
                $originalVersion,
56
                $moduleVersion
57
            )
58
        );
59
    }
60
}
61