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
Pull Request — master (#102)
by Dirk
02:33
created

Pinterest::__get()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3.009

Importance

Changes 0
Metric Value
dl 0
loc 22
c 0
b 0
f 0
ccs 9
cts 10
cp 0.9
rs 9.568
cc 3
nc 3
nop 1
crap 3.009
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 View Code Duplication
    public function getRateLimit()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
106
    {
107 1
        $header = $this->request->getHeaders();
108 1
        if (is_array($header)) {
109
            $header = array_change_key_case($header, CASE_LOWER);
110
        }
111 1
        return (isset($header['x-ratelimit-limit']) ? $header['x-ratelimit-limit'] : 1000);
112
    }
113
114
    /**
115
     * Get rate limit remaining from the headers
116
     * response header may change from X-Ratelimit-Remaining to X-RateLimit-Remaining
117
     * @access public
118
     * @return mixed
119
     */
120 1 View Code Duplication
    public function getRateLimitRemaining()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
121
    {
122 1
        $header = $this->request->getHeaders();
123 1
        if (is_array($header)) {
124
            $header = array_change_key_case($header, CASE_LOWER);
125
        }
126 1
        return (isset($header['x-ratelimit-remaining']) ? $header['x-ratelimit-remaining'] : 'unknown');
127
    }
128
}
129