Test Failed
Push — master ( e3b206...99d1d4 )
by Enjoys
02:23 queued 23s
created

Validator   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 75%

Importance

Changes 8
Bugs 0 Features 0
Metric Value
wmc 7
eloc 12
c 8
b 0
f 0
dl 0
loc 29
ccs 9
cts 12
cp 0.75
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 2
    public static function check(array $elements): bool
18
    {
19 2
        $_validate = true;
20
21 2
        foreach ($elements as $element) {
22 2
            if ($element instanceof Group) {
23
                $_validate = (!self::check($element->getElements())) ? false : $_validate;
24
                continue;
25
            }
26
27 2
            if (!($element instanceof Ruleable)) {
28
                continue;
29
            }
30
31
32 2
            foreach ($element->getRules() as $rule) {
33 2
                if (!$rule->validate($element)) {
34 1
                    $_validate = false;
35
                }
36
            }
37
        }
38 2
        return $_validate;
39
    }
40
}
41