Completed
Push — develop ( 73bd0a...ccb498 )
by Tom
05:04
created

BaseUrlListCommand::execute()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 23
rs 9.0856
cc 3
eloc 15
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 Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Input\InputOption;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
class BaseUrlListCommand extends AbstractMagentoCommand
12
{
13
    /**
14
     * @var \Magento\Framework\Store\StoreManagerInterface
15
     */
16
    protected $storeManager;
17
18
    protected function configure()
19
    {
20
        $this
21
            ->setName('sys:store:config:base-url:list')
22
            ->setDescription('Lists all base urls')
23
            ->addOption(
24
                'format',
25
                null,
26
                InputOption::VALUE_OPTIONAL,
27
                'Output Format. One of [' . implode(',', RendererFactory::getFormats()) . ']'
28
            )
29
        ;
30
    }
31
32
    /**
33
     * @param \Magento\Store\Model\StoreManagerInterface $storeManager
34
     */
35
    public function inject(\Magento\Store\Model\StoreManagerInterface $storeManager)
36
    {
37
        $this->storeManager = $storeManager;
0 ignored issues
show
Documentation Bug introduced by
It seems like $storeManager of type object<Magento\Store\Model\StoreManagerInterface> is incompatible with the declared type object<Magento\Framework...\StoreManagerInterface> of property $storeManager.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
38
    }
39
40
    /**
41
     * @param InputInterface $input
42
     * @param OutputInterface $output
43
     * @return void
44
     */
45
    protected function execute(InputInterface $input, OutputInterface $output)
46
    {
47
        $this->detectMagento($output, true);
48
49
        if (!$input->getOption('format')) {
50
            $this->writeSection($output, 'Magento Stores - Base URLs');
51
        }
52
        $this->initMagento();
53
54
        foreach ($this->storeManager->getStores() as $store) {
55
            $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...
56
                $store->getId(),
57
                $store->getCode(),
58
                $store->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB),
59
                $store->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB, true),
60
            );
61
        }
62
63
        ksort($table);
64
        $this->getHelper('table')
65
            ->setHeaders(array('id', 'code', 'unsecure_baseurl', 'secure_baseurl'))
66
            ->renderByFormat($output, $table, $input->getOption('format'));
67
    }
68
}
69