Nested::isValidArray()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 3
nop 3
dl 0
loc 13
ccs 9
cts 9
cp 1
crap 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the Valdi package.
5
 *
6
 * (c) Philip Lehmann-Böhm <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Valdi\Validator;
13
14
use Valdi\Validator;
15
16
/**
17
 * Validator for nested data sets.
18
 */
19
class Nested extends AbstractArray
20
{
21
22
    /**
23
     * {@inheritdoc}
24
     */
25 3
    protected function isValidArray($values, Validator $validator, array $rules)
26
    {
27 3
        if (!is_array($values)) {
28 1
            $this->invalidDetails = $values;
29 1
            return false;
30
        }
31
32 3
        $elementValidation = $validator->isValid($rules, $values);
33 3
        if (!$elementValidation['valid']) {
34 2
            $this->invalidDetails = $elementValidation['errors'];
35 2
            return false;
36
        }
37 2
        return true;
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43 1
    public function getInvalidDetails()
44
    {
45 1
        return ['nested' => $this->invalidDetails];
46
    }
47
}
48