Code Duplication    Length = 213-214 lines in 3 locations

src/Event/MultiRequestErroredEvent.php 1 location

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

src/Event/MultiRequestSentEvent.php 1 location

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

src/MultiHttpAdapterException.php 1 location

@@ 19-232 (lines=214) @@
16
/**
17
 * @author GeLo <[email protected]>
18
 */
19
class MultiHttpAdapterException extends \Exception
20
{
21
    /**
22
     * @var array
23
     */
24
    private $exceptions;
25
26
    /**
27
     * @var array
28
     */
29
    private $responses;
30
31
    /**
32
     * @param array $exceptions
33
     * @param array $responses
34
     */
35
    public function __construct(array $exceptions = [], array $responses = [])
36
    {
37
        parent::__construct('An error occurred when sending multiple requests.');
38
39
        $this->setExceptions($exceptions);
40
        $this->setResponses($responses);
41
    }
42
43
    public function clearExceptions()
44
    {
45
        $this->exceptions = [];
46
    }
47
48
    /**
49
     * @return bool
50
     */
51
    public function hasExceptions()
52
    {
53
        return !empty($this->exceptions);
54
    }
55
56
    /**
57
     * @return array
58
     */
59
    public function getExceptions()
60
    {
61
        return $this->exceptions;
62
    }
63
64
    /**
65
     * @param array $exceptions
66
     */
67
    public function setExceptions(array $exceptions)
68
    {
69
        $this->clearExceptions();
70
        $this->addExceptions($exceptions);
71
    }
72
73
    /**
74
     * @param array $exceptions
75
     */
76
    public function addExceptions(array $exceptions)
77
    {
78
        foreach ($exceptions as $exception) {
79
            $this->addException($exception);
80
        }
81
    }
82
83
    /**
84
     * @param array $exceptions
85
     */
86
    public function removeExceptions(array $exceptions)
87
    {
88
        foreach ($exceptions as $exception) {
89
            $this->removeException($exception);
90
        }
91
    }
92
93
    /**
94
     * @param HttpAdapterException $exception
95
     *
96
     * @return bool
97
     */
98
    public function hasException(HttpAdapterException $exception)
99
    {
100
        return array_search($exception, $this->exceptions, true) !== false;
101
    }
102
103
    /**
104
     * @param HttpAdapterException $exception
105
     */
106
    public function addException(HttpAdapterException $exception)
107
    {
108
        $this->exceptions[] = $exception;
109
    }
110
111
    /**
112
     * @param HttpAdapterException $exception
113
     */
114
    public function removeException(HttpAdapterException $exception)
115
    {
116
        unset($this->exceptions[array_search($exception, $this->exceptions, true)]);
117
        $this->exceptions = array_values($this->exceptions);
118
    }
119
120
    public function clearResponses()
121
    {
122
        $this->responses = [];
123
    }
124
125
    /**
126
     * @return bool
127
     */
128
    public function hasResponses()
129
    {
130
        return !empty($this->responses);
131
    }
132
133
    /**
134
     * @return array
135
     */
136
    public function getResponses()
137
    {
138
        return $this->responses;
139
    }
140
141
    /**
142
     * @param array $responses
143
     */
144
    public function setResponses(array $responses)
145
    {
146
        $this->clearResponses();
147
        $this->addResponses($responses);
148
    }
149
150
    /**
151
     * @param array
152
     */
153
    public function addResponses(array $responses)
154
    {
155
        foreach ($responses as $response) {
156
            $this->addResponse($response);
157
        }
158
    }
159
160
    /**
161
     * @param array $responses
162
     */
163
    public function removeResponses(array $responses)
164
    {
165
        foreach ($responses as $response) {
166
            $this->removeResponse($response);
167
        }
168
    }
169
170
    /**
171
     * @param ResponseInterface $response
172
     *
173
     * @return bool
174
     */
175
    public function hasResponse(ResponseInterface $response)
176
    {
177
        return array_search($response, $this->responses, true) !== false;
178
    }
179
180
    /**
181
     * @param ResponseInterface $response
182
     */
183
    public function addResponse(ResponseInterface $response)
184
    {
185
        $this->responses[] = $response;
186
    }
187
188
    /**
189
     * @param ResponseInterface $response
190
     */
191
    public function removeResponse(ResponseInterface $response)
192
    {
193
        unset($this->responses[array_search($response, $this->responses, true)]);
194
        $this->responses = array_values($this->responses);
195
    }
196
}
197