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

validateArea()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
/**
3
 * netz98 magento module
4
 *
5
 * LICENSE
6
 *
7
 * This source file is subject of netz98.
8
 * You may be not allowed to change the sources
9
 * without authorization of netz98 new media GmbH.
10
 *
11
 * @copyright  Copyright (c) 1999-2016 netz98 new media GmbH (http://www.netz98.de)
12
 * @author netz98 new media GmbH <[email protected]>
13
 * @category N98
14
 * @package N98\Magento\Command\Developer\Console
15
 */
16
17
namespace N98\Magento\Command\Developer\Console\Config;
18
19
use Magento\Framework\App\AreaList;
20
use N98\Magento\Command\Developer\Console\AbstractGeneratorCommand;
21
22
abstract class AbstractSimpleConfigFileGeneratorCommand extends AbstractGeneratorCommand
23
{
24
    /**
25
     * @param string $configFileName
26
     * @param string $area
27
     * @return string
28
     */
29
    protected function getRelativeConfigFilePath($configFileName, $area = 'global')
30
    {
31
        if ($area == 'global') {
32
            $relativeConfigFilePath = 'etc/' . $configFileName;
33
        } else {
34
            $this->validateArea($area);
35
            $relativeConfigFilePath = 'etc/' . $area . '/' . $configFileName;
36
        }
37
38
        return $relativeConfigFilePath;
39
    }
40
41
    /**
42
     * @param string $selectedArea
43
     */
44
    private function validateArea($selectedArea)
45
    {
46
        /** @var $areaList AreaList */
47
        $areaList = $this->get(AreaList::class);
48
        $areaCodes = $areaList->getCodes();
49
50
        if (!in_array($selectedArea, $areaCodes)) {
51
            throw new \InvalidArgumentException('Invalid area. Available ares are (' . implode(',', $areaCodes) . ')');
52
        }
53
    }
54
}
55