Code Duplication    Length = 58-58 lines in 3 locations

src/Throttle/Entity/CacheCount.php 1 location

@@ 7-64 (lines=58) @@
4
5
use Sunspikes\Ratelimit\Cache\ThrottlerItemInterface;
6
7
class CacheCount implements ThrottlerItemInterface
8
{
9
    /** @var int $count */
10
    private $count;
11
12
    /** @var int $ttl */
13
    private $ttl;
14
15
    /**
16
     * @param int $count
17
     * @param int $ttl
18
     */
19
    public function __construct(int $count, int $ttl = null)
20
    {
21
        $this->count = $count;
22
        $this->ttl = $ttl;
23
    }
24
25
    /**
26
     * @param array $array
27
     *
28
     * @return ThrottlerItemInterface
29
     */
30
    public static function createFromArray(array $array): ThrottlerItemInterface
31
    {
32
        return new static(
33
            $array['count'],
34
            $array['ttl']
35
        );
36
    }
37
38
    /**
39
     * @return array
40
     */
41
    public function jsonSerialize()
42
    {
43
        return [
44
            'count' => $this->count,
45
            'ttl' => $this->ttl,
46
        ];
47
    }
48
49
    /**
50
     * @return int
51
     */
52
    public function getCount(): int
53
    {
54
        return $this->count;
55
    }
56
57
    /**
58
     * @return int|null
59
     */
60
    public function getTtl()
61
    {
62
        return $this->ttl;
63
    }
64
}

src/Throttle/Entity/CacheHitMapping.php 1 location

@@ 7-64 (lines=58) @@
4
5
use Sunspikes\Ratelimit\Cache\ThrottlerItemInterface;
6
7
class CacheHitMapping implements ThrottlerItemInterface
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
    public function __construct(array $hitMapping, int $ttl = null)
20
    {
21
        $this->hitMapping = $hitMapping;
22
        $this->ttl = $ttl;
23
    }
24
25
    /**
26
     * @param array $array
27
     *
28
     * @return ThrottlerItemInterface
29
     */
30
    public static function createFromArray(array $array): ThrottlerItemInterface
31
    {
32
        return new static(
33
            $array['hitMapping'],
34
            $array['ttl']
35
        );
36
    }
37
38
    /**
39
     * @return array
40
     */
41
    public function jsonSerialize()
42
    {
43
        return [
44
            'hitMapping' => $this->hitMapping,
45
            'ttl' => $this->ttl,
46
        ];
47
    }
48
49
    /**
50
     * @return array
51
     */
52
    public function getHitMapping(): array
53
    {
54
        return $this->hitMapping;
55
    }
56
57
    /**
58
     * @return int|null
59
     */
60
    public function getTtl()
61
    {
62
        return $this->ttl;
63
    }
64
}

src/Throttle/Entity/CacheTime.php 1 location

@@ 7-64 (lines=58) @@
4
5
use Sunspikes\Ratelimit\Cache\ThrottlerItemInterface;
6
7
class CacheTime implements ThrottlerItemInterface
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
    public function __construct(float $time, int $ttl = null)
20
    {
21
        $this->time = $time;
22
        $this->ttl = $ttl;
23
    }
24
25
    /**
26
     * @param array $array
27
     *
28
     * @return ThrottlerItemInterface
29
     */
30
    public static function createFromArray(array $array): ThrottlerItemInterface
31
    {
32
        return new static(
33
            $array['time'],
34
            $array['ttl']
35
        );
36
    }
37
38
    /**
39
     * @return array
40
     */
41
    public function jsonSerialize()
42
    {
43
        return [
44
            'time' => $this->time,
45
            'ttl' => $this->ttl,
46
        ];
47
    }
48
49
    /**
50
     * @return float
51
     */
52
    public function getTime(): float
53
    {
54
        return $this->time;
55
    }
56
57
    /**
58
     * @return float|null
59
     */
60
    public function getTtl()
61
    {
62
        return $this->ttl;
63
    }
64
}