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

ArrayValidator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 19
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A check() 0 17 2
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