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

AbstractArray   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 38
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
isValidArray() 0 1 ?
A isValid() 0 10 4
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\ValidationException;
15
use Valdi\Validator;
16
17
/**
18
 * Validator for array data, be it maps or lists.
19
 */
20
abstract class AbstractArray implements ValidatorInterface {
21
22
23
    /**
24
     * Holds the invalid values.
25
     */
26
    protected $invalidDetails;
27
28
29
    /**
30
     * Checks whether the given values are of the expected array data.
31
     *
32
     * @param mixed $values
33
     * the potential array values to check
34
     * @param Validator $validator
35
     * the validator to check with
36
     * @param array $rules
37
     * the rules which the array data must fulfill
38
     *
39
     * @return boolean
40
     * true if all the $values are valid, else false with the invalid details set
41
     */
42
    protected abstract function isValidArray($values, Validator $validator, array $rules);
0 ignored issues
show
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function isValid($value, array $parameters) {
48
        if (count($parameters) !== 2) {
49
            throw new ValidationException('Expecting two parameters.');
50
        }
51
        if (!($parameters[0] instanceof Validator)) {
52
            throw new ValidationException('Expecting the first parameter to be an instance of a Validator.');
53
        }
54
        return in_array($value, ['', null], true) ||
55
            $this->isValidArray($value, $parameters[0], $parameters[1]);
56
    }
57
}
58