Passed
Pull Request — master (#372)
by Valentin
04:35
created

ArrayChecker::of()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 6
c 1
b 0
f 0
nc 4
nop 2
dl 0
loc 13
rs 9.6111
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Validation\Checker;
6
7
use Spiral\Validation\AbstractChecker;
8
use Spiral\Validation\ValidationInterface;
9
10
class ArrayChecker extends AbstractChecker
11
{
12
    /** @var ValidationInterface */
13
    private $validation;
14
15
    public function __construct(ValidationInterface $validation)
16
    {
17
        $this->validation = $validation;
18
    }
19
20
    public function of($value, $checker): bool
21
    {
22
        if (!is_array($value) || empty($value)) {
23
            return false;
24
        }
25
26
        foreach ($value as $item) {
27
            if (!$this->validation->validate(compact('item'), ['item' => [$checker]])->isValid()) {
28
                return false;
29
            }
30
        }
31
32
        return true;
33
    }
34
}
35