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.

Pinterest   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 105
Duplicated Lines 15.24 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 84.62%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 4
dl 16
loc 105
ccs 22
cts 26
cp 0.8462
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 2
A __get() 0 22 3
A getRateLimit() 8 8 3
A getRateLimitRemaining() 8 8 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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