Completed
Pull Request — develop (#167)
by Robbie
05:20
created

AbstractSetupCommand::getMagentoModuleName()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
dl 0
loc 11
rs 9.4286
c 2
b 0
f 1
cc 3
eloc 6
nc 3
nop 1
1
<?php
2
3
namespace N98\Magento\Command\System\Setup;
4
5
use N98\Magento\Command\AbstractMagentoCommand;
6
use Magento\Framework\Module\ModuleListInterface;
7
use Magento\Framework\Module\ResourceInterface;
8
9
/**
10
 * Class AbstractSetupCommand
11
 * @package N98\Magento\Command\System\Setup
12
 */
13
abstract class AbstractSetupCommand extends AbstractMagentoCommand
14
{
15
    /**
16
     * @var ModuleListInterface
17
     */
18
    protected $moduleList;
19
20
    /**
21
     * @var ResourceInterface
22
     */
23
    protected $resource;
24
25
    /**
26
     * Determine if a module exists. If it does, return the actual module name (not lowercased).
27
     * @param  string $requestedModuleName
28
     * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be integer|string?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
29
     * @throws \InvalidArgumentException When the module doesn't exist
30
     */
31
    public function getMagentoModuleName($requestedModuleName)
32
    {
33
        $lowercaseModuleName = strtolower($requestedModuleName);
34
        foreach ($this->getMagentoModuleList()->getAll() as $moduleName => $moduleInfo) {
35
            if ($lowercaseModuleName === strtolower($moduleName)) {
36
                return $moduleName;
37
            }
38
        }
39
        
40
        throw new \InvalidArgumentException(sprintf('Module does not exist: "%s"', $requestedModuleName));
41
    }
42
43
    /**
44
     * @return ModuleListInterface
45
     */
46
    public function getMagentoModuleList()
47
    {
48
        if (is_null($this->moduleList)) {
49
            $this->moduleList = $this->getObjectManager()->get('Magento\Framework\Module\ModuleListInterface');
50
        }
51
        return $this->moduleList;
52
    }
53
54
    /**
55
     * @return ResourceInterface
56
     */
57
    public function getMagentoModuleResource()
58
    {
59
        if (is_null($this->resource)) {
60
            $this->resource = $this->getObjectManager()->get('Magento\Framework\Module\ResourceInterface');
61
        }
62
        return $this->resource;
63
    }
64
}
65