Completed
Push — master ( b4a6ad...e2bab1 )
by Andrii
13:50
created

Config::loadAllConfigs()   B

Complexity

Conditions 6
Paths 7

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
rs 8.8571
cc 6
eloc 10
nc 7
nop 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A Config::getGoal() 0 4 1
A Config::getVcs() 0 5 1
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) 2014-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hidev\components;
13
14
use hidev\base\File;
15
use hidev\helpers\Helper;
16
use Yii;
17
use yii\base\BootstrapInterface;
18
use yii\base\InvalidParamException;
19
use yii\helpers\ArrayHelper;
20
21
/**
22
 * The Config. Keeps config and Goals.
23
 */
24
class Config extends \hiqdev\yii2\collection\Object
25
{
26
    public $file = '.hidev/config.yml';
27
28
    protected $_included = [];
29
30
    public function hasGoal($id)
31
    {
32
        return $this->hasItem($id);
33
    }
34
35
    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...
36
    {
37
        return ArrayHelper::merge([
38
            'class' => 'hidev\controllers\CommonController',
39
        ], $config);
40
    }
41
42
    protected function createItem($id, $config = [])
43
    {
44
        return Yii::createObject($this->getItemConfig($id, $config), [$id, Yii::$app]);
45
    }
46
47
    public function getItem($id)
48
    {
49
        $item = &$this->_items[$id];
50
        if (is_array($item)) {
51
            $item = $this->createItem($id, $item);
52
        }
53
54
        return $item;
55
    }
56
57
    /**
58
     * Include config file, unique only.
59
     * @param string|array $path
60
     * @return bool true if the path was unique and loaded
61
     */
62
    public function includeConfig($path)
63
    {
64
        $file = File::create($path);
65
        $path = $file->getPath();
66
        if (!isset($this->_included[$path])) {
67
            $this->_included[$path] = $path;
68
            $this->mergeItems($file->load());
69
            return true;
70
        }
71
72
        return false;
73
    }
74
75
    public function getGoal($id)
76
    {
77
        return Yii::$app->createControllerById($id);
78
    }
79
80
    public function getVcs()
81
    {
82
        /// TODO determine VCS
83
        return $this->getGoal('git');
84
    }
85
}
86