Completed
Pull Request — 3.x (#13)
by Damiano
01:31
created

PayloadImmutable::setMessages()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 *
4
 * This file is part of Aura for PHP.
5
 *
6
 * @license http://opensource.org/licenses/MIT MIT
7
 *
8
 */
9
10
namespace Aura\Payload;
11
12
use Aura\Payload_Interface\PayloadInterface;
13
14
/**
15
 *
16
 * A domain payload object.
17
 *
18
 * @package Aura.Payload
19
 *
20
 */
21
class PayloadImmutable implements PayloadInterface
22
{
23
    /**
24
     *
25
     * The payload status.
26
     *
27
     * @var mixed
28
     *
29
     */
30
    private $status;
31
32
    /**
33
     *
34
     * The domain input.
35
     *
36
     * @var mixed
37
     *
38
     */
39
    private $input;
40
41
    /**
42
     *
43
     * The domain output.
44
     *
45
     * @var mixed
46
     *
47
     */
48
    private $output;
49
50
    /**
51
     *
52
     * Messages reported by the domain.
53
     *
54
     * @var mixed
55
     *
56
     */
57
    private $messages;
58
59
    /**
60
     *
61
     * Arbitrary extra information from the domain.
62
     *
63
     * @var mixed
64
     *
65
     */
66
    private $extras;
67
68
    /**
69
     *
70
     * Sets the payload status.
71
     *
72
     * @param mixed $status The payload status.
73
     *
74
     * @return self
75
     *
76
     */
77 3
    public function setStatus($status)
78
    {
79 3
        $cloned = clone $this;
80 3
        $cloned->status = $status;
81
82 3
        return $cloned;
83
    }
84
85
    /**
86
     *
87
     * Gets the payload status.
88
     *
89
     * @return mixed
90
     *
91
     */
92 3
    public function getStatus()
93
    {
94 3
        return $this->status;
95
    }
96
97
    /**
98
     *
99
     * Sets the domain input.
100
     *
101
     * @param mixed $input The domain input.
102
     *
103
     * @return self
104
     *
105
     */
106 3
    public function setInput($input)
107
    {
108 3
        $cloned = clone $this;
109 3
        $cloned->input = $input;
110
111 3
        return $cloned;
112
    }
113
114
    /**
115
     *
116
     * Gets the domain input.
117
     *
118
     * @return mixed
119
     *
120
     */
121 1
    public function getInput()
122
    {
123 1
        return $this->input;
124
    }
125
126
    /**
127
     *
128
     * Sets the domain output.
129
     *
130
     * @param mixed $output The domain output.
131
     *
132
     * @return self
133
     *
134
     */
135 1
    public function setOutput($output)
136
    {
137 1
        $cloned = clone $this;
138 1
        $cloned->output = $output;
139
140 1
        return $cloned;
141
    }
142
143
    /**
144
     *
145
     * Gets the domain output.
146
     *
147
     * @return mixed
148
     *
149
     */
150 1
    public function getOutput()
151
    {
152 1
        return $this->output;
153
    }
154
155
    /**
156
     *
157
     * Sets the domain messages.
158
     *
159
     * @param mixed $messages The domain messages.
160
     *
161
     * @return self
162
     *
163
     */
164 1
    public function setMessages($messages)
165
    {
166 1
        $cloned = clone $this;
167 1
        $cloned->messages = $messages;
168
169 1
        return $cloned;
170
    }
171
172
    /**
173
     *
174
     * Gets the domain messages.
175
     *
176
     * @return mixed
177
     *
178
     */
179 1
    public function getMessages()
180
    {
181 1
        return $this->messages;
182
    }
183
184
    /**
185
     *
186
     * Sets arbitrary extra domain information.
187
     *
188
     * @param mixed $extras The domain extras.
189
     *
190
     * @return self
191
     *
192
     */
193 1
    public function setExtras($extras)
194
    {
195 1
        $cloned = clone $this;
196 1
        $cloned->extras = $extras;
197
198 1
        return $cloned;
199
    }
200
201
    /**
202
     *
203
     * Gets the arbitrary extra domain information.
204
     *
205
     * @return mixed
206
     *
207
     */
208 1
    public function getExtras()
209
    {
210 1
        return $this->extras;
211
    }
212
213
    /**
214
     * Deep clone all properties
215
     */
216 3
    protected function __clone()
217
    {
218 3
        $this->status = $this->deepClone($this->status);
219 3
        $this->input = $this->deepClone($this->input);
220 3
        $this->output = $this->deepClone($this->output);
221 3
        $this->messages = $this->deepClone($this->messages);
222 3
        $this->extras = $this->deepClone($this->extras);
223 3
    }
224
225
    /**
226
     * Return a cloned property
227
     *
228
     * @param $property
229
     *
230
     * @return mixed
231
     */
232 3
    protected function deepClone($property)
233
    {
234 3
        if (is_array($property)) {
235 2
            $cloned = [];
236 2
            foreach ($property as $key => $value) {
237 2
                $cloned[$key] = $this->deepClone($value);
238 2
            }
239
240 2
            return $cloned;
241
        }
242
243 3
        if (is_object($property)) {
244 2
            return clone $property;
245
        }
246
247 3
        return $property;
248
    }
249
}
250