MultiRequestErroredEvent::removeResponses()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 6
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 6
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
crap 2
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 MultiRequestErroredEvent 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 HttpAdapterException[]
25
     */
26
    private $exceptions;
27
28
    /**
29
     * @var ResponseInterface[]
30
     */
31
    private $responses = [];
32
33
    /**
34
     * @param HttpAdapterInterface   $httpAdapter
35
     * @param HttpAdapterException[] $exceptions
36
     */
37 207
    public function __construct(HttpAdapterInterface $httpAdapter, array $exceptions)
38
    {
39 207
        parent::__construct($httpAdapter);
40
41 207
        $this->setExceptions($exceptions);
42 207
    }
43
44 207
    public function clearExceptions()
45
    {
46 207
        $this->exceptions = [];
47 207
    }
48
49
    /**
50
     * @return bool
51
     */
52 54
    public function hasExceptions()
53
    {
54 54
        return !empty($this->exceptions);
55
    }
56
57
    /**
58
     * @return HttpAdapterException[]
59
     */
60 135
    public function getExceptions()
61
    {
62 135
        return $this->exceptions;
63
    }
64
65
    /**
66
     * @param HttpAdapterException[] $exceptions
67
     */
68 207
    public function setExceptions(array $exceptions)
69
    {
70 207
        $this->clearExceptions();
71 207
        $this->addExceptions($exceptions);
72 207
    }
73
74
    /**
75
     * @param HttpAdapterException[] $exceptions
76
     */
77 207
    public function addExceptions(array $exceptions)
78
    {
79 207
        foreach ($exceptions as $exception) {
80 207
            $this->addException($exception);
81 161
        }
82 207
    }
83
84
    /**
85
     * @param HttpAdapterException[] $exceptions
86
     */
87 9
    public function removeExceptions(array $exceptions)
88
    {
89 9
        foreach ($exceptions as $exception) {
90 9
            $this->removeException($exception);
91 7
        }
92 9
    }
93
94
    /**
95
     * @param HttpAdapterException $exception
96
     *
97
     * @return bool
98
     */
99 45
    public function hasException(HttpAdapterException $exception)
100
    {
101 45
        return array_search($exception, $this->exceptions, true) !== false;
102
    }
103
104
    /**
105
     * @param HttpAdapterException $exception
106
     */
107 207
    public function addException(HttpAdapterException $exception)
108
    {
109 207
        $this->exceptions[] = $exception;
110 207
    }
111
112
    /**
113
     * @param HttpAdapterException $exception
114
     */
115 36
    public function removeException(HttpAdapterException $exception)
116
    {
117 36
        unset($this->exceptions[array_search($exception, $this->exceptions, true)]);
118 36
        $this->exceptions = array_values($this->exceptions);
119 36
    }
120
121 108
    public function clearResponses()
122
    {
123 108
        $this->responses = [];
124 108
    }
125
126
    /**
127
     * @return bool
128
     */
129 72
    public function hasResponses()
130
    {
131 72
        return !empty($this->responses);
132
    }
133
134
    /**
135
     * @return ResponseInterface[]
136
     */
137 99
    public function getResponses()
138
    {
139 99
        return $this->responses;
140
    }
141
142
    /**
143
     * @param ResponseInterface[] $responses
144
     */
145 108
    public function setResponses(array $responses)
146
    {
147 108
        $this->clearResponses();
148 108
        $this->addResponses($responses);
149 108
    }
150
151
    /**
152
     * @param ResponseInterface[] $responses
153
     */
154 108
    public function addResponses(array $responses)
155
    {
156 108
        foreach ($responses as $response) {
157 72
            $this->addResponse($response);
158 84
        }
159 108
    }
160
161
    /**
162
     * @param ResponseInterface[] $responses
163
     */
164 9
    public function removeResponses(array $responses)
165
    {
166 9
        foreach ($responses as $response) {
167 9
            $this->removeResponse($response);
168 7
        }
169 9
    }
170
171
    /**
172
     * @param ResponseInterface $response
173
     *
174
     * @return bool
175
     */
176 36
    public function hasResponse(ResponseInterface $response)
177
    {
178 36
        return array_search($response, $this->responses, true) !== false;
179
    }
180
181
    /**
182
     * @param ResponseInterface $response
183
     */
184 90
    public function addResponse(ResponseInterface $response)
185
    {
186 90
        $this->responses[] = $response;
187 90
    }
188
189
    /**
190
     * @param ResponseInterface $response
191
     */
192 18
    public function removeResponse(ResponseInterface $response)
193
    {
194 18
        unset($this->responses[array_search($response, $this->responses, true)]);
195 18
        $this->responses = array_values($this->responses);
196 18
    }
197
}
198