Completed
Pull Request — master (#90)
by Benedikt
02:14
created

GenerateKeyEvent::setKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 4
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Noxlogic\RateLimitBundle\Events;
4
5
use Symfony\Component\HttpKernel\Kernel;
6
use Symfony\Contracts\EventDispatcher\Event as ContractsEvent;
7
use Symfony\Component\EventDispatcher\Event as ComponentEvent;
8
use Symfony\Component\HttpFoundation\Request;
9
10 1
if(Kernel::VERSION_ID >= 40300) {
11 View Code Duplication
    class GenerateKeyEvent extends ContractsEvent
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...
12
    {
13
14
        /** @var Request */
15
        protected $request;
16
17
        /** @var string */
18
        protected $key;
19
20
        /** @var mixed */
21
        protected $payload;
22
23
        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...
24
        {
25
            $this->request = $request;
26
            $this->key = $key;
27
            $this->payload = $payload;
28
        }
29
30
        /**
31
         * @return string
32
         */
33
        public function getKey()
34
        {
35
            return $this->key;
36
        }
37
38
        /**
39
         * @param string $key
40
         */
41
        public function setKey($key)
42
        {
43
            $this->key = $key;
44
        }
45
46
        /**
47
         * @return Request
48
         */
49
        public function getRequest()
50
        {
51
            return $this->request;
52
        }
53
54
        /**
55
         * @param $part
56
         */
57
        public function addToKey($part)
58
        {
59
            if ($this->key) {
60
                $this->key .= '.' . $part;
61
            } else {
62
                $this->key = $part;
63
            }
64
        }
65
66
        /**
67
         * @return mixed
68
         */
69
        public function getPayload()
70
        {
71
            return $this->payload;
72
        }
73
    }
74
} else {
75 View Code Duplication
    class GenerateKeyEvent extends ComponentEvent
0 ignored issues
show
Comprehensibility Best Practice introduced by
The type Noxlogic\RateLimitBundle\Events\GenerateKeyEvent has been defined more than once; this definition is ignored, only the first definition in this file (L11-73) is considered.

This check looks for classes that have been defined more than once in the same file.

If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.

This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.

Loading history...
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...
76
    {
77
78
        /** @var Request */
79
        protected $request;
80
81
        /** @var string */
82
        protected $key;
83
84
        /** @var mixed */
85
        protected $payload;
86
87
        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...
88
        {
89
            $this->request = $request;
90
            $this->key = $key;
91
            $this->payload = $payload;
92
        }
93
94
        /**
95
         * @return string
96
         */
97
        public function getKey()
98
        {
99
            return $this->key;
100
        }
101
102
        /**
103
         * @param string $key
104
         */
105
        public function setKey($key)
106
        {
107
            $this->key = $key;
108
        }
109
110
        /**
111
         * @return Request
112
         */
113
        public function getRequest()
114
        {
115
            return $this->request;
116
        }
117
118
        /**
119
         * @param $part
120
         */
121
        public function addToKey($part)
122
        {
123
            if ($this->key) {
124
                $this->key .= '.' . $part;
125
            } else {
126
                $this->key = $part;
127
            }
128
        }
129
130
        /**
131
         * @return mixed
132
         */
133
        public function getPayload()
134
        {
135
            return $this->payload;
136
        }
137
    }    
138
}
139