These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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 | * Multi request errored event. |
||
20 | * |
||
21 | * @author GeLo <[email protected]> |
||
22 | */ |
||
23 | View Code Duplication | class MultiRequestErroredEvent extends AbstractEvent |
|
0 ignored issues
–
show
|
|||
24 | { |
||
25 | /** @var \Ivory\HttpAdapter\HttpAdapterException[] */ |
||
26 | private $exceptions; |
||
27 | |||
28 | /** @var \Ivory\HttpAdapter\Message\ResponseInterface[] */ |
||
29 | private $responses = array(); |
||
30 | |||
31 | /** |
||
32 | * Creates a multi request errored event. |
||
33 | * |
||
34 | * @param \Ivory\HttpAdapter\HttpAdapterInterface $httpAdapter The http adapter. |
||
35 | * @param \Ivory\HttpAdapter\HttpAdapterException[] $exceptions The exceptions. |
||
36 | */ |
||
37 | 437 | public function __construct(HttpAdapterInterface $httpAdapter, array $exceptions) |
|
38 | { |
||
39 | 437 | parent::__construct($httpAdapter); |
|
40 | |||
41 | 437 | $this->setExceptions($exceptions); |
|
42 | 437 | } |
|
43 | |||
44 | /** |
||
45 | * Clears the exceptions. |
||
46 | */ |
||
47 | 437 | public function clearExceptions() |
|
48 | { |
||
49 | 437 | $this->exceptions = array(); |
|
50 | 437 | } |
|
51 | |||
52 | /** |
||
53 | * Checks if there are exceptions. |
||
54 | * |
||
55 | * @return boolean TRUE if there are exceptions else FALSE. |
||
56 | */ |
||
57 | 114 | public function hasExceptions() |
|
58 | { |
||
59 | 114 | return !empty($this->exceptions); |
|
60 | } |
||
61 | |||
62 | /** |
||
63 | * Gets the exceptions. |
||
64 | * |
||
65 | * @return \Ivory\HttpAdapter\HttpAdapterException[] The exceptions. |
||
66 | */ |
||
67 | 285 | public function getExceptions() |
|
68 | { |
||
69 | 285 | return $this->exceptions; |
|
70 | } |
||
71 | |||
72 | /** |
||
73 | * Sets the exceptions. |
||
74 | * |
||
75 | * @param \Ivory\HttpAdapter\HttpAdapterException[] $exceptions The exceptions. |
||
76 | */ |
||
77 | 437 | public function setExceptions(array $exceptions) |
|
78 | { |
||
79 | 437 | $this->clearExceptions(); |
|
80 | 437 | $this->addExceptions($exceptions); |
|
81 | 437 | } |
|
82 | |||
83 | /** |
||
84 | * Adds the exceptions. |
||
85 | * |
||
86 | * @param \Ivory\HttpAdapter\HttpAdapterException[] $exceptions The exceptions. |
||
87 | */ |
||
88 | 437 | public function addExceptions(array $exceptions) |
|
89 | { |
||
90 | 437 | foreach ($exceptions as $exception) { |
|
91 | 437 | $this->addException($exception); |
|
92 | 414 | } |
|
93 | 437 | } |
|
94 | |||
95 | /** |
||
96 | * Removes the exceptions. |
||
97 | * |
||
98 | * @param \Ivory\HttpAdapter\HttpAdapterException[] $exceptions The exceptions. |
||
99 | */ |
||
100 | 19 | public function removeExceptions(array $exceptions) |
|
101 | { |
||
102 | 19 | foreach ($exceptions as $exception) { |
|
103 | 19 | $this->removeException($exception); |
|
104 | 18 | } |
|
105 | 19 | } |
|
106 | |||
107 | /** |
||
108 | * Checks if there is an exception. |
||
109 | * |
||
110 | * @param \Ivory\HttpAdapter\HttpAdapterException $exception The exception. |
||
111 | * |
||
112 | * @return boolean TRUE if there is the exception else FALSE. |
||
113 | */ |
||
114 | 95 | public function hasException(HttpAdapterException $exception) |
|
115 | { |
||
116 | 95 | return array_search($exception, $this->exceptions, true) !== false; |
|
117 | } |
||
118 | |||
119 | /** |
||
120 | * Adds an exception. |
||
121 | * |
||
122 | * @param \Ivory\HttpAdapter\HttpAdapterException $exception The exception |
||
123 | */ |
||
124 | 437 | public function addException(HttpAdapterException $exception) |
|
125 | { |
||
126 | 437 | $this->exceptions[] = $exception; |
|
127 | 437 | } |
|
128 | |||
129 | /** |
||
130 | * Removes an exception. |
||
131 | * |
||
132 | * @param \Ivory\HttpAdapter\HttpAdapterException $exception The exception. |
||
133 | */ |
||
134 | 76 | public function removeException(HttpAdapterException $exception) |
|
135 | { |
||
136 | 76 | unset($this->exceptions[array_search($exception, $this->exceptions, true)]); |
|
137 | 76 | $this->exceptions = array_values($this->exceptions); |
|
138 | 76 | } |
|
139 | |||
140 | /** |
||
141 | * Clears the responses. |
||
142 | */ |
||
143 | 228 | public function clearResponses() |
|
144 | { |
||
145 | 228 | $this->responses = array(); |
|
146 | 228 | } |
|
147 | |||
148 | /** |
||
149 | * Checks if there are responses. |
||
150 | * |
||
151 | * @return boolean TRUE if there are responses else FALSE. |
||
152 | */ |
||
153 | 152 | public function hasResponses() |
|
154 | { |
||
155 | 152 | return !empty($this->responses); |
|
156 | } |
||
157 | |||
158 | /** |
||
159 | * Gets the responses. |
||
160 | * |
||
161 | * @return \Ivory\HttpAdapter\Message\ResponseInterface[] The responses. |
||
162 | */ |
||
163 | 209 | public function getResponses() |
|
164 | { |
||
165 | 209 | return $this->responses; |
|
166 | } |
||
167 | |||
168 | /** |
||
169 | * Sets the responses. |
||
170 | * |
||
171 | * @param \Ivory\HttpAdapter\Message\ResponseInterface[] $responses The responses. |
||
172 | */ |
||
173 | 228 | public function setResponses(array $responses) |
|
174 | { |
||
175 | 228 | $this->clearResponses(); |
|
176 | 228 | $this->addResponses($responses); |
|
177 | 228 | } |
|
178 | |||
179 | /** |
||
180 | * Adds the responses. |
||
181 | * |
||
182 | * @param \Ivory\HttpAdapter\Message\ResponseInterface[] $responses The responses. |
||
183 | */ |
||
184 | 228 | public function addResponses(array $responses) |
|
185 | { |
||
186 | 228 | foreach ($responses as $response) { |
|
187 | 152 | $this->addResponse($response); |
|
188 | 216 | } |
|
189 | 228 | } |
|
190 | |||
191 | /** |
||
192 | * Removes the responses. |
||
193 | * |
||
194 | * @param \Ivory\HttpAdapter\Message\ResponseInterface[] $responses The responses. |
||
195 | */ |
||
196 | 19 | public function removeResponses(array $responses) |
|
197 | { |
||
198 | 19 | foreach ($responses as $response) { |
|
199 | 19 | $this->removeResponse($response); |
|
200 | 18 | } |
|
201 | 19 | } |
|
202 | |||
203 | /** |
||
204 | * Checks if there is a response. |
||
205 | * |
||
206 | * @param \Ivory\HttpAdapter\Message\ResponseInterface $response The response. |
||
207 | * |
||
208 | * @return boolean TRUE if there is the response else FALSE. |
||
209 | */ |
||
210 | 76 | public function hasResponse(ResponseInterface $response) |
|
211 | { |
||
212 | 76 | return array_search($response, $this->responses, true) !== false; |
|
213 | } |
||
214 | |||
215 | /** |
||
216 | * Adds a response. |
||
217 | * |
||
218 | * @param \Ivory\HttpAdapter\Message\ResponseInterface $response The response. |
||
219 | */ |
||
220 | 190 | public function addResponse(ResponseInterface $response) |
|
221 | { |
||
222 | 190 | $this->responses[] = $response; |
|
223 | 190 | } |
|
224 | |||
225 | /** |
||
226 | * Removes a response. |
||
227 | * |
||
228 | * @param \Ivory\HttpAdapter\Message\ResponseInterface $response The response. |
||
229 | */ |
||
230 | 38 | public function removeResponse(ResponseInterface $response) |
|
231 | { |
||
232 | 38 | unset($this->responses[array_search($response, $this->responses, true)]); |
|
233 | 38 | $this->responses = array_values($this->responses); |
|
234 | 38 | } |
|
235 | } |
||
236 |
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.