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 — master ( 1bd209...b712a4 )
by Jared
04:45
created

OAuth::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 3
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: jaredchu
5
 * Date: 12/2/16
6
 * Time: 4:25 PM
7
 */
8
9
namespace JCFirebase;
10
11
use Firebase\JWT\JWT;
12
use Requests;
13
14
class OAuth
15
{
16
    public $tokenLifeTime;
17
    public $key;
18
    public $iss;
19
20
    protected $exp;
21
    protected $accessToken;
22
    /**
23
     * OAuth constructor.
24
     * @param $key
25
     * @param $iss
26
     */
27
    public function __construct($key, $iss,$tokenLifeTime = 3600)
0 ignored issues
show
Unused Code introduced by
The parameter $tokenLifeTime is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
28
    {
29
        $this->key = $key;
30
        $this->iss = $iss;
31
        $this->tokenLifeTime = 3600;
32
    }
33
34
    public function getAccessToken(){
35
        $accessToken = null;
36
37
        if($this->exp <= time()){
38
            $sTime = time();
39
40
            $jsonToken = array(
41
                "iss"=>$this->iss,
42
                "scope"=>"https://www.googleapis.com/auth/firebase.database https://www.googleapis.com/auth/userinfo.email",
43
                "aud"=>"https://www.googleapis.com/oauth2/v4/token",
44
                "exp"=>time()+$this->tokenLifeTime,
45
                "iat"=>time()
46
            );
47
            $jwt = JWT::encode($jsonToken, $this->key, 'RS256');
48
49
            $OAuthResponse = Requests::post('https://www.googleapis.com/oauth2/v4/token',null,array(
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a array.

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...
50
                'grant_type' => 'urn:ietf:params:oauth:grant-type:jwt-bearer',
51
                'assertion' => $jwt
52
            ));
53
54
            if($OAuthResponse->status_code == 200){
55
                $accessToken = json_decode($OAuthResponse->body)->access_token;
56
                $this->accessToken = $accessToken;
57
58
                //set expire time
59
                $eTime = time();
60
                $this->exp = $sTime - $eTime + $this->tokenLifeTime;
61
            }
62
        }
63
        else{
64
            $accessToken = $this->accessToken;
65
        }
66
67
        return $accessToken;
68
    }
69
}