Completed
Pull Request — master (#105)
by Maxime
04:27
created

GenerateKeyEvent   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 94.74%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 63
ccs 18
cts 19
cp 0.9474
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getKey() 0 4 1
A getRequest() 0 4 1
A getPayload() 0 4 1
A __construct() 0 6 1
A setKey() 0 4 1
A addToKey() 0 8 2
1
<?php
2
3
namespace Noxlogic\RateLimitBundle\Events;
4
5
use Symfony\Component\HttpFoundation\Request;
6
7
class GenerateKeyEvent extends AbstractEvent
8
{
9
10
    /** @var Request */
11
    protected $request;
12
13
    /** @var string */
14
    protected $key;
15
16
    /** @var mixed */
17
    protected $payload;
18
19 7
    public function __construct(Request $request, $key = '', $payload = null)
0 ignored issues
show
Bug introduced by
You have injected the Request via parameter $request. This is generally not recommended as there might be multiple instances during a request cycle (f.e. when using sub-requests). Instead, it is recommended to inject the RequestStack and retrieve the current request each time you need it via getCurrentRequest().
Loading history...
20
    {
21 7
        $this->request = $request;
22 7
        $this->key = $key;
23 7
        $this->payload = $payload;
24 7
    }
25
26
    /**
27
     * @return string
28
     */
29 5
    public function getKey()
30
    {
31 5
        return $this->key;
32
    }
33
34
    /**
35
     * @param string $key
36
     */
37 1
    public function setKey($key)
38
    {
39 1
        $this->key = $key;
40 1
    }
41
42
    /**
43
     * @return Request
44
     */
45 1
    public function getRequest()
46
    {
47 1
        return $this->request;
48
    }
49
50
    /**
51
     * @param $part
52
     */
53 2
    public function addToKey($part)
54
    {
55 2
        if ($this->key) {
56 2
            $this->key .= '.'.$part;
57
        } else {
58
            $this->key = $part;
59
        }
60 2
    }
61
62
    /**
63
     * @return mixed
64
     */
65 1
    public function getPayload()
66
    {
67 1
        return $this->payload;
68
    }
69
}
70