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.

PinterestOAuth::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 11
c 0
b 0
f 0
ccs 6
cts 6
cp 1
rs 9.9
cc 1
nc 1
nop 3
crap 1
1
<?php
2
/**
3
 * Copyright 2015 Dirk Groenen
4
 *
5
 * (c) Dirk Groenen <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace DirkGroenen\Pinterest\Auth;
12
13
use DirkGroenen\Pinterest\Transport\Request;
14
use DirkGroenen\Pinterest\Exceptions\PinterestException;
15
16
class PinterestOAuth {
17
18
    /**
19
     * The application ID
20
     *
21
     * @var string
22
     */
23
    private $client_id;
24
25
    /**
26
     * The app secret
27
     *
28
     * @var string
29
     */
30
    private $client_secret;
31
32
    /**
33
     * Random string indicating the state
34
     * to prevent spoofing
35
     *
36
     * @var void
37
     */
38
    private $state;
39
40
    /**
41
     * A reference to the request instance
42
     *
43
     * @var Request
44
     */
45
    private $request;
46
47
    /**
48
     * Pinterest's oauth endpoint
49
     */
50
    const AUTH_HOST = "https://api.pinterest.com/oauth/";
51
52
    /**
53
     * Construct
54
     *
55
     * @param  string   $client_id
56
     * @param  string   $client_secret
57
     * @param  Request  $request
58
     */
59 43
    public function __construct($client_id, $client_secret, $request)
60
    {
61 43
        $this->client_id = $client_id;
62 43
        $this->client_secret = $client_secret;
63
64
        // Generate and set the state
65 43
        $this->state = $this->generateState();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->generateState() of type string is incompatible with the declared type null of property $state.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
66
67
        // Set request instance
68 43
        $this->request = $request;
69 43
    }
70
71
    /**
72
     * Returns the login url
73
     *
74
     * @access public
75
     * @param  array    $scopes
76
     * @param  string   $redirect_uri
77
     * @return string
78
     */
79
    public function getLoginUrl($redirect_uri, $scopes = array("read_public"), $response_type = "code")
80
    {
81
        $queryparams = array(
82
            "response_type"     => $response_type,
83
            "redirect_uri"      => $redirect_uri,
84
            "client_id"         => $this->client_id,
85
            "scope"             => implode(",", $scopes),
86
            "state"             => $this->state
87
        );
88
89
        // Build url and return it
90
        return sprintf("%s?%s", self::AUTH_HOST, http_build_query($queryparams));
91
    }
92
93
    /**
94
     * Generates a random string and returns is
95
     *
96
     * @access private
97
     * @return string       random string
98
     */
99 43
    private function generateState()
100
    {
101 43
        return substr(md5(rand()), 0, 7);
102
    }
103
104
    /**
105
     * Get the generated state
106
     *
107
     * @return string
108
     */
109 2
    public function getState()
110
    {
111 2
        return $this->state;
112
    }
113
114
    /**
115
     * Set a state manually
116
     *
117
     * @param  string    $state
118
     * @return void
119
     */
120 1
    public function setState($state)
121
    {
122 1
        $this->state = $state;
0 ignored issues
show
Documentation Bug introduced by
It seems like $state of type string is incompatible with the declared type null of property $state.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
123 1
    }
124
125
    /**
126
     * Change the code for an access_token
127
     *
128
     * @param  string   $code
129
     * @return \DirkGroenen\Pinterest\Transport\Response
130
     */
131
    public function getOAuthToken($code)
132
    {
133
        // Build data array
134
        $data = array(
135
            "grant_type"    => "authorization_code",
136
            "client_id"     => $this->client_id,
137
            "client_secret" => $this->client_secret,
138
            "code"          => $code
139
        );
140
141
        // Perform post request
142
        $response = $this->request->post("oauth/token", $data);
143
144
        return $response;
145
    }
146
147
    /**
148
     * Set the access_token for further requests
149
     *
150
     * @access public
151
     * @param  string   $access_token
152
     * @return void
153
     */
154 43
    public function setOAuthToken($access_token)
155
    {
156 43
        $this->request->setAccessToken($access_token);
157
    }
158
}