Passed
Pull Request — master (#1)
by lee
03:01
created

AbstractTransformer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 8
c 1
b 0
f 0
dl 0
loc 21
ccs 8
cts 8
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A transform() 0 15 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