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.

Magic::tailRecursion()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 4
c 0
b 0
f 0
nc 2
nop 2
dl 0
loc 8
ccs 0
cts 7
cp 0
crap 6
rs 10
1
<?php
2
/**
3
 * Class Magic
4
 *
5
 * @link https://www.icy2003.com/
6
 * @author icy2003 <[email protected]>
7
 * @copyright Copyright (c) 2017, icy2003
8
 */
9
10
namespace icy2003\php\ihelpers;
11
12
/**
13
 * 一个奇怪的类
14
 */
15
class Magic
16
{
17
    /**
18
     * 消除尾递归.
19
     *
20
     * @param callable $callback 使用匿名函数尾调用的函数
21
     * @param array    $params   函数参数
22
     *
23
     * @example
24
     *
25
     * 以斐波那契函数为例子
26
     * function factorial($n, $accumulator = 1)
27
     * {
28
     *     if (0 == $n) {
29
     *        return $accumulator;
30
     *     }
31
     *     return function () use ($n, $accumulator) {
32
     *        return factorial($n - 1, $accumulator * $n);
33
     *     };
34
     * }
35
     * Magic::tailRecursion('factorial', array(100));
36
     *
37
     * @return mixed
38
     */
39
    public static function tailRecursion($callback, $params)
40
    {
41
        $result = call_user_func_array($callback, $params);
42
        while (is_callable($result)) {
43
            $result = $result();
44
        }
45
46
        return $result;
47
    }
48
}
49