Passed
Push — main ( 36bb88...fbfcc4 )
by Alexandra
03:15
created

CombinationApprovals::verifyAllCombinations()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
nc 2
nop 2
dl 0
loc 11
ccs 6
cts 6
cp 1
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AHJ\ApprovalTests;
6
7
final class CombinationApprovals
8
{
9
    private Combinations $combinations;
10
11
    private Approvals $approvals;
12
13 1
    public static function create(): self
14
    {
15 1
        return new self(
16 1
            new Combinations(),
17 1
            Approvals::create()
18
        );
19
    }
20
21 1
    public function __construct(
22
        Combinations $combinations,
23
        Approvals $approvals
24
    ) {
25 1
        $this->combinations = $combinations;
26 1
        $this->approvals = $approvals;
27 1
    }
28
29 1
    public function verifyAllCombinations(callable $function, array $arguments): void
30
    {
31 1
        $inputCombinations = $this->combinations->getAllCombinations($arguments, []);
32
33 1
        $output = [];
34
35 1
        foreach ($inputCombinations as $combination) {
36 1
            $output = $this->extend($output, call_user_func($function, ...$combination));
37
        }
38
39 1
        $this->approvals->verifyList($inputCombinations, $output);
40 1
    }
41
42 1
    private function extend(array $first, array $second): array
43
    {
44 1
        foreach ($second as $value) {
45 1
            $first[] = $value;
46
        }
47
48 1
        return $first;
49
    }
50
}
51