Passed
Push — master ( 80f6a8...d3e0b5 )
by Koldo
02:40
created

ArrayValidator::check()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 12
nc 1
nop 2
dl 0
loc 17
ccs 12
cts 12
cp 1
crap 2
rs 9.8666
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Validator;
6
7
use Assert\Assertion;
8
9
class ArrayValidator
10
{
11 5
    public static function check(array $fields, array $rules): void
12
    {
13
        array_walk($fields, function ($value, $field) use ($rules) : void {
14 5
            Assertion::keyExists($rules, $field);
15 5
            array_map(
16
                function ($validationRule) use ($value) : void {
17 5
                    $method = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $method is dead and can be removed.
Loading history...
18 5
                    $param = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $param is dead and can be removed.
Loading history...
19 5
                    $validation = explode(':', $validationRule);
20
21 5
                    list($method, $param) = (array_key_exists(1, $validation)
22 3
                        ? [$validation[0], $validation[1]]
23 5
                        : [$validation[0], null]);
24
25 5
                    call_user_func_array([Assertion::class, $method], [$value, $param]);
26 5
                },
27 5
                explode('|', $rules[$field])
28
            );
29 5
        });
30 1
    }
31
}
32