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

CheckedRateLimitEvent::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 5
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 5
loc 5
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
namespace Noxlogic\RateLimitBundle\Events;
4
5
use Noxlogic\RateLimitBundle\Annotation\RateLimit;
6
use Symfony\Component\HttpKernel\Kernel;
7
use Symfony\Contracts\EventDispatcher\Event as ContractsEvent;
8
use Symfony\Component\EventDispatcher\Event as ComponentEvent;
9
use Symfony\Component\HttpFoundation\Request;
10
11 1
if(Kernel::VERSION_ID >= 40300) {
12 View Code Duplication
    class CheckedRateLimitEvent 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...
13
    {
14
15
        /**
16
         * @var Request
17
         */
18
        protected $request;
19
20
        /**
21
         * @var RateLimit|null
22
         */
23
        protected $rateLimit;
24
25
        public function __construct(Request $request, RateLimit $rateLimit = 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...
26
        {
27
            $this->request = $request;
28
            $this->rateLimit = $rateLimit;
29
        }
30
31
        /**
32
         * @return RateLimit|null
33
         */
34
        public function getRateLimit()
35
        {
36
            return $this->rateLimit;
37
        }
38
39
        /**
40
         * @param RateLimit|null $rateLimit
41
         */
42
        public function setRateLimit(RateLimit $rateLimit = null)
43
        {
44
            $this->rateLimit = $rateLimit;
45
        }
46
47
        /**
48
         * @return Request
49
         */
50
        public function getRequest()
51
        {
52
            return $this->request;
53
        }
54
    }
55
} else {
56 View Code Duplication
    class CheckedRateLimitEvent extends ComponentEvent
0 ignored issues
show
Comprehensibility Best Practice introduced by
The type Noxlogic\RateLimitBundle...s\CheckedRateLimitEvent has been defined more than once; this definition is ignored, only the first definition in this file (L12-54) 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...
57
    {
58
59
        /**
60
         * @var Request
61
         */
62
        protected $request;
63
64
        /**
65
         * @var RateLimit|null
66
         */
67
        protected $rateLimit;
68
69
        public function __construct(Request $request, RateLimit $rateLimit = 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...
70
        {
71
            $this->request = $request;
72
            $this->rateLimit = $rateLimit;
73
        }
74
75
        /**
76
         * @return RateLimit|null
77
         */
78
        public function getRateLimit()
79
        {
80
            return $this->rateLimit;
81
        }
82
83
        /**
84
         * @param RateLimit|null $rateLimit
85
         */
86
        public function setRateLimit(RateLimit $rateLimit = null)
87
        {
88
            $this->rateLimit = $rateLimit;
89
        }
90
91
        /**
92
         * @return Request
93
         */
94
        public function getRequest()
95
        {
96
            return $this->request;
97
        }
98
    }
99
}