HasValidFields   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 30
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A toString() 0 3 1
A __construct() 0 3 1
A matches() 0 13 6
1
<?php
2
3
namespace JoshGaber\NovaUnit\Constraints;
4
5
use Laravel\Nova\Fields\Field;
6
use Laravel\Nova\Panel;
7
use PHPUnit\Framework\Constraint\Constraint;
8
9
class HasValidFields extends Constraint
10
{
11
    private $allowPanels;
12
13 5
    public function __construct(bool $allowPanels = false)
14
    {
15 5
        $this->allowPanels = $allowPanels;
16 5
    }
17
18
    /**
19
     * {@inheritdoc}
20
     */
21 2
    public function toString(): string
22
    {
23 2
        return 'contains valid fields only';
24
    }
25
26 4
    public function matches($other): bool
27
    {
28 4
        foreach ($other as $field) {
29 4
            if ($this->allowPanels && $field instanceof Panel) {
30 2
                if (! $this->matches($field->data)) {
31 2
                    return false;
32
                }
33 4
            } elseif (! $field instanceof Field) {
34 4
                return false;
35
            }
36
        }
37
38 3
        return true;
39
    }
40
}
41