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.

PoloniexClient   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 66
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
A isInaccessible() 0 3 1
A request() 0 15 4
1
<?php
2
/**
3
 * This file is part of Poloniex PHP SDK.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @copyright 2017-2018 Chasovskih Grisha <[email protected]>
9
 * @license https://github.com/signulls/poloniex-php-sdk/blob/master/LICENSE MIT
10
 */
11
12
namespace Poloniex;
13
14
use GuzzleHttp\{Client, RequestOptions};
15
use Poloniex\CallHistory\CallHistoryInterface;
16
use Psr\Http\Message\ResponseInterface;
17
18
/**
19
 * Class PoloniexClient
20
 *
21
 * NOTE: Currency pairs are reverse of what most exchanges use.
22
 *       For instance, instead of XPM_BTC, use BTC_XPM
23
 *
24
 * @link   https://poloniex.com/support/api/
25
 * @author Grisha Chasovskih <[email protected]>
26
 */
27
class PoloniexClient extends Client
28
{
29
    /**
30
     * @var CallHistoryInterface
31
     */
32
    private $callHistory;
33
34
    /**
35
     * Timeout in seconds
36
     *
37
     * @var int
38
     */
39
    private $timeout;
40
41
    /**
42
     * PoloniexClient constructor.
43
     *
44
     * @param CallHistoryInterface $callHistory
45
     * @param string $baseUri
46
     * @param int $timeout
47
     * @param string|null $proxy
48
     */
49
    public function __construct(
50
        CallHistoryInterface $callHistory,
51
        string $baseUri = 'https://poloniex.com/',
52
        int $timeout = 0,
53
        string $proxy = null
54
    ) {
55
        $this->callHistory = $callHistory;
56
        $this->timeout = $timeout;
57
58
        parent::__construct([
59
            'base_uri' => $baseUri,
60
            RequestOptions::ALLOW_REDIRECTS => false,
61
            RequestOptions::PROXY => $proxy,
62
        ]);
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68
    public function request($method, $uri = '', array $options = []): ResponseInterface
69
    {
70
        $wait = false;
71
        $proxy = $options[RequestOptions::PROXY] ?? $this->getConfig(RequestOptions::PROXY) ?: null;
72
73
        do {
74
            if ($wait) {
75
                sleep(1);
76
            }
77
            $wait = true;
78
        } while ($this->callHistory->isIncreased($proxy));
79
80
        $this->callHistory->create($proxy);
81
82
        return parent::request($method, $uri, array_merge(['timeout' => $this->timeout], $options));
83
    }
84
85
    /**
86
     * Check whether service is accessible
87
     *
88
     * @return bool
89
     */
90
    public function isInaccessible(): bool
91
    {
92
        return $this->get('/')->getStatusCode() !== 200;
93
    }
94
}