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.
Completed
Push — rewrite ( 22f219...c351b2 )
by Adam
03:05
created

Client::poniverse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Poniverse\Lib;
4
5
use GuzzleHttp\Client as HttpClient;
6
use League\OAuth2\Client\Token\AccessToken;
7
use Poniverse\Lib\OAuth2\PoniverseProvider;
8
9
class Client
10
{
11
    /**
12
     * @var string|null
13
     */
14
    protected $accessToken = null;
15
16
    /**
17
     * @var \GuzzleHttp\Client
18
     */
19
    protected $httpClient;
20
21
    /**
22
     * Poniverse.net Client ID.
23
     *
24
     * @var string
25
     */
26
    private $clientId;
27
28
    /**
29
     * Poniverse.net Client Secret.
30
     *
31
     * @var string
32
     */
33
    private $clientSecret;
34
35
    /**
36
     * Poniverse project url mappings.
37
     *
38
     * @var array
39
     */
40
    protected $urlMappings = [
41
        'poniverse' => 'https://api.poniverse.net',
42
        'ponyfm' => 'https://pony.fm',
43
    ];
44
45
    /**
46
     * Initializes the Poniverse Api client.
47
     *
48
     * @param string $clientId
49
     * @param string $clientSecret
50
     * @param \GuzzleHttp\Client $httpClient
51
     * @param array $urlOverrides
52
     */
53
    public function __construct($clientId, $clientSecret, HttpClient $httpClient, $urlOverrides = [])
54
    {
55
        $this->clientId = $clientId;
56
        $this->clientSecret = $clientSecret;
57
        $this->httpClient = $httpClient;
58
59
        if (count($urlOverrides) > 0) {
60
            $this->urlMappings = array_merge($this->urlMappings, $urlOverrides);
61
        }
62
    }
63
64
    /**
65
     * Returns the set access key.
66
     *
67
     * @return string
68
     */
69
    public function getAccessToken()
70
    {
71
        return $this->accessToken;
72
    }
73
74
    /**
75
     * Sets the access token to communicate to the api with.
76
     *
77
     * @param $accessToken
78
     *
79
     * @return $this
80
     */
81
    public function setAccessToken(AccessToken $accessToken)
82
    {
83
        $this->accessToken = $accessToken->getToken();
84
85
        return $this;
86
    }
87
88
    /**
89
     * Returns the http client.
90
     *
91
     * @return \GuzzleHttp\Client
92
     */
93
    public function getHttpClient()
94
    {
95
        return $this->httpClient;
96
    }
97
98
    /**
99
     * Returns the Autho.
100
     *
101
     * @return array
102
     */
103
    public function getAuthHeader()
104
    {
105
        return ['Authorization' => 'Bearer '.$this->getAccessToken()];
106
    }
107
108
    public function getPoniverseUrl()
109
    {
110
        return $this->urlMappings['poniverse'][$this->environment];
0 ignored issues
show
Bug introduced by
The property environment does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
111
    }
112
113
    public function getPonyfmUrl()
114
    {
115
        return $this->urlMappings['ponyfm'][$this->environment];
116
    }
117
118
    /**
119
     * Returns the Poniverse.net service factory.
120
     *
121
     * @return Service\Poniverse\Factory
122
     */
123
    public function poniverse()
124
    {
125
        return new Service\Poniverse\Factory($this);
126
    }
127
128
    /**
129
     * Returns the Poniverse OAuth Provider class.
130
     *
131
     * @param array $options
132
     * @return PoniverseProvider
133
     */
134
    public function getOAuthProvider(array $options = [])
135
    {
136
        $options = array_merge([
137
            'clientId' => $this->clientId,
138
            'clientSecret' => $this->clientSecret,
139
        ], $options);
140
141
        return new PoniverseProvider($options);
142
    }
143
}
144