KeysToCamelCaseWalker   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 14
dl 0
loc 26
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toCamelCase() 0 7 2
A walk() 0 15 3
1
<?php
2
declare(strict_types=1);
3
4
namespace ReadModel\Walker;
5
6
class KeysToCamelCaseWalker implements ResultWalker
7
{
8 1
    public function walk(array $result): array
9
    {
10 1
        $camelCased = [];
11
12 1
        array_walk($result, function ($value, $key) use (&$camelCased) {
13 1
            $key = is_string($key) ? $this->toCamelCase($key) : $key;
14
15 1
            if (is_array($value)) {
16 1
                $camelCased[$key] = $this->walk($value);
17
            } else {
18 1
                $camelCased[$key] = $value;
19
            }
20 1
        }, array_keys($result));
21
22 1
        return $camelCased;
23
    }
24
25
    private function toCamelCase(string $value): string
26
    {
27 1
        $camelCasedName = preg_replace_callback('/(^|_|\.)+(.)/', function ($match) {
28 1
            return ('.' === $match[1] ? '_' : '').strtoupper($match[2]);
29 1
        }, $value);
30
31 1
        return lcfirst($camelCasedName);
32
    }
33
}
34