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.

AbstractApi::setToken()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
/*
4
 * This file is part of Slackify.
5
 *
6
 * (c) Strime <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Strime\Slackify\Api;
13
14
abstract class AbstractApi implements ApiInterface
15
{
16
    const SLACK_API_URL = "https://slack.com/api/";
17
18
19
    /** @var string */
20
    protected $token;
21
    /** @var string */
22
    public $url;
23
24
25
    public function __construct($token) {
26
        $this->token = $token;
27
    }
28
29
30
31
    /**
32
     * @return string
33
     */
34
    public function getToken() {
35
        return $this->token;
36
    }
37
38
    /**
39
     * @param string $token
40
     *
41
     * @return ApiInterface
42
     */
43
    public function setToken($token) {
44
45
        if (!is_string($token)) {
46
            throw new InvalidArgumentException('The token must be a string.');
47
        }
48
49
        $this->token = $token;
50
51
        return $this;
52
    }
53
54
    /**
55
     * @param string $method
56
     * @param array $arguments
57
     *
58
     * @return ApiInterface
59
     */
60
    public function setUrl($method, $arguments = NULL) {
61
62
        if (!is_string($method)) {
63
            throw new InvalidArgumentException('The method variable must be a string.');
64
        }
65
        if (($arguments != NULL) && !is_array($arguments)) {
66
            throw new InvalidArgumentException('The arguments variable must be an array.');
67
        }
68
69
        // Set a new array
70
        $arguments_list = array();
71
72
        // Check if a token is set through the arguments
73
        $token_is_set = FALSE;
74
75
        if ($arguments != NULL) {
76
            foreach ($arguments as $key => $value) {
77
                $arguments_list[] = $key . "=" . $value;
78
79
                if(strcmp($key, "token") == 0) {
80
                    $token_is_set = TRUE;
81
                }
82
            }
83
        }
84
85
        // If the token has not been set, add it to the list
86
        if(!$token_is_set && isset($this->token) && is_string($this->token)) {
87
            $arguments_list[] = "token=".$this->token;
88
        }
89
90
        $this->url = self::SLACK_API_URL . $method . "?" . implode("&", $arguments_list);
91
92
        return $this;
93
    }
94
95
    /**
96
     * @return string
97
     */
98
    public function getUrl() {
99
        return $this->url;
100
    }
101
102
}
103