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

CacheHitMapping::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 5
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 1

Importance

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