Passed
Push — 0.3 ( a188cc...3c900f )
by Philippe
27:26
created

Details::get()   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
eloc 3
c 0
b 0
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Thinktomorrow\Chief\Management\Details;
6
7
use Illuminate\Contracts\Support\Arrayable;
8
9
/**
10
 * @property $key
11
 * @property $singular
12
 * @property $plural
13
 * @property $internal_label
14
 * @property $title
15
 * @property $subtitle
16
 * @property $intro
17
 */
18
class Details implements Arrayable
19
{
20
    /** @var array */
21
    protected $values = [];
22
23 110
    public function __construct($id, string $key, string $singular, string $plural, string $internal_label, string $title)
24
    {
25
        // Default model details
26 110
        $this->values['id'] = $id;
27 110
        $this->values['key'] = $key;
28 110
        $this->values['singular'] = $singular;
29 110
        $this->values['plural'] = $plural;
30 110
        $this->values['internal_label'] = $internal_label;
31 110
        $this->values['title'] = $title;
32 110
    }
33
34 94
    public function get($attribute = null)
35
    {
36 94
        if (array_key_exists($attribute, $this->values)) {
37 94
            return $this->values[$attribute];
38
        }
39
40 1
        return null;
41
    }
42
43
    public function has($attribute): bool
44
    {
45
        return null !== $this->get($attribute);
46
    }
47
48 80
    public function set($attribute, $value)
49
    {
50 80
        $this->values[$attribute] = $value;
51
52 80
        return $this;
53
    }
54
55 94
    public function __get($attribute)
56
    {
57 94
        return $this->get($attribute);
58
    }
59
60
    public function __set($attribute, $value)
61
    {
62
        return $this->set($attribute, $value);
63
    }
64
65
    public function __toString()
66
    {
67
        return (string) $this->get('key');
68
    }
69
70
    /**
71
     * Get the instance as an array.
72
     *
73
     * @return array
74
     */
75
    public function toArray()
76
    {
77
        return $this->values;
78
    }
79
}
80