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

ArrayChecker   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 23
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A of() 0 13 5
A __construct() 0 3 1
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