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

CacheCount   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 58
loc 58
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A createFromArray() 7 7 1
A jsonSerialize() 7 7 1
A getCount() 4 4 1
A getTtl() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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