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

AbstractElement::unserialize()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 6

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 21
ccs 13
cts 13
cp 1
rs 8.7624
cc 6
eloc 12
nc 6
nop 1
crap 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
}