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

ArrayChecker::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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