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

VideoResource::fetchSearchFirst()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 12
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 18
rs 9.8666
1
<?php
2
3
namespace icy2003\php\iapis;
4
5
use icy2003\php\I;
6
use icy2003\php\ihelpers\Arrays;
7
use icy2003\php\ihelpers\Http;
8
use icy2003\php\ihelpers\Json;
9
use icy2003\php\ihelpers\Strings;
10
11
/**
12
 * api 来自“今日影视”,请勿做商业用途,侵删
13
 */
14
class VideoResource extends Api
15
{
16
17
    /**
18
     * 按首字母查询视频
19
     *
20
     * @param string $firsts 首字母字符串,如果是中文,则强制转成首字母
21
     * @param integer $page
22
     * @param integer $pageSize
23
     *
24
     * @return static
25
     */
26
    public function fetchSearchFirst($firsts, $page = 0, $pageSize = 20)
27
    {
28
        $res = Http::get('http://api.jinsapi.com/yingshi/search', [
29
            'keys' => Strings::toPinyinFirst($firsts),
30
            'page' => $page,
31
            'pageSize' => $pageSize,
32
        ]);
33
        $this->_result = Json::get($res, 'data', []);
0 ignored issues
show
Documentation Bug introduced by
It seems like icy2003\php\ihelpers\Jso...($res, 'data', array()) can also be of type false or string. However, the property $_result is declared as type array. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
34
        $this->_toArrayCall = function ($array) {
35
            return Arrays::columns($array, [
36
                'id' => 'd_id',
37
                'name' => 'd_name',
38
                'picture' => 'd_pic',
39
                'tag' => 'd_remarks',
40
            ], 2);
41
        };
42
43
        return $this;
44
    }
45
46
    /**
47
     * 按关键字查询视频
48
     *
49
     * @param string $keywords
50
     * @param integer $page
51
     * @param integer $pageSize
52
     *
53
     * @return static
54
     */
55
    public function fetchSearch($keywords, $page = 0, $pageSize = 20)
56
    {
57
        $res = Http::post('http://api.jinsapi.com/yingshi/searchForHanZi', [
58
            'keys' => $keywords,
59
            'page' => $page,
60
            'pageSize' => $pageSize,
61
        ]);
62
        $this->_result = Json::get($res, 'data', []);
0 ignored issues
show
Documentation Bug introduced by
It seems like icy2003\php\ihelpers\Jso...($res, 'data', array()) can also be of type false or string. However, the property $_result is declared as type array. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
63
        $this->_toArrayCall = function ($array) {
64
            return Arrays::columns($array, [
65
                'id' => 'd_id',
66
                'name' => 'd_name',
67
                'picture' => 'd_pic',
68
                'tag' => 'd_remarks',
69
            ], 2);
70
        };
71
72
        return $this;
73
    }
74
75
    /**
76
     * 根据视频 ID 获取视频信息
77
     *
78
     * @param integer $id
79
     *
80
     * @return static
81
     */
82
    public function fetchById($id)
83
    {
84
        $res = Http::get('http://api.jinsapi.com/yingshi/getVodById', [
85
            'd_id' => $id,
86
        ]);
87
        $this->_result = Json::get($res, 'data', []);
0 ignored issues
show
Documentation Bug introduced by
It seems like icy2003\php\ihelpers\Jso...($res, 'data', array()) can also be of type false or string. However, the property $_result is declared as type array. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
88
        $this->_toArrayCall = function ($array) {
89
            return Arrays::columns($array, [
90
                'id' => 'd_id',
91
                'name' => 'd_name',
92
                'picture' => 'd_pic',
93
                'actors' => 'd_starring',
94
                'tag' => 'd_remarks',
95
                'area' => 'd_area',
96
                'lang' => 'd_lang',
97
                'year' => 'd_year',
98
                'description' => 'd_content',
99
                'episodes' => function ($array) {
100
                    $episodes = explode('#', I::get($array, 'd_playurl'));
0 ignored issues
show
Bug introduced by
It seems like icy2003\php\I::get($array, 'd_playurl') can also be of type false; however, parameter $string of explode() does only seem to accept string, 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

100
                    $episodes = explode('#', /** @scrutinizer ignore-type */ I::get($array, 'd_playurl'));
Loading history...
101
                    return Arrays::explode('$', $episodes);
102
                },
103
            ], 1);
104
        };
105
106
        return $this;
107
    }
108
109
}
110