LinkedListItem::setNext()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Smoren\Containers\Structs;
4
5
/**
6
 * Class LinkedListItem
7
 */
8
class LinkedListItem
9
{
10
    /**
11
     * @var mixed data value
12
     */
13
    protected $data;
14
    /**
15
     * @var mixed|null extra data
16
     */
17
    protected $extra = null;
18
    /**
19
     * @var LinkedListItem|null previous element position
20
     */
21
    protected ?LinkedListItem $prev;
22
    /**
23
     * @var LinkedListItem|null next element position
24
     */
25
    protected ?LinkedListItem $next;
26
27
    /**
28
     * LinkedListItem constructor.
29
     * @param mixed $data data value
30
     * @param LinkedListItem|null $prev previous element position
31
     * @param LinkedListItem|null $next next element position
32
     * @param mixed $extra extra data
33
     */
34
    public function __construct($data, ?LinkedListItem $prev, ?LinkedListItem $next, $extra = null)
35
    {
36
        $this->data = $data;
37
        $this->prev = $prev;
38
        $this->next = $next;
39
        $this->extra = $extra;
40
    }
41
42
    /**
43
     * Returns data value
44
     * @return mixed
45
     */
46
    public function getData()
47
    {
48
        return $this->data;
49
    }
50
51
    /**
52
     * Sets data value
53
     * @param mixed $data data value
54
     * @return $this
55
     */
56
    public function setData($data): LinkedListItem
57
    {
58
        $this->data = $data;
59
        return $this;
60
    }
61
62
    /**
63
     * Returns previous element position
64
     * @return LinkedListItem|null
65
     */
66
    public function getPrev(): ?LinkedListItem
67
    {
68
        return $this->prev;
69
    }
70
71
    /**
72
     * Returns next element position
73
     * @return LinkedListItem|null
74
     */
75
    public function getNext(): ?LinkedListItem
76
    {
77
        return $this->next;
78
    }
79
80
    /**
81
     * Sets previous element position
82
     * @param LinkedListItem|null $item previous element position
83
     * @return $this
84
     */
85
    public function setPrev(?LinkedListItem $item): self
86
    {
87
        $this->prev = $item;
88
        return $this;
89
    }
90
91
    /**
92
     * Sets next element position
93
     * @param LinkedListItem|null $item
94
     * @return $this
95
     */
96
    public function setNext(?LinkedListItem $item): self
97
    {
98
        $this->next = $item;
99
        return $this;
100
    }
101
102
    /**
103
     * Gets extra data
104
     * @return mixed|null
105
     */
106
    public function getExtra()
107
    {
108
        return $this->extra;
109
    }
110
111
    /**
112
     * Sets extra data
113
     * @param mixed $extra extra data
114
     * @return $this
115
     */
116
    public function setExtra($extra): self
117
    {
118
        $this->extra = $extra;
119
        return $this;
120
    }
121
122
    /**
123
     * Clones object
124
     */
125
    public function __clone()
126
    {
127
        if(is_object($this->data)) {
128
            $this->data = clone $this->data;
129
        }
130
131
        if(is_object($this->extra)) {
132
            $this->extra = clone $this->extra;
133
        }
134
135
        $this->prev = null;
136
        $this->next = null;
137
    }
138
}
139