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

Validator::check()   B

Complexity

Conditions 7
Paths 5

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 7.7656

Importance

Changes 7
Bugs 0 Features 0
Metric Value
eloc 11
c 7
b 0
f 0
dl 0
loc 22
ccs 9
cts 12
cp 0.75
rs 8.8333
cc 7
nc 5
nop 1
crap 7.7656
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