AbstractTransformer::transform()   A
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 15
ccs 8
cts 8
cp 1
rs 10
cc 4
nc 5
nop 1
crap 4
1
<?php
2
3
namespace ArrayKeysCaseTransform\Transformer;
4
5
abstract class AbstractTransformer
6
{
7
8 5
    public function transform(array $values) : array
9
    {
10 5
        $arrayFormatted = [];
11
12 5
        foreach ($values as $key => $value) {
13 2
            if (\is_array($value)) {
14 2
                $value = $this->transform($value);
15
            }
16
17 2
            $keyFormatted = \is_string($key) ? $this->format($key) : $key;
18
19 2
            $arrayFormatted[$keyFormatted] = $value;
20
        }
21
22 5
        return $arrayFormatted;
23
    }
24
25
    abstract protected function format(string $key) : string;
26
}
27