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.

ConnpassEventService   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 104
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 12
c 2
b 0
f 0
lcom 0
cbo 0
dl 0
loc 104
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A _createRequestConnpassApiUrl() 0 9 1
A getYear() 0 6 3
A getMonth() 0 6 3
B getConnpassApiOneMonthEventJson() 0 48 4
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'];
0 ignored issues
show
Unused Code introduced by
$count is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
28
        $firstMonth = date("$year-$month-01");
0 ignored issues
show
Unused Code introduced by
$firstMonth is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
29
        $lastMonth = date("$year-$month-t");
0 ignored issues
show
Unused Code introduced by
$lastMonth is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
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 = [];
0 ignored issues
show
Unused Code introduced by
$eventData is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
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';
0 ignored issues
show
Coding Style introduced by
CASE statements must be defined using a colon

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
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