AbstractArray::isValid()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 6
nc 4
nop 2
dl 0
loc 10
ccs 7
cts 7
cp 1
crap 4
rs 10
c 1
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\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
    /**
25
     * Holds the invalid values.
26
     */
27
    protected $invalidDetails;
28
29
30
    /**
31
     * Checks whether the given values are of the expected array data.
32
     *
33
     * @param mixed $values the potential array values to check
34
     * @param Validator $validator the validator to check with
35
     * @param array $rules the rules which the array data must fulfill
36
     *
37
     * @return boolean - true if all the $values are valid, else false with the invalid details set
38
     */
39
    abstract protected function isValidArray($values, Validator $validator, array $rules);
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 6
    public function isValid($value, array $parameters)
45
    {
46 6
        if (count($parameters) !== 2) {
47 2
            throw new ValidationException('Expecting two parameters.');
48
        }
49 6
        if (!($parameters[0] instanceof Validator)) {
50 2
            throw new ValidationException('Expecting the first parameter to be an instance of a Validator.');
51
        }
52 6
        return in_array($value, ['', null], true) ||
53 6
            $this->isValidArray($value, $parameters[0], $parameters[1]);
54
    }
55
}
56