Arguments::isEmpty()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Bakery\Support;
4
5
use ArrayObject;
6
7
class Arguments extends ArrayObject
8
{
9
    /**
10
     * Arguments constructor.
11
     *
12
     * @param array $args
13
     */
14
    public function __construct(array $args)
15
    {
16
        $data = [];
17
18
        foreach ($args as $key => $value) {
19
            if (is_array($value)) {
20
                $value = new self($value);
21
            }
22
23
            $data[$key] = $value;
24
        }
25
26
        parent::__construct($data, ArrayObject::ARRAY_AS_PROPS);
27
    }
28
29
    /**
30
     * @param $offset
31
     * @return mixed|null
32
     */
33
    public function offsetGet($offset)
34
    {
35
        if (! $this->offsetExists($offset)) {
36
            return null;
37
        }
38
39
        return parent::offsetGet($offset);
40
    }
41
42
    /**
43
     * Get the instance as an array.
44
     *
45
     * @return array
46
     */
47
    public function toArray(): array
48
    {
49
        return $this->getArrayCopy();
50
    }
51
52
    /**
53
     * @return array
54
     */
55
    public function getArrayCopy(): array
56
    {
57
        $array = parent::getArrayCopy();
58
59
        foreach ($array as $key => $value) {
60
            if ($value instanceof self) {
61
                $array[$key] = $value->getArrayCopy();
62
            }
63
        }
64
65
        return $array;
66
    }
67
68
    /**
69
     * Return if the arguments are empty.
70
     *
71
     * @return bool
72
     */
73
    public function isEmpty()
74
    {
75
        return empty($this->toArray());
76
    }
77
}
78