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 (#9)
by Grisha
04:35
created

RedisCallHistory::getTime()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
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\CallHistory;
13
14
use Predis\Client;
0 ignored issues
show
Bug introduced by
The type Predis\Client was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use DateTime;
16
17
/**
18
 * Class RedisCallHistory
19
 *
20
 * @author Grisha Chasovskih <[email protected]>
21
 */
22
class RedisCallHistory implements CallHistoryInterface
23
{
24
    private const MAIN_KEY = 'poloniex:calls';
25
26
    /**
27
     * Client class used for connecting and executing commands on Redis.
28
     *
29
     * @var Client
30
     */
31
    protected $redisClient;
32
33
    /**
34
     * Time for cache
35
     *
36
     * @var string
37
     */
38
    protected $expireTime;
39
40
    /**
41
     * RedisCallHistory constructor.
42
     *
43
     * @param Client $client
44
     * @param string $expireTime
45
     */
46
    public function __construct(Client $client, string $expireTime = '1 hour')
47
    {
48
        $this->expireTime = $expireTime;
49
        $this->redisClient = $client;
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function create(): void
56
    {
57
        $this->redisClient->hincrby(self::MAIN_KEY, $this->getTime(), 1);
58
        $this->redisClient->expireat(self::MAIN_KEY, strtotime('+' . $this->expireTime));
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64
    public function isIncreased(): bool
65
    {
66
        return $this->redisClient->hget(self::MAIN_KEY, $this->getTime()) >= self::CALLS_PER_SECOND;
67
    }
68
69
    /**
70
     * Create time key based by one second
71
     *
72
     * @return string
73
     */
74
    private function getTime(): string
75
    {
76
        return (new DateTime())->format('Y:m:d:H:i:s');
77
    }
78
}