Completed
Push — master ( 8c886d...91409e )
by Ben
03:10
created

ConvertToTree   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A fromFlattened() 0 10 3
1
<?php
2
3
4
namespace Thinktomorrow\Squanto\Services;
5
6
7
final class ConvertToTree
8
{
9
    /**
10
     * convert flat array of key-value pairs to multidimensional array e.g. foo.bar => 'translation of foo' to [foo => [ bar => 'translation of foo' ]]
11
     *
12
     * @param array $lines
13
     * @return array
14
     */
15 4
    public static function fromFlattened(array $lines = [], $includePage = true)
16
    {
17 4
        $translations = [];
18
19 4
        foreach ($lines as $key => $value) {
20 4
            array_set($translations, $key, $value);
21
        }
22
23 4
        return $includePage ? $translations : reset($translations);
24
    }
25
}