Passed
Push — master ( 5153a0...c7b3db )
by Josh
03:56
created

HasValidFields::matches()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 6
nc 4
nop 1
dl 0
loc 13
ccs 7
cts 7
cp 1
crap 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace JoshGaber\NovaUnit\Constraints;
4
5
use Laravel\Nova\Fields\Field;
6
use PHPUnit\Framework\Constraint\Constraint;
7
8
class HasValidFields extends Constraint
9
{
10
    /**
11
     * {@inheritdoc}
12
     */
13 4
    public function toString(): string
14
    {
15 4
        return 'contains valid fields only';
16
    }
17
18 6
    public function matches($other): bool
19
    {
20 6
        if (! \is_array($other)) {
21 2
            return false;
22
        }
23
24 4
        foreach ($other as $field) {
25 4
            if (! $field instanceof Field) {
26 4
                return false;
27
            }
28
        }
29
30 2
        return true;
31
    }
32
}
33