|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Services\Contents\It\Event; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* ConnpassEventService. |
|
7
|
|
|
* |
|
8
|
|
|
* ConnpassEventを扱うService |
|
9
|
|
|
*/ |
|
10
|
|
|
class ConnpassEventService |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* Create a new instance. |
|
14
|
|
|
*/ |
|
15
|
|
|
public function __construct() |
|
16
|
|
|
{ |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* ConnpassAPIにリクエストするURLの生成 |
|
21
|
|
|
* @param リクエストパラム |
|
22
|
|
|
* @return string ConnpassAPIにリクエストするURL |
|
23
|
|
|
*/ |
|
24
|
|
|
private function _createRequestConnpassApiUrl($param) { |
|
25
|
|
|
$year = $param['year']; |
|
26
|
|
|
$month = $param['month']; |
|
27
|
|
|
$count = $param['count']; |
|
|
|
|
|
|
28
|
|
|
$firstMonth = date("$year-$month-01"); |
|
|
|
|
|
|
29
|
|
|
$lastMonth = date("$year-$month-t"); |
|
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
return "http://connpass.com/api/v1/event/?keyword=python"; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* 今年の年数字を取得 |
|
36
|
|
|
* |
|
37
|
|
|
* @param array $param リクエストパラメータ |
|
38
|
|
|
* @return string 今年 |
|
39
|
|
|
*/ |
|
40
|
|
|
public function getYear($param) { |
|
41
|
|
|
if (isset($param['year']) && is_numeric($param['year'])){ |
|
42
|
|
|
return $param['year']; |
|
43
|
|
|
} |
|
44
|
|
|
return date('Y'); |
|
45
|
|
|
} |
|
46
|
|
|
/** |
|
47
|
|
|
* 今月の月数字を取得 |
|
48
|
|
|
* |
|
49
|
|
|
* @param array $param リクエストパラメータ |
|
50
|
|
|
* @return string 今月 |
|
51
|
|
|
*/ |
|
52
|
|
|
public function getMonth($param) { |
|
53
|
|
|
if (isset($param['month']) && is_numeric($param['month'])){ |
|
54
|
|
|
return $param['month']; |
|
55
|
|
|
} |
|
56
|
|
|
return date('m'); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* connpassのAPIからJSONを取得する. |
|
61
|
|
|
* |
|
62
|
|
|
* @param array リクエストパラム |
|
63
|
|
|
* @return array connpassのイベントを取得 |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getConnpassApiOneMonthEventJson($param) |
|
66
|
|
|
{ |
|
67
|
|
|
$context = stream_context_create([ |
|
68
|
|
|
'http' => array('ignore_errors' => true) |
|
69
|
|
|
]); |
|
70
|
|
|
$response = file_get_contents( |
|
71
|
|
|
$this->_createRequestConnpassApiUrl($param), |
|
72
|
|
|
false, |
|
73
|
|
|
$context |
|
74
|
|
|
); |
|
75
|
|
|
|
|
76
|
|
|
// ステータスコードを取得する |
|
77
|
|
|
preg_match( |
|
78
|
|
|
'/HTTP\/1\.[0|1|x] ([0-9]{3})/', |
|
79
|
|
|
$http_response_header[0], |
|
80
|
|
|
$matches |
|
81
|
|
|
); |
|
82
|
|
|
$status_code = $matches[1]; |
|
83
|
|
|
|
|
84
|
|
|
// APIのデータ取得用変数 |
|
85
|
|
|
$eventData = []; |
|
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
switch ($status_code) { |
|
88
|
|
|
case '200': |
|
89
|
|
|
// JSONファイルは配列に変換しておく |
|
90
|
|
|
$jsonData = mb_convert_encoding($response, 'UTF8', 'auto'); |
|
91
|
|
|
$eventData = json_decode($jsonData, true); |
|
92
|
|
|
break; |
|
93
|
|
|
case '403'; |
|
|
|
|
|
|
94
|
|
|
// 403の場合 |
|
95
|
|
|
$eventData = [ |
|
96
|
|
|
'status' => '403' |
|
97
|
|
|
]; |
|
98
|
|
|
break; |
|
99
|
|
|
case '404': |
|
100
|
|
|
// 404の場合 |
|
101
|
|
|
$eventData = [ |
|
102
|
|
|
'status' => '404' |
|
103
|
|
|
]; |
|
104
|
|
|
break; |
|
105
|
|
|
default: |
|
106
|
|
|
$eventData = [ |
|
107
|
|
|
'status' => 'error' |
|
108
|
|
|
]; |
|
109
|
|
|
break; |
|
110
|
|
|
} |
|
111
|
|
|
return $eventData; |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.