Completed
Push — master ( 89313f...8b5ee1 )
by Nassif
02:33
created

Util   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
wmc 11
lcom 0
cbo 0
dl 0
loc 44
ccs 21
cts 24
cp 0.875
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
B varExport() 0 21 7
A asArray() 0 10 2
A keyValues() 0 8 2
1
<?php
2
3
namespace Nikaia\TranslationSheet;
4
5
use Illuminate\Support\Collection;
6
7
class Util
8
{
9 2
    public static function varExport($var, $indent = '')
10
    {
11 2
        switch (gettype($var)) {
12 2
            case 'string':
13 2
                return '"'.addcslashes($var, "\\\$\"\r\n\t\v\f").'"';
14 2
            case 'array':
15 2
                $indexed = array_keys($var) === range(0, count($var) - 1);
16 2
                $r = [];
17 2
                foreach ($var as $key => $value) {
18 2
                    $r[] = "$indent    "
19 2
                        .($indexed ? '' : self::varExport($key).' => ')
20 2
                        .self::varExport($value, "$indent    ");
21
                }
22
23 2
                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 2
    public static function keyValues($values, $keys)
32
    {
33 2
        $values = $values instanceof Collection ? $values : new Collection($values);
0 ignored issues
show
Bug introduced by
The class Illuminate\Support\Collection does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
34
35
        return $values->map(function ($values) use ($keys) {
36 1
            return array_combine($keys, $values);
37 2
        });
38
    }
39
40 5
    public static function asArray($value)
41
    {
42 5
        if (is_array($value)) {
43 3
            return $value;
44
        }
45
46
        return array_filter(array_map(function ($item) {
47 3
            return trim($item);
48 3
        }, explode(',', $value)));
49
    }
50
}
51