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

Validator   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 8
Bugs 0 Features 0
Metric Value
wmc 7
eloc 12
c 8
b 0
f 0
dl 0
loc 29
ccs 12
cts 12
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B check() 0 22 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