Test Failed
Push — master ( 31c635...ef6440 )
by Paul
07:17 queued 01:32
created

Arguments   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Test Coverage

Coverage 64.71%

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 12
eloc 25
dl 0
loc 103
ccs 22
cts 34
cp 0.6471
rs 10
c 2
b 0
f 2

10 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 6 2
A cast() 0 3 1
A isEmpty() 0 3 1
A merge() 0 5 1
A toArray() 0 3 1
A offsetUnset() 0 6 1
A offsetGet() 0 4 1
A set() 0 4 1
A __construct() 0 8 2
A __toString() 0 3 1
1
<?php
2
3
namespace GeminiLabs\SiteReviews;
4
5
use GeminiLabs\SiteReviews\Helpers\Arr;
6
use GeminiLabs\SiteReviews\Helpers\Cast;
7
8
class Arguments extends \ArrayObject
9
{
10
    /**
11
     * @param mixed $args
12
     */
13 24
    public function __construct($args)
14
    {
15 24
        if ($args instanceof Arguments) {
16
            $args = $args->toArray();
17
        } else {
18 24
            $args = Arr::consolidate($args);
19
        }
20 24
        parent::__construct($args, \ArrayObject::STD_PROP_LIST | \ArrayObject::ARRAY_AS_PROPS);
21 24
    }
22
23
    /**
24
     * @return string
25
     */
26
    public function __toString()
27
    {
28
        return serialize($this->toArray());
29
    }
30
31
    /**
32
     * @param mixed $key
33
     * @param string $cast
34
     * @return mixed
35
     */
36
    public function cast($key, $cast)
37
    {
38
        return Cast::to($cast, $this->get($key));
39
    }
40
41
    /**
42
     * @param mixed $key
43
     * @param mixed $fallback
44
     * @return mixed
45
     */
46 24
    public function get($key, $fallback = null)
47
    {
48 24
        $value = Arr::get($this->toArray(), $key, $fallback);
49 24
        return isset($fallback)
50 15
            ? Helper::ifEmpty($value, $fallback)
51 24
            : $value;
52
    }
53
54
    /**
55
     * @return bool
56
     */
57
    public function isEmpty()
58
    {
59
        return empty($this->toArray());
60
    }
61
62
    /**
63
     * @return self
64
     */
65 13
    public function merge(array $data = [])
66
    {
67 13
        $storage = wp_parse_args($data, $this->toArray());
68 13
        $this->exchangeArray($storage);
69 13
        return $this;
70
    }
71
72
    /**
73
     * @param mixed $key
74
     * @return mixed
75
     */
76
    #[\ReturnTypeWillChange]
77 15
    public function offsetGet($key)
78
    {
79 15
        return $this->get($key);
80
    }
81
82
    /**
83
     * @param mixed $key
84
     * @return void
85
     */
86
    #[\ReturnTypeWillChange]
87
    public function offsetUnset($key)
88
    {
89
        $storage = $this->toArray();
90
        unset($storage[$key]);
91
        $this->exchangeArray($storage);
92
    }
93
94
    /**
95
     * @param string $path
96
     * @param mixed $value
97
     * @return void
98
     */
99 23
    public function set($path, $value)
100
    {
101 23
        $storage = Arr::set($this->toArray(), $path, $value);
102 23
        $this->exchangeArray($storage);
103 23
    }
104
105
    /**
106
     * @return array
107
     */
108 25
    public function toArray()
109
    {
110 25
        return $this->getArrayCopy();
111
    }
112
}
113