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

ReceivedMap::create()   B

Complexity

Conditions 7
Paths 25

Size

Total Lines 29
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 7

Importance

Changes 0
Metric Value
cc 7
eloc 16
nc 25
nop 2
dl 0
loc 29
ccs 17
cts 17
cp 1
crap 7
rs 8.8333
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AHJ\ApprovalTests;
6
7
final class ReceivedMap
8
{
9 5
    public function create(array $input, array $output): string
10
    {
11 5
        $received = [];
12
13 5
        foreach ($input as $inputKey => $inputValue) {
14 5
            if ('array' === gettype($inputValue)) {
15 2
                $received[$inputKey] = '[';
16 2
                $received[$inputKey] .= implode(', ', $inputValue);
17 2
                $received[$inputKey] .= '] -> ';
18
            }
19
            // TODO: make sure this works for objects which do not have a __toString method
20 5
            if ('object' === gettype($inputValue)) {
21 3
                $received[$inputKey] = '[' . $inputValue . '] -> ';
0 ignored issues
show
Bug introduced by
Are you sure $inputValue of type object can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

21
                $received[$inputKey] = '[' . /** @scrutinizer ignore-type */ $inputValue . '] -> ';
Loading history...
22
            }
23
        }
24
25 5
        foreach ($output as $outputKey => $outputValue) {
26 5
            if ('array' === gettype($outputValue)) {
27 1
                $received[$outputKey] = $received[$outputKey] . '[';
28 1
                $received[$outputKey] .= implode(', ', $outputValue);
29 1
                $received[$outputKey] .= ']';
30
            }
31
32 5
            if ('object' === gettype($outputValue)) {
33 4
                $received[$outputKey] = $received[$outputKey] . '[' . $outputValue . ']';
0 ignored issues
show
Bug introduced by
Are you sure $outputValue of type object can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

33
                $received[$outputKey] = $received[$outputKey] . '[' . /** @scrutinizer ignore-type */ $outputValue . ']';
Loading history...
34
            }
35
        }
36
37 5
        return implode("\n", $received);
38
    }
39
}
40