Completed
Push — master ( aeb11c...f98da5 )
by Adrian
02:32
created

ArrayWrapper   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 10
Bugs 2 Features 1
Metric Value
wmc 7
c 10
b 2
f 1
lcom 1
cbo 1
dl 0
loc 39
ccs 16
cts 16
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 14 5
A getItemValue() 0 4 1
A getItemsBySelector() 0 4 1
1
<?php
2
3
namespace Sirius\Validation\DataWrapper;
4
5
use Sirius\Validation\Util\Arr;
6
use Sirius\Validation\DataWrapper\WrapperInterface;
7
8
class ArrayWrapper implements WrapperInterface
9
{
10
11
    /**
12
     * @var array
13
     */
14
    protected $data = array();
15
16
    /**
17
     * @param array|\ArrayObject|object $data
18
     *
19
     * @throws \InvalidArgumentException
20
     */
21 31
    public function __construct($data = array())
22
    {
23 31
        if (is_object($data)) {
24 1
            if ($data instanceof \ArrayObject) {
25 1
                $data = $data->getArrayCopy();
26 1
            } elseif (method_exists($data, 'toArray')) {
27 1
                $data = $data->toArray();
28 1
            }
29 1
        }
30 31
        if ( ! is_array($data)) {
31 1
            throw new \InvalidArgumentException('Data passed to validator is not an array or an ArrayObject');
32
        }
33 30
        $this->data = $data;
34 30
    }
35
36 14
    public function getItemValue($item)
37
    {
38 14
        return Arr::getByPath($this->data, $item);
39
    }
40
41 14
    public function getItemsBySelector($selector)
42
    {
43 14
        return Arr::getBySelector($this->data, $selector);
44
    }
45
46
}
47