Completed
Push — master ( 3204cd...9afd5c )
by Andrii
02:53
created

Config   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Test Coverage

Coverage 10.53%

Importance

Changes 0
Metric Value
wmc 14
lcom 2
cbo 4
dl 0
loc 69
ccs 2
cts 19
cp 0.1053
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A createItem() 0 4 1
A hasGoal() 0 4 1
A getItemConfig() 0 10 3
A includeConfig() 0 13 3
A getGoal() 0 4 1
A getVcs() 0 5 1
A getItem() 0 13 4
1
<?php
2
/**
3
 * Automation tool mixed with code generator for easier continuous development
4
 *
5
 * @link      https://github.com/hiqdev/hidev
6
 * @package   hidev
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hidev\components;
12
13
use hidev\base\File;
14
use Yii;
15
use yii\helpers\ArrayHelper;
16
17
/**
18
 * The Config. Keeps config and Goals.
19
 */
20
class Config extends \hiqdev\yii2\collection\Object
21
{
22
    protected $_included = [];
23
24
    public function hasGoal($id)
25
    {
26
        return $this->hasItem($id);
27
    }
28
29 3
    public function getItemConfig($id = null, array $config = [])
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
30
    {
31
        if (isset($config['class']) && $this->hasItem($config['class'])) {
32
            $config = array_merge($config, $this->_items[$config['class']]);
33
        }
34
35
        return ArrayHelper::merge([
36
            'class' => 'hidev\controllers\CommonController',
37
        ], $config);
38 3
    }
39
40
    public function createItem($id, $config = [])
41
    {
42
        return Yii::createObject($this->getItemConfig($id, $config), [$id, Yii::$app]);
43
    }
44
45
    public function getItem($id, $default = null)
46
    {
47
        $item = &$this->_items[$id];
48
        if (is_array($item)) {
49
            if (count($item) === 1 && key($item) === 'alias') {
50
                $item = $this->getItem($item['alias']);
51
            } else {
52
                $item = $this->createItem($id, $item);
53
            }
54
        }
55
56
        return $item;
57
    }
58
59
    /**
60
     * Include config file, unique only.
61
     * @param string|array $path
62
     * @return bool true if the path was unique and loaded
63
     */
64
    public function includeConfig($path, $force = false)
65
    {
66
        $file = File::create($path);
67
        $path = $file->getPath();
68
        if (!isset($this->_included[$path]) || $force) {
69
            $this->_included[$path] = $path;
70
            $this->mergeItems($file->load());
71
72
            return true;
73
        }
74
75
        return false;
76
    }
77
78
    public function getGoal($id)
79
    {
80
        return Yii::$app->createControllerById($id);
81
    }
82
83
    public function getVcs()
84
    {
85
        /// TODO determine VCS
86
        return $this->getGoal('git');
87
    }
88
}
89