Completed
Push — master ( bc4a85...ef080e )
by
unknown
02:43
created

GenerateKeyEvent   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getKey() 0 4 1
A setKey() 0 4 1
A getRequest() 0 4 1
A addToKey() 0 8 2
A getPayload() 0 4 1
1
<?php
2
3
namespace Noxlogic\RateLimitBundle\Events;
4
5
use Symfony\Component\EventDispatcher\Event;
6
use Symfony\Component\HttpFoundation\Request;
7
8
class GenerateKeyEvent extends Event
9
{
10
11
    /** @var Request */
12
    protected $request;
13
14
    /** @var string */
15
    protected $key;
16
17
    /** @var mixed */
18
    protected $payload;
19
20 17
    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...
21
    {
22 17
        $this->request = $request;
23 17
        $this->key = $key;
24 17
        $this->payload = $payload;
25 17
    }
26
27
    /**
28
     * @return string
29
     */
30 15
    public function getKey()
31
    {
32 15
        return $this->key;
33
    }
34
35
    /**
36
     * @param string $key
37
     */
38 1
    public function setKey($key)
39
    {
40 1
        $this->key = $key;
41 1
    }
42
43
    /**
44
     * @return Request
45
     */
46 2
    public function getRequest()
47
    {
48 2
        return $this->request;
49
    }
50
51
    /**
52
     * @param $part
53
     */
54 12
    public function addToKey($part)
55
    {
56 12
        if ($this->key) {
57 2
            $this->key .= '.'.$part;
58
        } else {
59 10
            $this->key = $part;
60
        }
61 12
    }
62
63
    /**
64
     * @return mixed
65
     */
66 2
    public function getPayload()
67
    {
68 2
        return $this->payload;
69
    }
70
}
71