HasField   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 22
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A toString() 0 3 1
A __construct() 0 4 1
A matches() 0 3 1
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