Key   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 6.25 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 3
loc 48
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 14 1
A execute() 3 23 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace LimeSoda\Ess\M2ePro\License;
4
5
use N98\Magento\Command\AbstractMagentoCommand;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
class Key extends AbstractMagentoCommand
11
{
12
    const EXTENSION_NAME = 'Ess_M2ePro';
13
    
14
    protected function configure()
15
    {
16
      $this
17
          ->setName('ls:ess:m2epro:license:key')
18
          ->addArgument('key', InputArgument::REQUIRED, 'Ess_M2ePro license key')
19
          ->setDescription('Set the Ess_M2ePro license key')
20
          ->setHelp(
21
              <<<EOT
22
              Sets the license key for Ess_M2ePro. The extension has to be installed and enabled.
23
EOT
24
              );
25
          
26
      ;
27
    }
28
29
   /**
30
    * @param \Symfony\Component\Console\Input\InputInterface $input
31
    * @param \Symfony\Component\Console\Output\OutputInterface $output
32
    * @return int|void
33
    */
34
    protected function execute(InputInterface $input, OutputInterface $output)
35
    {
36
        $this->detectMagento($output);
37
        if ($this->initMagento()) {
38 View Code Duplication
            if (\Mage::helper('core')->isModuleEnabled(self::EXTENSION_NAME) === false) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
39
                throw new \Exception("Extension '" . self::EXTENSION_NAME ."' is not installed.");
40
            }
41
42
            $key = strip_tags($input->getArgument('key'));
43
44
            \Mage::helper('M2ePro/Primary')->getConfig()->setGroupValue(
45
                '/'.\Mage::helper('M2ePro/Module')->getName().'/license/', 'key',(string)$key
46
            );
47
48
            \Mage::getModel('M2ePro/Servicing_Dispatcher')->processTasks(
49
                array(\Mage::getModel('M2ePro/Servicing_Task_License')->getPublicNick())
50
            );
51
52
            \Mage::helper('M2ePro/data_cache')->removeValue('M2ePro/Config_Primary_data');
53
54
            $output->writeln("Set license key '" . $key . "'.");
55
        }
56
    }
57
}
58