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 ( 0d28ae...851f9e )
by Peter
05:22 queued 03:49
created

AccessTokenInfo   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 7
dl 0
loc 49
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handleError() 0 10 2
A introspect() 0 22 1
1
<?php
2
3
/**
4
 * Copyright 2016 Peter Deltchev
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace Poniverse\Lib\Service\Poniverse;
20
21
use Poniverse\Lib\Errors\InvalidAccessTokenException;
22
use Poniverse\Lib\Service\Service;
23
24
class AccessTokenInfo extends Service {
25
26
    /**
27
     * @param \Psr\Http\Message\ResponseInterface $response
28
     * @throws InvalidAccessTokenException
29
     * @throws \Poniverse\Lib\Errors\ApiException
30
     */
31
    protected function handleError(\Psr\Http\Message\ResponseInterface $response) {
32
        if (404 === $response->getStatusCode()) {
33
            throw new InvalidAccessTokenException('This access token is expired or invalid!');
34
        } else {
35
            throw new \Poniverse\Lib\Errors\ApiException(
36
                $response->getStatusCode(),
37
                ['response' => var_export($response, true)],
0 ignored issues
show
Documentation introduced by
array('response' => var_export($response, true)) is of type array<string,string,{"response":"string"}>, but the function expects a array<integer,object<Poniverse\Lib\Errors\Error>>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
38
                'An unknown error occurred while contacting the Poniverse API.');
39
        }
40
    }
41
42
    /**
43
     * Gets information about the given access token.
44
     *
45
     * @link https://tools.ietf.org/html/draft-richer-oauth-introspection-06
46
     *
47
     * @param $accessTokenToIntrospect
48
     * @return \Poniverse\Lib\AccessToken
49
     */
50
    public function introspect($accessTokenToIntrospect) {
51
        $clientToken = $this->client->getOAuthProvider()->getAccessToken('client_credentials');
52
        $this->client->setAccessToken($clientToken);
53
54
        $request = $this->request(
55
            'post',
56
            $this->client->getPoniverseUrl() . "/v1/meta/introspect?token={$accessTokenToIntrospect}",
57
            ['headers' => array_merge(
58
                ['Accept' => 'application/json'],
59
                $this->client->getAuthHeader()
60
            )]
61
        );
62
63
        $response = json_decode($request->getBody(), true);
64
65
        $tokenInfo = new \Poniverse\Lib\AccessToken($accessTokenToIntrospect);
66
        $tokenInfo
67
            ->setIsActive($response['active'])
68
            ->setScopes($response['scope'])
69
            ->setClientId($response['client_id']);
70
        return $tokenInfo;
71
    }
72
}
73