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

HasInitial   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 45
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getInitial() 0 7 2
A hasInitial() 0 7 2
A setInitial() 0 5 1
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