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

CombinationApprovals   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
dl 0
loc 42
ccs 19
cts 19
cp 1
rs 10
c 1
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A verifyAllCombinations() 0 11 2
A create() 0 5 1
A extend() 0 7 2
A __construct() 0 6 1
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