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

ArrayWrapper::getItemsBySelector()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 5
Bugs 1 Features 0
Metric Value
c 5
b 1
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 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