Completed
Push — master ( 8ff8a5...9a5f44 )
by Luka
05:09
created

Helper   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 26
ccs 9
cts 9
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B toArray() 0 17 6
1
<?php
2
3
namespace Teto\Object;
4
5
/**
6
 * Interface for array compatible object
7
 *
8
 * @author    USAMI Kenta <[email protected]>
9
 * @copyright 2016 Baguette HQ
10
 * @license   http://www.apache.org/licenses/LICENSE-2.0
11
 */
12
class Helper
13
{
14
    /**
15
     * Convert object to array recursive
16
     *
17
     * @param  mixed $ary_or_obj
18
     * @return array|null
19
     */
20 16
    public static function toArray($ary_or_obj, $is_toplevel = true)
21
    {
22 16
        if ($ary_or_obj instanceof ToArrayInterface) {
23 5
            return $ary_or_obj->toArray();
24
        }
25
26 12
        if (!is_array($ary_or_obj) && !($ary_or_obj instanceof \Traversable)) {
27 10
            return $is_toplevel ? null : $ary_or_obj;
28
        }
29
30 9
        $array = [];
31 9
        foreach ($ary_or_obj as $i => $elm) {
32 7
            $array[$i] = Helper::toArray($elm, false);
33
        }
34
35 9
        return $array;
36
    }
37
}
38