MultiRequestSentEvent   A
last analyzed

Complexity

Total Complexity 23

Size/Duplication

Total Lines 177
Duplicated Lines 100 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 23
lcom 2
cbo 1
dl 177
loc 177
ccs 64
cts 64
cp 1
rs 10
c 0
b 0
f 0

19 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 6 6 1
A clearResponses() 4 4 1
A hasResponses() 4 4 1
A getResponses() 4 4 1
A setResponses() 5 5 1
A addResponses() 6 6 2
A removeResponses() 6 6 2
A hasResponse() 4 4 1
A addResponse() 4 4 1
A removeResponse() 5 5 1
A clearExceptions() 4 4 1
A hasExceptions() 4 4 1
A getExceptions() 4 4 1
A setExceptions() 5 5 1
A addExceptions() 6 6 2
A removeExceptions() 6 6 2
A hasException() 4 4 1
A addException() 4 4 1
A removeException() 5 5 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/*
4
 * This file is part of the Ivory Http Adapter package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ivory\HttpAdapter\Event;
13
14
use Ivory\HttpAdapter\HttpAdapterException;
15
use Ivory\HttpAdapter\HttpAdapterInterface;
16
use Ivory\HttpAdapter\Message\ResponseInterface;
17
18
/**
19
 * @author GeLo <[email protected]>
20
 */
21 View Code Duplication
class MultiRequestSentEvent extends AbstractEvent
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...
22
{
23
    /**
24
     * @var ResponseInterface[]
25
     */
26
    private $responses;
27
28
    /**
29
     * @var HttpAdapterException[]
30
     */
31
    private $exceptions = [];
32
33
    /**
34
     * @param HttpAdapterInterface $httpAdapter
35
     * @param ResponseInterface[]  $responses
36
     */
37 243
    public function __construct(HttpAdapterInterface $httpAdapter, array $responses)
38
    {
39 243
        parent::__construct($httpAdapter);
40
41 243
        $this->setResponses($responses);
42 243
    }
43
44 243
    public function clearResponses()
45
    {
46 243
        $this->responses = [];
47 243
    }
48
49
    /**
50
     * @return bool
51
     */
52 90
    public function hasResponses()
53
    {
54 90
        return !empty($this->responses);
55
    }
56
57
    /**
58
     * @return ResponseInterface[]
59
     */
60 171
    public function getResponses()
61
    {
62 171
        return $this->responses;
63
    }
64
65
    /**
66
     * @param ResponseInterface[] $responses
67
     */
68 243
    public function setResponses(array $responses)
69
    {
70 243
        $this->clearResponses();
71 243
        $this->addResponses($responses);
72 243
    }
73
74
    /**
75
     * @param ResponseInterface[] $responses
76
     */
77 243
    public function addResponses(array $responses)
78
    {
79 243
        foreach ($responses as $response) {
80 243
            $this->addResponse($response);
81 189
        }
82 243
    }
83
84
    /**
85
     * @param ResponseInterface[] $responses
86
     */
87 9
    public function removeResponses(array $responses)
88
    {
89 9
        foreach ($responses as $response) {
90 9
            $this->removeResponse($response);
91 7
        }
92 9
    }
93
94
    /**
95
     * @param ResponseInterface $response
96
     *
97
     * @return bool
98
     */
99 45
    public function hasResponse(ResponseInterface $response)
100
    {
101 45
        return array_search($response, $this->responses, true) !== false;
102
    }
103
104
    /**
105
     * @param ResponseInterface $response
106
     */
107 243
    public function addResponse(ResponseInterface $response)
108
    {
109 243
        $this->responses[] = $response;
110 243
    }
111
112
    /**
113
     * @param ResponseInterface $response
114
     */
115 81
    public function removeResponse(ResponseInterface $response)
116
    {
117 81
        unset($this->responses[array_search($response, $this->responses, true)]);
118 81
        $this->responses = array_values($this->responses);
119 81
    }
120
121 45
    public function clearExceptions()
122
    {
123 45
        $this->exceptions = [];
124 45
    }
125
126
    /**
127
     * @return bool
128
     */
129 99
    public function hasExceptions()
130
    {
131 99
        return !empty($this->exceptions);
132
    }
133
134
    /**
135
     * @return HttpAdapterException[]
136
     */
137 99
    public function getExceptions()
138
    {
139 99
        return $this->exceptions;
140
    }
141
142
    /**
143
     * @param HttpAdapterException[] $exceptions
144
     */
145 45
    public function setExceptions(array $exceptions)
146
    {
147 45
        $this->clearExceptions();
148 45
        $this->addExceptions($exceptions);
149 45
    }
150
151
    /**
152
     * @param HttpAdapterException[] $exceptions
153
     */
154 54
    public function addExceptions(array $exceptions)
155
    {
156 54
        foreach ($exceptions as $exception) {
157 54
            $this->addException($exception);
158 42
        }
159 54
    }
160
161
    /**
162
     * @param HttpAdapterException[] $exceptions
163
     */
164 9
    public function removeExceptions(array $exceptions)
165
    {
166 9
        foreach ($exceptions as $exception) {
167 9
            $this->removeException($exception);
168 7
        }
169 9
    }
170
171
    /**
172
     * @param HttpAdapterException $exception
173
     *
174
     * @return bool
175
     */
176 36
    public function hasException(HttpAdapterException $exception)
177
    {
178 36
        return array_search($exception, $this->exceptions, true) !== false;
179
    }
180
181
    /**
182
     * @param HttpAdapterException $exception
183
     */
184 90
    public function addException(HttpAdapterException $exception)
185
    {
186 90
        $this->exceptions[] = $exception;
187 90
    }
188
189
    /**
190
     * @param HttpAdapterException $exception
191
     */
192 18
    public function removeException(HttpAdapterException $exception)
193
    {
194 18
        unset($this->exceptions[array_search($exception, $this->exceptions, true)]);
195 18
        $this->exceptions = array_values($this->exceptions);
196 18
    }
197
}
198