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 ( fec26d...4e4046 )
by Dirk
05:35
created

Pinterest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 90.91%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
lcom 1
cbo 4
dl 0
loc 99
ccs 20
cts 22
cp 0.9091
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 2
A __get() 0 22 3
A getRateLimit() 0 5 2
A getRateLimitRemaining() 0 5 2
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
     *
102
     * @access public
103
     * @return integer
104
     */
105 1
    public function getRateLimit()
106
    {
107 1
        $header = $this->request->getHeaders();
108 1
        return (isset($header['X-Ratelimit-Limit']) ? $header['X-Ratelimit-Limit'] : 1000);
109
    }
110
111
    /**
112
     * Get rate limit remaining from the headers
113
     *
114
     * @access public
115
     * @return mixed
116
     */
117 1
    public function getRateLimitRemaining()
118
    {
119 1
        $header = $this->request->getHeaders();
120 1
        return (isset($header['X-Ratelimit-Remaining']) ? $header['X-Ratelimit-Remaining'] : 'unknown');
121
    }
122
}
123