Completed
Push — master ( bcac64...9b6ee4 )
by Nassif
11:39
created

Util   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 1
dl 0
loc 33
ccs 0
cts 20
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B varExport() 0 21 7
A keyValues() 0 8 2
1
<?php
2
3
namespace Nikaia\TranslationSheet;
4
5
use Illuminate\Support\Collection;
6
7
class Util
8
{
9
    public static function varExport($var, $indent = '')
10
    {
11
        switch (gettype($var)) {
12
            case 'string':
13
                return '"'.addcslashes($var, "\\\$\"\r\n\t\v\f").'"';
14
            case 'array':
15
                $indexed = array_keys($var) === range(0, count($var) - 1);
16
                $r = [];
17
                foreach ($var as $key => $value) {
18
                    $r[] = "$indent    "
19
                        .($indexed ? '' : self::varExport($key).' => ')
20
                        .self::varExport($value, "$indent    ");
21
                }
22
23
                return "[\n".implode(",\n", $r)."\n".$indent.']';
24
            case 'boolean':
25
                return $var ? 'true' : 'false';
26
            default:
27
                return var_export($var, true);
28
        }
29
    }
30
31
    public static function keyValues($values, $keys)
32
    {
33
        $values = $values instanceof Collection ? $values : new Collection($values);
34
35
        return $values->map(function ($values) use ($keys) {
36
            return array_combine($keys, $values);
37
        });
38
    }
39
}
40