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

AbstractElement   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 76%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 12
c 4
b 0
f 0
lcom 1
cbo 3
dl 0
loc 82
ccs 19
cts 25
cp 0.76
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getView() 0 4 1
A setView() 0 6 2
A propertiesForSerialization() 0 6 1
A toArray() 0 6 1
A serialize() 0 4 1
B unserialize() 0 21 6
1
<?php
2
namespace Malezha\Menu\Element;
3
4
use Illuminate\Container\Container;
5
use Malezha\Menu\Contracts\DisplayRule;
6
use Malezha\Menu\Contracts\Element;
7
use Malezha\Menu\Contracts\MenuRender;
8
use Serafim\Properties\Properties;
9
10
/**
11
 * Class AbstractElement
12
 * @package Malezha\Menu\Element
13
 */
14
abstract class AbstractElement implements Element
15
{
16
    use Properties;
17
18
    /**
19
     * @var string
20
     */
21
    protected $view;
22
23
    /**
24
     * @var MenuRender
25
     */
26
    protected $render;
27
28
    /**
29
     * @inheritdoc
30
     */
31
    public function getView()
32
    {
33
        return $this->view;
34
    }
35
36
    /**
37
     * @inheritdoc
38
     */
39
    public function setView($view)
40
    {
41
        if ($this->render->exists($view)) {
42
            $this->view = $view;
43
        }
44
    }
45
46 3
    protected function propertiesForSerialization()
47
    {
48
        return [
49 3
            'view' => $this->view,
50
        ];
51
    }
52
53
    /**
54
     * @inheritDoc
55
     */
56 3
    public function toArray()
57
    {
58
        return [
59 3
            'view' => $this->view,
60
        ];
61
    }
62
63
    /**
64
     * @inheritDoc
65
     */
66 3
    public function serialize()
67
    {
68 3
        return serialize($this->propertiesForSerialization());
69
    }
70
71
    /**
72
     * @inheritDoc
73
     */
74 2
    public function unserialize($serialized)
75
    {
76 2
        $data = unserialize($serialized);
77
78 2
        if ($this instanceof DisplayRule
79 2
            && method_exists($this, 'unserializeRule')
80 2
            && array_key_exists('displayRule', $data)
81
        ) {
82 2
            $this->unserializeRule($data['displayRule']);
0 ignored issues
show
Bug introduced by
The method unserializeRule() does not exist on Malezha\Menu\Element\AbstractElement. Did you maybe mean serialize()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
83 2
            unset($data['displayRule']);
84
        }
85
86 2
        foreach ($data as $key => $value) {
87 2
            if (property_exists($this, $key)) {
88 2
                $this->{$key} = $value;
89
            }
90
        }
91
92 2
        $app = Container::getInstance();
93 2
        $this->render = $app->make(MenuRender::class);
94
    }
95
}