SystemParams   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 4
dl 0
loc 71
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A bootstrap() 0 26 5
A getParam() 0 6 2
1
<?php
2
3
namespace yiicod\systemparams;
4
5
use Yii;
6
use yii\base\BootstrapInterface;
7
use yii\base\Component;
8
use yii\helpers\ArrayHelper;
9
10
/**
11
 * Cms extension settings.
12
 *
13
 * @author Orlov Alexey <[email protected]>
14
 */
15
class SystemParams extends Component implements BootstrapInterface
16
{
17
    /**
18
     * @var bool
19
     */
20
    public $commandMap = [];
21
22
    /**
23
     * @var array table settings
24
     */
25
    public $modelMap = [];
26
27
    /**
28
     * Cache durations.
29
     *
30
     * @var int
31
     */
32
    public $cacheDuration;
33
34
    /**
35
     * System params service instance
36
     *
37
     * @var null
38
     */
39
    private static $service;
40
41
    /**
42
     * Init components, Merge config.
43
     */
44
    public function bootstrap($app)
45
    {
46
        //Merge main extension config with local extension config
47
        $config = include dirname(__FILE__) . '/config/main.php';
48
49
        foreach ($config as $key => $value) {
50
            if (is_array($value)) {
51
                $this->{$key} = ArrayHelper::merge($value, $this->{$key});
52
            } elseif (null === $this->{$key}) {
53
                $this->{$key} = $value;
54
            }
55
        }
56
57
        self::$service = Yii::createObject([
0 ignored issues
show
Documentation Bug introduced by
It seems like \Yii::createObject(array... $this->cacheDuration)) of type object is incompatible with the declared type null of property $service.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
58
            'class' => SystemParamsService::class,
59
            'cacheDuration' => $this->cacheDuration,
60
        ]);
61
62
        //Merge commands map
63
        if (Yii::$app instanceof \yii\console\Application) {
64
            Yii::$app->controllerMap = ArrayHelper::merge($this->commandMap, Yii::$app->controllerMap);
65
            Yii::$app->controllerMap = array_filter(Yii::$app->controllerMap);
66
        }
67
68
        Yii::setAlias('@yiicod', realpath(dirname(__FILE__) . '/..'));
69
    }
70
71
    /**
72
     * Get parameter
73
     *
74
     * @param string $param
75
     * @param mixed $default
76
     *
77
     * @return mixed
78
     */
79
    public static function getParam(string $param, $default = null)
80
    {
81
        $value = self::$service->getParam($param);
0 ignored issues
show
Bug introduced by
The method getParam cannot be called on self::$service (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
82
83
        return null === $value ? $default : $value;
84
    }
85
}
86