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

GenerateKeyEvent::addToKey()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 5
cp 0.8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2.032
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