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

Collection   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 28
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isValidArray() 0 15 4
A getInvalidDetails() 0 3 1
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