Completed
Push — master ( 6a485a...18c4f3 )
by Andrii
04:57
created

ObjClass   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 14
lcom 1
cbo 3
dl 0
loc 75
c 1
b 0
f 1
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getAlias() 0 11 3
A getColor() 0 8 2
A getLabel() 0 8 2
A findLabel() 0 12 3
A getValue() 0 8 2
A get() 0 4 1
1
<?php
2
3
namespace hipanel\models;
4
5
use Closure;
6
use Yii;
7
8
class ObjClass extends \yii\base\Object
0 ignored issues
show
Deprecated Code introduced by
The class yii\base\Object has been deprecated with message: since 2.0.13, the class name `Object` is invalid since PHP 7.2, use [[BaseObject]] instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
9
{
10
    public $knownClasses = [];
11
12
    protected $className;
13
14
    protected $_alias;
15
16
    protected $_color;
17
18
    protected $_label;
19
20
    public function __construct($className, $config = [])
21
    {
22
        parent::__construct($config);
23
        $this->className = $className;
24
    }
25
26
    public function getAlias()
27
    {
28
        if ($this->_alias === null) {
29
            $this->_alias = $this->getValue('alias');
30
        }
31
        if ($this->_alias === null) {
32
            $this->_alias = $this->className;
33
        }
34
35
        return $this->_alias;
36
    }
37
38
    public function getColor()
39
    {
40
        if ($this->_color === null) {
41
            $this->_color = $this->getValue('color');
42
        }
43
44
        return $this->_color;
45
    }
46
47
    public function getLabel()
48
    {
49
        if ($this->_label === null) {
50
            $this->_label = $this->findLabel();
51
        }
52
53
        return $this->_label;
54
    }
55
56
    public function findLabel()
57
    {
58
        $label = $this->getValue('label');
59
        if ($label instanceof Closure) {
60
            $label = call_user_func($label, $this);
61
        }
62
        if (!$label) {
63
            $label = ucfirst($this->className);
64
        }
65
66
        return $label;
67
    }
68
69
    public function getValue($key)
70
    {
71
        if (isset($this->knownClasses[$this->className][$key])) {
72
            return $this->knownClasses[$this->className][$key];
73
        }
74
75
        return null;
76
    }
77
78
    public static function get($className)
79
    {
80
        return Yii::$container->get(static::class, [$className]);
81
    }
82
}
83