Completed
Push — develop ( 095a7f...8813d8 )
by Tom
03:54
created

BaseUrlListCommand::execute()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 25
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 16
nc 4
nop 2
1
<?php
2
3
namespace N98\Magento\Command\System\Store\Config;
4
5
use N98\Magento\Command\AbstractMagentoCommand;
6
use N98\Util\Console\Helper\Table\Renderer\RendererFactory;
7
use N98\Util\Console\Helper\TableHelper;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Input\InputOption;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
class BaseUrlListCommand extends AbstractMagentoCommand
13
{
14 View Code Duplication
    protected function configure()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
15
    {
16
        $this
17
            ->setName('sys:store:config:base-url:list')
18
            ->setDescription('Lists all base urls')
19
            ->addOption(
20
                'format',
21
                null,
22
                InputOption::VALUE_OPTIONAL,
23
                'Output Format. One of [' . implode(',', RendererFactory::getFormats()) . ']'
24
            )
25
        ;
26
    }
27
28
    /**
29
     * @param InputInterface  $input
30
     * @param OutputInterface $output
31
     *
32
     * @return int|void
33
     */
34
    protected function execute(InputInterface $input, OutputInterface $output)
35
    {
36
        $this->detectMagento($output, true);
37
38
        if (!$input->getOption('format')) {
39
            $this->writeSection($output, 'Magento Stores - Base URLs');
40
        }
41
        $this->initMagento();
42
43
        foreach (\Mage::app()->getStores() as $store) {
44
            $table[$store->getId()] = array(
0 ignored issues
show
Coding Style Comprehensibility introduced by
$table was never initialized. Although not strictly required by PHP, it is generally a good practice to add $table = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
45
                $store->getId(),
46
                $store->getCode(),
47
                \Mage::getStoreConfig('web/unsecure/base_url', $store),
48
                \Mage::getStoreConfig('web/secure/base_url', $store),
49
            );
50
        }
51
52
        ksort($table);
53
        /* @var $tableHelper TableHelper */
54
        $tableHelper = $this->getHelper('table');
55
        $tableHelper
56
            ->setHeaders(array('id', 'code', 'unsecure_baseurl', 'secure_baseurl'))
57
            ->renderByFormat($output, $table, $input->getOption('format'));
58
    }
59
}
60