Completed
Push — master ( 9d213e...40d07d )
by Andrii
03:03
created

Config::getClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
cc 1
eloc 1
nc 1
nop 1
crap 2
1
<?php
2
3
/*
4
 * Task runner, code generator and build tool for easier continuos integration
5
 *
6
 * @link      https://github.com/hiqdev/hidev
7
 * @package   hidev
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hidev\components;
13
14
use hidev\base\File;
15
use Yii;
16
use yii\helpers\ArrayHelper;
17
18
/**
19
 * The Config. Keeps config and Goals.
20
 */
21
class Config extends \hiqdev\yii2\collection\Object
22
{
23
    public $file = '.hidev/config.yml';
24
25
    protected $_included = [];
26
27
    public function hasGoal($id)
28
    {
29
        return $this->hasItem($id);
30
    }
31
32
    public function getClass($name)
0 ignored issues
show
Unused Code introduced by
The parameter $name 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...
33
    {
34
    }
35
36
    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...
37
    {
38
        if (isset($config['class']) && $this->hasItem($config['class'])) {
39
            $config = array_merge($config, $this->_items[$config['class']]);
40
        }
41
        return ArrayHelper::merge([
42
            'class' => 'hidev\controllers\CommonController',
43
        ], $config);
44
    }
45
46
    protected function createItem($id, $config = [])
47
    {
48
        return Yii::createObject($this->getItemConfig($id, $config), [$id, Yii::$app]);
49
    }
50
51
    public function getItem($id)
52
    {
53
        $item = &$this->_items[$id];
54
        if (is_array($item)) {
55
            $item = $this->createItem($id, $item);
56
        }
57
58
        return $item;
59
    }
60
61
    /**
62
     * Include config file, unique only.
63
     * @param string|array $path
64
     * @return bool true if the path was unique and loaded
65
     */
66
    public function includeConfig($path)
67
    {
68
        $file = File::create($path);
69
        $path = $file->getPath();
70
        if (!isset($this->_included[$path])) {
71
            $this->_included[$path] = $path;
72
            $this->mergeItems($file->load());
73
            return true;
74
        }
75
76
        return false;
77
    }
78
79
    public function getGoal($id)
80
    {
81
        return Yii::$app->createControllerById($id);
82
    }
83
84
    public function getVcs()
85
    {
86
        /// TODO determine VCS
87
        return $this->getGoal('git');
88
    }
89
}
90