IsActionResponseType::__construct()   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 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