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

Sections::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
ccs 3
cts 4
cp 0.75
rs 10
cc 2
nc 2
nop 1
crap 2.0625
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Thinktomorrow\Chief\Management\Details;
6
7
use Illuminate\Contracts\Support\Arrayable;
8
9
class Sections implements Arrayable
10
{
11
    /** @var array */
12
    protected $values = [];
13
14 1
    public function get($attribute = null)
15
    {
16 1
        if (array_key_exists($attribute, $this->values)) {
17
            return $this->values[$attribute];
18
        }
19
20 1
        return null;
21
    }
22
23
    public function has($attribute): bool
24
    {
25
        return null !== $this->get($attribute);
26
    }
27
28
    public function set($attribute, $value)
29
    {
30
        $this->values[$attribute] = $value;
31
32
        return $this;
33
    }
34
35 1
    public function __get($attribute)
36
    {
37 1
        return $this->get($attribute);
38
    }
39
40
    public function __set($attribute, $value)
41
    {
42
        return $this->set($attribute, $value);
43
    }
44
45
    public function __toString()
46
    {
47
        return (string) $this->get('key');
48
    }
49
50
    /**
51
     * Get the instance as an array.
52
     *
53
     * @return array
54
     */
55
    public function toArray()
56
    {
57
        return $this->values;
58
    }
59
}
60