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.
Passed
Pull Request — master (#23)
by t
03:08
created

Api::mobile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 11
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 16
rs 9.9

1 Method

Rating   Name   Duplication   Size   Complexity  
A Api::getResult() 0 10 3
1
<?php
2
/**
3
 * Class Api
4
 *
5
 * @link https://www.icy2003.com/
6
 * @author icy2003 <[email protected]>
7
 * @copyright Copyright (c) 2017, icy2003
8
 */
9
namespace icy2003\php\iapis;
10
11
use Exception;
12
use icy2003\php\I;
13
use icy2003\php\ihelpers\Arrays;
14
use icy2003\php\ihelpers\Http;
15
use icy2003\php\ihelpers\Json;
16
17
/**
18
 * 搜集的 API 接口
19
 */
20
class Api
21
{
22
23
    /**
24
     * API 返回原始数组
25
     *
26
     * @var array
27
     */
28
    protected $_result = [];
29
30
    /**
31
     * 成功判断
32
     *
33
     * @return boolean
34
     */
35
    public function isSuccess()
36
    {
37
        return true;
38
    }
39
40
    /**
41
     * 返回错误信息
42
     *
43
     * @return array|string
44
     */
45
    public function getError()
46
    {
47
        return [];
48
    }
49
50
    /**
51
     * 获取结果
52
     *
53
     * @param string $key 如果有此参数,表示取某个属性
54
     *
55
     * @return mixed
56
     */
57
    public function getResult($key = null)
58
    {
59
        if ($this->isSuccess()) {
60
            if (null === $key) {
61
                return $this->_result;
62
            } else {
63
                return I::get($this->_result, $key);
64
            }
65
        }
66
        throw new Exception($this->getError());
0 ignored issues
show
Bug introduced by
$this->getError() of type array is incompatible with the type string expected by parameter $message of Exception::__construct(). ( Ignorable by Annotation )

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

66
        throw new Exception(/** @scrutinizer ignore-type */ $this->getError());
Loading history...
67
    }
68
69
    /**
70
     * toArray 时调用的函数
71
     *
72
     * @var callback
73
     */
74
    protected $_toArrayCall;
75
76
    /**
77
     * 智能返回有效数据
78
     *
79
     * - 如果数据缺失,请使用 getResult() 获取原始数据
80
     *
81
     * @return array
82
     */
83
    public function toArray()
84
    {
85
        return (array)I::call($this->_toArrayCall, [$this->getResult()]);
86
    }
87
88
    /**
89
     * 选项列表
90
     *
91
     * @var array
92
     */
93
    protected $_options = [];
94
95
    /**
96
     * 设置选项
97
     *
98
     * @param array $options
99
     *
100
     * @return static
101
     */
102
    public function setOptions($options)
103
    {
104
        $this->_options = Arrays::merge($this->_options, $options);
105
        return $this;
106
    }
107
108
    /**
109
     * toString 魔术方法
110
     *
111
     * @return string
112
     */
113
    public function __toString()
114
    {
115
        return Json::encode($this->_result);
116
    }
117
}
118