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

ConvertToTree::fromFlattened()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 4
nop 2
dl 0
loc 10
ccs 5
cts 5
cp 1
crap 3
rs 9.4285
c 0
b 0
f 0
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
}