Completed
Push — master ( 4292b8...a9ea1a )
by Andrii
04:42
created

Config::getVcs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
ccs 2
cts 2
cp 1
rs 9.4285
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 * Automation tool mixed with code generator for easier continuous development
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
    protected $_included = [];
24
25 5
    public function hasGoal($id)
26
    {
27 5
        return $this->hasItem($id);
28
    }
29
30 5
    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...
31
    {
32 5
        if (isset($config['class']) && $this->hasItem($config['class'])) {
33
            $config = array_merge($config, $this->_items[$config['class']]);
34
        }
35 5
        return ArrayHelper::merge([
36 5
            'class' => 'hidev\controllers\CommonController',
37 5
        ], $config);
38
    }
39
40 5
    public function createItem($id, $config = [])
41
    {
42 5
        return Yii::createObject($this->getItemConfig($id, $config), [$id, Yii::$app]);
43
    }
44
45 5
    public function getItem($id)
46
    {
47 5
        $item = &$this->_items[$id];
48 5
        if (is_array($item)) {
49 5
            $item = $this->createItem($id, $item);
50 5
        }
51
52 5
        return $item;
53
    }
54
55
    /**
56
     * Include config file, unique only.
57
     * @param string|array $path
58
     * @return bool true if the path was unique and loaded
59
     */
60 2
    public function includeConfig($path, $force = false)
61
    {
62 2
        $file = File::create($path);
63 2
        $path = $file->getPath();
64 2
        if (!isset($this->_included[$path]) || $force) {
65 2
            $this->_included[$path] = $path;
66 2
            $this->mergeItems($file->load());
67 2
            return true;
68
        }
69
70
        return false;
71
    }
72
73 4
    public function getGoal($id)
74
    {
75 4
        return Yii::$app->createControllerById($id);
76
    }
77
78 2
    public function getVcs()
79
    {
80
        /// TODO determine VCS
81 2
        return $this->getGoal('git');
82
    }
83
}
84