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

Collection::isValidArray()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.2
c 0
b 0
f 0
nc 4
cc 4
eloc 10
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 array values fulfilling a rule.
18
 */
19
class Collection 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
        $this->invalidDetails = [];
31
        foreach ($values as $key => $value) {
32
            $elementValidation = $validator->isValid(['value' => $rules], ['value' => $value]);
33
            if (!$elementValidation['valid']) {
34
                $this->invalidDetails[$key] = $elementValidation['errors']['value'];
35
            }
36
        }
37
        return count($this->invalidDetails) === 0;
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function getInvalidDetails() {
44
        return ['collection' => $this->invalidDetails];
45
    }
46
}
47