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 (#15)
by Grisha
05:34
created

PoloniexClient::log()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 3
dl 0
loc 4
rs 10
c 0
b 0
f 0
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;
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
     * Base url for poloniex api requests
31
     */
32
    public const BASE_URI = 'https://poloniex.com/';
33
34
    /**
35
     * @var CallHistoryInterface
36
     */
37
    private $callHistory;
38
39
    /**
40
     * Timeout in seconds
41
     *
42
     * @var int
43
     */
44
    private $timeout;
45
46
    /**
47
     * PoloniexClient constructor.
48
     *
49
     * @param CallHistoryInterface $callHistory
50
     * @param string               $baseUri
51
     * @param int                  $timeout
52
     */
53
    public function __construct(
54
        CallHistoryInterface $callHistory = null,
55
        string $baseUri = self::BASE_URI,
56
        int $timeout = 0
57
    ) {
58
        $this->callHistory = $callHistory;
59
        $this->timeout = $timeout;
60
61
        parent::__construct([
62
            'base_uri' => $baseUri,
63
            'allow_redirects' => false,
64
        ]);
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70
    public function request($method, $uri = '', array $options = []): ResponseInterface
71
    {
72
        if ($this->callHistory !== null) {
73
            if ($this->callHistory->isIncreased()) {
74
                sleep(1);
75
            }
76
77
            $this->callHistory->create();
78
        }
79
80
        return parent::request($method, $uri, array_merge(['timeout' => $this->timeout], $options));
81
    }
82
83
    /**
84
     * Check whether service is accessible
85
     *
86
     * @return bool
87
     */
88
    public function isInaccessible(): bool
89
    {
90
        return $this->get('/')->getStatusCode() !== 200;
91
    }
92
}