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

Sections   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 29.4%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 12
c 1
b 0
f 0
dl 0
loc 49
ccs 5
cts 17
cp 0.294
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 3 1
A set() 0 5 1
A has() 0 3 1
A toArray() 0 3 1
A __set() 0 3 1
A get() 0 7 2
A __get() 0 3 1
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