Completed
Push — master ( e84808...5a9d2e )
by Oleg
07:58
created

AbstractElementFactory   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 115
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 12
c 2
b 0
f 0
lcom 2
cbo 1
dl 0
loc 115
ccs 18
cts 18
cp 1
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getElementConfig() 0 4 1
A getParameter() 0 8 2
A setParameter() 0 6 1
A unsetParameter() 0 6 1
A existsParameter() 0 4 1
A mergeParameters() 0 4 1
A __get() 0 4 1
A __set() 0 4 1
A __isset() 0 4 1
A __unset() 0 4 1
1
<?php
2
namespace Malezha\Menu\Factory;
3
4
use Illuminate\Contracts\Config\Repository;
5
use Illuminate\Contracts\Container\Container;
6
use Malezha\Menu\Contracts\ElementFactory;
7
8
/**
9
 * Class AbstractElementFactory
10
 * @package Malezha\Menu\Factory
11
 */
12
abstract class AbstractElementFactory implements ElementFactory
13
{
14
    /**
15
     * @var Container
16
     */
17
    protected $app;
18
19
    /**
20
     * @var array
21
     */
22
    protected $parameters = [];
23
24
    /**
25
     * @inheritdoc
26
     */
27 27
    public function __construct(Container $container)
28
    {
29 27
        $this->app = $container;
30 27
    }
31
32
    /**
33
     * @param string $class
34
     * @return array
35
     */
36 27
    protected function getElementConfig($class)
37
    {
38 27
        return $this->app->make(Repository::class)->get('menu.elements')[$class];
39
    }
40
41
    /**
42
     * @param string $name
43
     * @return mixed
44
     */
45 12
    protected function getParameter($name)
46
    {
47 12
        if (array_key_exists($name, $this->parameters)) {
48 12
            return $this->parameters[$name];
49
        }
50
51
        return null;
52
    }
53
54
    /**
55
     * @param string $name
56
     * @param mixed $value
57
     * @return $this
58
     */
59 26
    protected function setParameter($name, $value)
60
    {
61 26
        $this->parameters[$name] = $value;
62
        
63 26
        return $this;
64
    }
65
66
    /**
67
     * @param string $name
68
     * @return $this
69
     */
70
    protected function unsetParameter($name)
71
    {
72
        unset($this->parameters[$name]);
73
        
74
        return $this;
75
    }
76
77
    /**
78
     * @param string $name
79
     * @return bool
80
     */
81
    protected function existsParameter($name)
82
    {
83
        return array_key_exists($name, $this->parameters);
84
    }
85
86
    /**
87
     * @param array $parameters
88
     * @return array
89
     */
90 22
    protected function mergeParameters($parameters = [])
91
    {
92 22
        return array_merge($this->parameters, $parameters);
93
    }
94
95
    /**
96
     * @inheritDoc
97
     */
98 12
    function __get($name)
99
    {
100 12
        return $this->getParameter($name);
101
    }
102
103
    /**
104
     * @inheritDoc
105
     */
106 26
    function __set($name, $value)
107
    {
108 26
        $this->setParameter($name, $value);
109 26
    }
110
111
    /**
112
     * @inheritDoc
113
     */
114
    function __isset($name)
115
    {
116
        return $this->existsParameter($name);
117
    }
118
119
    /**
120
     * @inheritDoc
121
     */
122
    function __unset($name)
123
    {
124
        $this->unsetParameter($name);
125
    }
126
}