Util   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
lcom 0
cbo 0
dl 0
loc 45
ccs 23
cts 23
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B toPhp() 0 23 5
A typeOf() 0 4 2
1
<?php
2
/**
3
 * For licensing information, please see the LICENSE file accompanied with this file.
4
 *
5
 * @author Gerard van Helden <[email protected]>
6
 * @copyright 2012 Gerard van Helden <http://melp.nl>
7
 */
8
9
namespace Zicht\Tool;
10
11
12
/**
13
 * Utility container
14
 */
15
final class Util
16
{
17
    /**
18
     * A wrapper for var_export, having list-style arrays (0-indexed incremental keys) compile without the keys in
19
     * the code.
20
     *
21
     * @param mixed $var
22
     * @return string
23
     */
24 1
    public static function toPhp($var)
25
    {
26 1
        switch (gettype($var)) {
27 1
            case 'array':
28 1
                $skipKeys = (range(0, count($var) - 1) === array_keys($var));
29 1
                $ret = 'array(';
30 1
                $i = 0;
31 1
                foreach ($var as $key => $value) {
32 1
                    if ($i++ > 0) {
33 1
                        $ret .= ', ';
34 1
                    }
35 1
                    if (!$skipKeys) {
36 1
                        $ret .= self::toPhp($key) . ' => ';
37 1
                    }
38 1
                    $ret .= self::toPhp($value);
39 1
                }
40 1
                $ret .= ')';
41 1
                break;
42 1
            default:
43 1
                $ret = var_export($var, true);
44 1
        }
45 1
        return $ret;
46
    }
47
48
49
    /**
50
     * Returns the type of the variable, and it's class if it's an object.
51
     *
52
     * @param mixed $what
53
     * @return string
54
     */
55 1
    public static function typeOf($what)
56
    {
57 1
        return is_object($what) ? get_class($what) : gettype($what);
58
    }
59
}