Passed
Push — master ( 99d1d4...64b5d9 )
by Enjoys
15:28
created

Validator::check()   B

Complexity

Conditions 7
Paths 5

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 7

Importance

Changes 7
Bugs 0 Features 0
Metric Value
eloc 11
c 7
b 0
f 0
dl 0
loc 22
ccs 12
cts 12
cp 1
rs 8.8333
cc 7
nc 5
nop 1
crap 7
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Enjoys\Forms;
6
7
use Enjoys\Forms\Elements\Group;
8
use Enjoys\Forms\Interfaces\Ruleable;
9
10
class Validator
11
{
12
    /**
13
     * Валидация формы
14
     * @param Element[] $elements
15
     * @return bool
16
     */
17 47
    public static function check(array $elements): bool
18
    {
19 47
        $_validate = true;
20
21 47
        foreach ($elements as $element) {
22 46
            if ($element instanceof Group) {
23 3
                $_validate = (!self::check($element->getElements())) ? false : $_validate;
24 3
                continue;
25
            }
26
27 46
            if (!($element instanceof Ruleable)) {
28 1
                continue;
29
            }
30
31
32 46
            foreach ($element->getRules() as $rule) {
33 45
                if (!$rule->validate($element)) {
34 20
                    $_validate = false;
35
                }
36
            }
37
        }
38 47
        return $_validate;
39
    }
40
}
41