ConfigAwareTrait   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 57
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A registerContainerConfig() 0 4 1
A getConfig() 0 8 2
A setConfig() 0 6 1
A initConfig() 0 9 2
A newConfig() 0 4 1
1
<?php
2
3
namespace Nip\Config;
4
5
/**
6
 * Class ConfigAwareTrait
7
 * @package Nip\Config
8
 */
9
trait ConfigAwareTrait
10
{
11
    /**
12
     * @var Config|Config|null
13
     */
14
    protected $config = null;
15
16
    public function registerContainerConfig()
17
    {
18
        app()->add('config', $this->getConfig(), true);
19
    }
20
21
    /**
22
     * Get the container.
23
     *
24
     * @return Config
25
     */
26
    public function getConfig()
27
    {
28
        if ($this->config == null) {
29
            $this->initConfig();
30
        }
31
32
        return $this->config;
33
    }
34
35
    /**
36
     * Set a container.
37
     *
38
     * @param  Config $config
39
     * @return $this
40
     */
41
    public function setConfig($config)
42
    {
43
        $this->config = $config;
44
45
        return $this;
46
    }
47
48
    public function initConfig()
49
    {
50
        if (app()->has('config')) {
51
            $config = app()->get('config');
52
        } else {
53
            $config = $this->newConfig();
54
        }
55
        $this->setConfig($config);
56
    }
57
58
    /**
59
     * @return Config
60
     */
61
    public function newConfig()
62
    {
63
        return new Config();
64
    }
65
}
66