HasInitial::setInitial()   A
last analyzed

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
declare(strict_types=1);
4
5
namespace Swis\JsonApi\Client\Concerns;
6
7
trait HasInitial
8
{
9
    /**
10
     * @var array
11
     */
12
    protected $initial = [];
13
14
    /**
15
     * @param  string|null  $key
16
     * @return array|mixed
17
     */
18 4
    public function getInitial($key = null)
19
    {
20 4
        if ($key === null) {
21 4
            return $this->initial;
22
        }
23
24 4
        return $this->initial[$key];
25
    }
26
27
    /**
28
     * @return static
29
     */
30 12
    public function setInitial(array $initial)
31
    {
32 12
        $this->initial = $initial;
33
34 12
        return $this;
35
    }
36
37
    /**
38
     * @param  string|null  $key
39
     */
40 4
    public function hasInitial($key = null): bool
41
    {
42 4
        if ($key === null) {
43 4
            return ! empty($this->initial);
44
        }
45
46 4
        return isset($this->initial[$key]);
47
    }
48
}
49