GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 6fcb7a...fcde01 )
by t
06:59 queued 04:42
created

Tree   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 36
ccs 0
cts 22
cp 0
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A expand() 0 22 5
1
<?php
2
/**
3
 * Class Tree
4
 *
5
 * @link https://www.icy2003.com/
6
 * @author icy2003 <[email protected]>
7
 * @copyright Copyright (c) 2017, icy2003
8
 */
9
namespace icy2003\php\ihelpers;
10
11
use icy2003\php\I;
12
13
/**
14
 * 树操作
15
 */
16
class Tree
17
{
18
    /**
19
     * 展开一棵树
20
     *
21
     * - 展开后为一维数组,并且靠后的元素的 pid 对应 id 的元素一定在靠前的元素里存在
22
     *
23
     * @param array $array
24
     * @param string $rootId 根节点 ID
25
     * @param string $idName ID 名
26
     * @param string $pidName PID 名
27
     *
28
     * @return array
29
     */
30
    public static function expand($array, $rootId = '0', $idName = 'id', $pidName = 'pid')
31
    {
32
        $array = Arrays::indexBy($array, $idName);
33
        $array2 = Arrays::indexBy($array, $pidName, true);
34
        $pidArray = [$rootId];
35
        $return = [];
36
        while (true) {
37
            $temp = [];
38
            foreach ($pidArray as $pid) {
39
                $rows = I::get($array2, $pid, []);
40
                if (empty($rows)) {
41
                    continue;
42
                }
43
                $return = Arrays::merge($return, $rows);
44
                $temp = Arrays::merge($temp, Arrays::column($rows, $idName));
0 ignored issues
show
Bug introduced by
It seems like $rows can also be of type string; however, parameter $array of icy2003\php\ihelpers\Arrays::column() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

44
                $temp = Arrays::merge($temp, Arrays::column(/** @scrutinizer ignore-type */ $rows, $idName));
Loading history...
45
            }
46
            if (empty($temp)) {
47
                break;
48
            }
49
            $pidArray = $temp;
50
        }
51
        return $return;
52
    }
53
}
54