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

HasInitial::getInitial()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
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