Completed
Push — master ( 535b5e...300324 )
by Jasper
13s queued 13s
created

HasInitial::setInitial()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Swis\JsonApi\Client\Concerns;
4
5
trait HasInitial
6
{
7
    /**
8
     * @var array
9
     */
10
    protected $initial = [];
11
12
    /**
13
     * @param string|null $key
14
     *
15
     * @return array|mixed
16
     */
17 5
    public function getInitial($key = null)
18
    {
19 5
        if (null === $key) {
20 5
            return $this->initial;
21
        }
22
23 5
        return $this->initial[$key];
24
    }
25
26
    /**
27
     * @param array $initial
28
     *
29
     * @return static
30
     */
31 15
    public function setInitial(array $initial)
32
    {
33 15
        $this->initial = $initial;
34
35 15
        return $this;
36
    }
37
38
    /**
39
     * @param string|null $key
40
     *
41
     * @return bool
42
     */
43 5
    public function hasInitial($key = null): bool
44
    {
45 5
        if (null === $key) {
46 5
            return !empty($this->initial);
47
        }
48
49 5
        return isset($this->initial[$key]);
50
    }
51
}
52