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:07
created

Meteorology::fetchProvinces()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 8
rs 10
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
        $this->_result = (array)Json::decode(Http::get('http://www.nmc.cn/f/rest/province/' . $provinceCode));
40
        $this->_toArrayCall = function ($array) {
41
            return Arrays::columns($array, ['code', 'city', 'province']);
42
        };
43
44
        return $this;
45
    }
46
47
    /**
48
     * 获取天气状况
49
     * - publish_time:更新时间(2020-01-01 19:35)
50
     * - airpressure:气压(hPa)
51
     * - feelst:体感温度(℃)
52
     * - humidity:相对湿度(%)
53
     * - icomfort:舒适度
54
     *      - 温暖,较舒适:1
55
     *      - 舒适,最可接受:0
56
     *      - 凉爽,较舒适:-1
57
     *      - 凉,不舒适:-2
58
     *      - 冷,很不舒适:-3
59
     *      - 很冷,极不适应:-4
60
     * - info:天气(如:晴)
61
     * - rain:降水(mm)
62
     * - temperature:气温(℃)
63
     * - direct:风向(东南风)
64
     * - power:风强(微风、1 级……)
65
     *
66
     * @param string $cityId 城市 ID
67
     *
68
     * @return static
69
     */
70
    public function fetchWeather($cityId)
71
    {
72
        $this->_result = (array)Json::decode(Http::get('http://www.nmc.cn/f/rest/real/' . $cityId));
73
        $this->_toArrayCall = function ($array) {
74
            return Arrays::columns($array, [
75
                'publish_time',
76
                'airpressure' => 'weather.airpressure',
77
                'feelst' => 'weather.feelst',
78
                'humidity' => 'weather.humidity',
79
                'info' => 'weather.info',
80
                'rain'=>'weather.rain',
81
                'temperature' => 'weather.temperature',
82
                'direct' => 'wind.direct',
83
                'power' => 'wind.power',
84
            ], 1);
85
        };
86
87
        return $this;
88
    }
89
90
    /**
91
     * 空气质量
92
     * - forecasttime:发布时间(2020-01-01 19:00)
93
     * - aq:空气质量
94
     *      - 优:1
95
     *      - 良:2
96
     *      - 轻度污染:3
97
     *      - 中度污染:4
98
     * - text:空气质量文本
99
     *
100
     * @param string $cityId 城市 ID
101
     *
102
     * @return static
103
     */
104
    public function fetchAirQuality($cityId)
105
    {
106
        $this->_result = (array)Json::decode(Http::get('http://www.nmc.cn/f/rest/aqi/' . $cityId));
107
        $this->_toArrayCall = function ($array) {
108
            return Arrays::columns($array, [
109
                'forecasttime',
110
                'aq',
111
                'text'
112
            ], 1);
113
        };
114
115
        return $this;
116
    }
117
118
    /**
119
     * 今天 24 小时实况
120
     *  - time:时间(2020-01-01 20:00)
121
     *  - humidity:相对湿度(%)
122
     *  - pressure:气压(hPa)
123
     *  - rain:降水(mm)
124
     *  - temperature:温度(℃)
125
     *  - windDirection:风向(?)
126
     *  - windSpeed:风速(?)
127
     *
128
     * @param string $cityId 城市 ID
129
     *
130
     * @return static
131
     */
132
    public function fetchToday($cityId){
133
        $this->_result = (array)Json::decode(Http::get('http://www.nmc.cn/f/rest/passed/' . $cityId));
134
        $this->_toArrayCall = function ($array) {
135
            return Arrays::columns($array, [
136
                'time',
137
                'humidity',
138
                'pressure',
139
                'rain'=>'rain1h',
140
                'temperature',
141
                'windDirection',
142
                'windSpeed'
143
            ], 2);
144
        };
145
146
        return $this;
147
    }
148
}
149