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.
Test Failed
Pull Request — master (#100)
by
unknown
01:55
created

Pinterest::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 0
Metric Value
dl 0
loc 12
c 0
b 0
f 0
ccs 5
cts 6
cp 0.8333
rs 9.8666
cc 2
nc 2
nop 3
crap 2.0185
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;
12
13
use DirkGroenen\Pinterest\Auth\PinterestOAuth;
14
use DirkGroenen\Pinterest\Utils\CurlBuilder;
15
use DirkGroenen\Pinterest\Transport\Request;
16
use DirkGroenen\Pinterest\Exceptions\InvalidEndpointException;
17
18
/**
19
 * @property \DirkGroenen\Pinterest\Endpoints\Boards boards
20
 * @property \DirkGroenen\Pinterest\Endpoints\Following following
21
 * @property \DirkGroenen\Pinterest\Endpoints\Pins pins
22
 * @property \DirkGroenen\Pinterest\Endpoints\Users users
23
 */
24
class Pinterest {
25
26
    /**
27
     * Reference to authentication class instance
28
     *
29
     * @var Auth\PinterestOAuth
30
     */
31
    public $auth;
32
33
    /**
34
     * A reference to the request class which travels
35
     * through the application
36
     *
37
     * @var Transport\Request
38
     */
39
    public $request;
40
41
    /**
42
     * A array containing the cached endpoints
43
     *
44
     * @var array
45
     */
46
    private $cachedEndpoints = [];
47
48
    /**
49
     * Constructor
50
     *
51
     * @param  string       $client_id
52
     * @param  string       $client_secret
53
     * @param  CurlBuilder  $curlbuilder
54
     */
55 39
    public function __construct($client_id, $client_secret, $curlbuilder = null)
56
    {
57 39
        if ($curlbuilder == null) {
58
            $curlbuilder = new CurlBuilder();
59
        }
60
61
        // Create new instance of Transport\Request
62 39
        $this->request = new Request($curlbuilder);
63
64
        // Create and set new instance of the OAuth class
65 39
        $this->auth = new PinterestOAuth($client_id, $client_secret, $this->request);
66 39
    }
67
68
    /**
69
     * Get an Pinterest API endpoint
70
     *
71
     * @access public
72
     * @param string    $endpoint
73
     * @return mixed
74
     * @throws Exceptions\InvalidEndpointException
75
     */
76 35
    public function __get($endpoint)
77
    {
78 35
        $endpoint = strtolower($endpoint);
79 35
        $class = "\\DirkGroenen\\Pinterest\\Endpoints\\" . ucfirst($endpoint);
80
81
        // Check if an instance has already been initiated
82 35
        if (!isset($this->cachedEndpoints[$endpoint])) {
83
            // Check endpoint existence
84 35
            if (!class_exists($class)) {
85
                throw new InvalidEndpointException;
86
            }
87
88
            // Create a reflection of the called class and initialize it
89
            // with a reference to the request class
90 35
            $ref = new \ReflectionClass($class);
91 35
            $obj = $ref->newInstanceArgs([$this->request, $this]);
92
93 35
            $this->cachedEndpoints[$endpoint] = $obj;
94
        }
95
96 35
        return $this->cachedEndpoints[$endpoint];
97
    }
98
99
    /**
100
     * Get rate limit from the headers
101
     * response header may change from X-Ratelimit-Limit to X-RateLimit-Limit
102
     * @access public
103
     * @return integer
104
     */
105 1
    public function getRateLimit()
106
    {
107 1
        $header = $this->request->getHeaders();
108 1
        $lcHeader = array_change_key_case($header, CASE_LOWER);
109
        return (isset($lcHeader['x-ratelimit-limit']) ? $lcHeader['x-ratelimit-limit'] : 1000);
110
    }
111
112
    /**
113
     * Get rate limit remaining from the headers
114
     * response header may change from X-Ratelimit-Remaining to X-RateLimit-Remaining
115
     * @access public
116
     * @return mixed
117
     */
118 1
    public function getRateLimitRemaining()
119
    {
120 1
        $header = $this->request->getHeaders();
121 1
        $lcHeader = array_change_key_case($header, CASE_LOWER);
122
        return (isset($lcHeader['x-ratelimit-remaining']) ? $lcHeader['x-ratelimit-remaining'] : 'unknown');
123
    }
124
}
125