HasField::matches()   A
last analyzed

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 1
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 JoshGaber\NovaUnit\Fields\FieldHelper;
6
use Laravel\Nova\Fields\Field;
7
use PHPUnit\Framework\Constraint\Constraint;
8
9
class HasField extends Constraint
10
{
11
    private $fieldName;
12
    private $allowPanels;
13
14 10
    public function __construct(string $fieldName, bool $allowPanels = false)
15
    {
16 10
        $this->fieldName = $fieldName;
17 10
        $this->allowPanels = $allowPanels;
18 10
    }
19
20
    /**
21
     * {@inheritdoc}
22
     */
23 4
    public function toString(): string
24
    {
25 4
        return \sprintf('contains field "%s"', $this->fieldName);
26
    }
27
28 10
    public function matches($other): bool
29
    {
30 10
        return FieldHelper::findField($other, $this->fieldName, $this->allowPanels) instanceof Field;
31
    }
32
}
33