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

HasField::toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
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 HasField extends Constraint
9
{
10
    private $fieldName;
11
12 8
    public function __construct(string $fieldName)
13
    {
14 8
        $this->fieldName = $fieldName;
15 8
    }
16
17
    /**
18
     * {@inheritdoc}
19
     */
20 4
    public function toString(): string
21
    {
22 4
        return \sprintf('contains field "%s"', $this->fieldName);
23
    }
24
25 8
    public function matches($other): bool
26
    {
27 8
        foreach ($other as $field) {
28 8
            if ($field instanceof Field) {
29
                if (
30 8
                    $field->attribute === $this->fieldName ||
31 8
                    \mb_strtolower($field->name) === \mb_strtolower($this->fieldName)
32
                ) {
33 8
                    return true;
34
                }
35
            }
36
        }
37
38 4
        return false;
39
    }
40
}
41