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

Meteorology::fetchToday()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
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 1
dl 0
loc 16
rs 9.8666
1
<?php
2
3
namespace icy2003\php\iapis;
4
5
use icy2003\php\iapis\Api;
6
use icy2003\php\ihelpers\Arrays;
7
use icy2003\php\ihelpers\Http;
8
use icy2003\php\ihelpers\Json;
9
10
/**
11
 * 气象(meteorology)接口
12
 */
13
class Meteorology extends Api
14
{
15
    /**
16
     * 获取省份代码
17
     *
18
     * @return static
19
     */
20
    public function fetchProvinces()
21
    {
22
        $this->fetchCitys();
23
        $this->_toArrayCall = function ($array) {
24
            return Arrays::columns($array, ['code', 'name']);
25
        };
26
27
        return $this;
28
    }
29
30
    /**
31
     * 获取城市列表
32
     *
33
     * @param string|null $provinceCode 省份代码
34
     *
35
     * @return static
36
     */
37
    public function fetchCitys($provinceCode = null)
38
    {
39
        $res = Http::get('http://www.nmc.cn/f/rest/province/' . $provinceCode);
40
        $this->_result = Json::decode($res);
0 ignored issues
show
Documentation Bug introduced by
It seems like icy2003\php\ihelpers\Json::decode($res) can also be of type false. 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...
41
        $this->_toArrayCall = function ($array) {
42
            return Arrays::columns($array, ['code', 'city', 'province']);
43
        };
44
45
        return $this;
46
    }
47
48
    /**
49
     * 获取天气状况
50
     * - publish_time:更新时间(2020-01-01 19:35)
51
     * - airpressure:气压(hPa)
52
     * - feelst:体感温度(℃)
53
     * - humidity:相对湿度(%)
54
     * - icomfort:舒适度
55
     *      - 温暖,较舒适:1
56
     *      - 舒适,最可接受:0
57
     *      - 凉爽,较舒适:-1
58
     *      - 凉,不舒适:-2
59
     *      - 冷,很不舒适:-3
60
     *      - 很冷,极不适应:-4
61
     * - info:天气(如:晴)
62
     * - rain:降水(mm)
63
     * - temperature:气温(℃)
64
     * - direct:风向(东南风)
65
     * - power:风强(微风、1 级……)
66
     *
67
     * @param string $cityId 城市 ID
68
     *
69
     * @return static
70
     */
71
    public function fetchWeather($cityId)
72
    {
73
        $res = Http::get('http://www.nmc.cn/f/rest/real/' . $cityId);
74
        $this->_result = Json::decode($res);
0 ignored issues
show
Documentation Bug introduced by
It seems like icy2003\php\ihelpers\Json::decode($res) can also be of type false. 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...
75
        $this->_toArrayCall = function ($array) {
76
            return Arrays::columns($array, [
77
                'publish_time',
78
                'airpressure' => 'weather.airpressure',
79
                'feelst' => 'weather.feelst',
80
                'humidity' => 'weather.humidity',
81
                'info' => 'weather.info',
82
                'rain'=>'weather.rain',
83
                'temperature' => 'weather.temperature',
84
                'direct' => 'wind.direct',
85
                'power' => 'wind.power',
86
            ], 1);
87
        };
88
89
        return $this;
90
    }
91
92
    /**
93
     * 空气质量
94
     * - forecasttime:发布时间(2020-01-01 19:00)
95
     * - aq:空气质量
96
     *      - 优:1
97
     *      - 良:2
98
     *      - 轻度污染:3
99
     *      - 中度污染:4
100
     * - text:空气质量文本
101
     *
102
     * @param string $cityId 城市 ID
103
     *
104
     * @return static
105
     */
106
    public function fetchAirQuality($cityId)
107
    {
108
        $res = Http::get('http://www.nmc.cn/f/rest/aqi/' . $cityId);
109
        $this->_result = Json::decode($res);
0 ignored issues
show
Documentation Bug introduced by
It seems like icy2003\php\ihelpers\Json::decode($res) can also be of type false. 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...
110
        $this->_toArrayCall = function ($array) {
111
            return Arrays::columns($array, [
112
                'forecasttime',
113
                'aq',
114
                'text'
115
            ], 1);
116
        };
117
118
        return $this;
119
    }
120
121
    /**
122
     * 今天 24 小时实况
123
     *  - time:时间(2020-01-01 20:00)
124
     *  - humidity:相对湿度(%)
125
     *  - pressure:气压(hPa)
126
     *  - rain:降水(mm)
127
     *  - temperature:温度(℃)
128
     *  - windDirection:风向(?)
129
     *  - windSpeed:风速(?)
130
     *
131
     * @param string $cityId 城市 ID
132
     *
133
     * @return static
134
     */
135
    public function fetchToday($cityId){
136
        $res = Http::get('http://www.nmc.cn/f/rest/passed/' . $cityId);
137
        $this->_result = Json::decode($res);
0 ignored issues
show
Documentation Bug introduced by
It seems like icy2003\php\ihelpers\Json::decode($res) can also be of type false. 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...
138
        $this->_toArrayCall = function ($array) {
139
            return Arrays::columns($array, [
140
                'time',
141
                'humidity',
142
                'pressure',
143
                'rain'=>'rain1h',
144
                'temperature',
145
                'windDirection',
146
                'windSpeed'
147
            ], 2);
148
        };
149
150
        return $this;
151
    }
152
}
153