Completed
Pull Request — master (#10)
by Krishnaprasad
08:08 queued 03:56
created

CacheTime::createFromArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 7
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 7
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Sunspikes\Ratelimit\Throttle\Entity;
4
5
use Sunspikes\Ratelimit\Cache\ThrottlerItemInterface;
6
7 View Code Duplication
class CacheTime implements ThrottlerItemInterface
0 ignored issues
show
Duplication introduced by
This class 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...
8
{
9
    /** @var float $limit */
10
    private $time;
11
12
    /** @var int $ttl */
13
    private $ttl;
14
15
    /**
16
     * @param float $time
17
     * @param int $ttl
18
     */
19 16
    public function __construct(float $time, int $ttl = null)
20
    {
21 16
        $this->time = $time;
22 16
        $this->ttl = $ttl;
23 16
    }
24
25
    /**
26
     * @param array $array
27
     *
28
     * @return ThrottlerItemInterface
29
     */
30 16
    public static function createFromArray(array $array): ThrottlerItemInterface
31
    {
32 16
        return new static(
33 16
            $array['time'],
34 16
            $array['ttl']
35
        );
36
    }
37
38
    /**
39
     * @return array
40
     */
41 16
    public function jsonSerialize()
42
    {
43
        return [
44 16
            'time' => $this->time,
45 16
            'ttl' => $this->ttl,
46
        ];
47
    }
48
49
    /**
50
     * @return float
51
     */
52 16
    public function getTime(): float
53
    {
54 16
        return $this->time;
55
    }
56
57
    /**
58
     * @return float|null
59
     */
60 16
    public function getTtl()
61
    {
62 16
        return $this->ttl;
63
    }
64
}