Completed
Push — master ( 375de1...c13e1e )
by Andrii
13:21
created

Collection   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 11
c 0
b 0
f 0
lcom 1
cbo 3
dl 0
loc 52
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A hasGoal() 0 4 1
A getItemConfig() 0 10 3
A createItem() 0 4 1
A getItem() 0 13 4
A getGoal() 0 4 1
A getVcs() 0 5 1
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\controllers;
12
13
use Yii;
14
use yii\helpers\ArrayHelper;
15
16
/**
17
 * Controllers collection.
18
 * Keeps and creates controllers from configs.
19
 */
20
class Collection extends \hiqdev\yii2\collection\Object
21
{
22
    public $defaultClass = CommonController::class;
23
24
    protected $_included = [];
25
26
    public function hasGoal($id)
27
    {
28
        return $this->hasItem($id);
29
    }
30
31
    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...
32
    {
33
        if (isset($config['class']) && $this->hasItem($config['class'])) {
34
            $config = array_merge($config, $this->_items[$config['class']]);
35
        }
36
37
        return ArrayHelper::merge([
38
            'class' => $this->defaultClass,
39
        ], $config);
40
    }
41
42
    public function createItem($id, $config = [])
43
    {
44
        return Yii::createObject($this->getItemConfig($id, $config), [$id, Yii::$app]);
45
    }
46
47
    public function getItem($id, $default = null)
48
    {
49
        $item = &$this->_items[$id];
50
        if (is_array($item)) {
51
            if (count($item) === 1 && key($item) === 'alias') {
52
                $item = $this->getItem($item['alias']);
53
            } else {
54
                $item = $this->createItem($id, $item);
55
            }
56
        }
57
58
        return $item;
59
    }
60
61
    public function getGoal($id)
62
    {
63
        return Yii::$app->createControllerById($id);
64
    }
65
66
    public function getVcs()
67
    {
68
        /// TODO determine VCS
69
        return $this->getGoal('git');
70
    }
71
}
72