IsActionResponseType   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 26
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A toString() 0 3 1
A matches() 0 9 1
1
<?php
2
3
namespace JoshGaber\NovaUnit\Constraints;
4
5
use Laravel\Nova\Actions\Action;
6
use PHPUnit\Framework\Constraint\Constraint;
7
8
class IsActionResponseType extends Constraint
9
{
10
    private $actionType;
11
12 15
    public function __construct($actionType)
13
    {
14 15
        $this->actionType = $actionType;
15 15
    }
16
17
    /**
18
     * {@inheritdoc}
19
     */
20 8
    public function toString(): string
21
    {
22 8
        return \sprintf('matches the "%s" Action response', $this->actionType);
23
    }
24
25 14
    public function matches($response): bool
26
    {
27 14
        $structure = \array_keys(\call_user_func([Action::class, $this->actionType], 'param 1', 'param 2'));
28 14
        $responseKeys = \array_keys($response);
29
30 14
        \sort($structure);
31 14
        \sort($responseKeys);
32
33 14
        return $structure === $responseKeys;
34
    }
35
}
36