Completed
Push — master ( d0ffc9...f4094b )
by Philip
02:22 queued 18s
created

Nested::isValidArray()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
nc 3
cc 3
eloc 9
nop 3
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
     * {@inheritdoc}
23
     */
24
    protected function isValidArray($values, Validator $validator, array $rules) {
25
        if (!is_array($values)) {
26
            $this->invalidDetails = $values;
27
            return false;
28
        }
29
30
        $elementValidation = $validator->isValid($rules, $values);
31
        if (!$elementValidation['valid']) {
32
            $this->invalidDetails = $elementValidation['errors'];
33
            return false;
34
        }
35
        return true;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function getInvalidDetails() {
42
        return ['nested' => $this->invalidDetails];
43
    }
44
}
45