Client::getCharacter()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
dl 8
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
1
<?php declare(strict_types = 1);
2
3
namespace Ikoene\MarvelApiBundle\Controller;
4
5
use GuzzleHttp\Client as GuzzleClient;
6
use GuzzleHttp\Exception\ClientException;
7
use GuzzleHttp\Psr7\Response;
8
use Ikoene\MarvelApiBundle\DataWrapper\CharacterDataWrapper;
9
use Ikoene\MarvelApiBundle\DataWrapper\ComicDataWrapper;
10
use Ikoene\MarvelApiBundle\DataWrapper\CreatorDataWrapper;
11
use Ikoene\MarvelApiBundle\DataWrapper\EventDataWrapper;
12
use Ikoene\MarvelApiBundle\DataWrapper\SeriesDataWrapper;
13
use Ikoene\MarvelApiBundle\DataWrapper\StoryDataWrapper;
14
use Ikoene\MarvelApiBundle\Entity\CharacterFilter;
15
use Ikoene\MarvelApiBundle\Entity\ComicFilter;
16
use Ikoene\MarvelApiBundle\Entity\CreatorFilter;
17
use Ikoene\MarvelApiBundle\Entity\EventFilter;
18
use Ikoene\MarvelApiBundle\Entity\SeriesFilter;
19
use Ikoene\MarvelApiBundle\Entity\StoryFilter;
20
use JMS\Serializer\SerializerBuilder;
21
22
/**
23
 * Class Client
24
 * @package Ikoene\MarvelApiBundle\Controller
25
 */
26
class Client
27
{
28
    /**
29
     * @var string
30
     */
31
    private $baseUrl = 'http://gateway.marvel.com/v1/public/';
32
33
    /**
34
     * @var string
35
     */
36
    private $publicApiKey;
37
38
    /**
39
     * @var string
40
     */
41
    private $privateApiKey;
42
43
    /**
44
     * @param string $publicApiKey
45
     * @param string $privateApiKey
46
     */
47
    public function __construct(string $publicApiKey, string $privateApiKey)
48
    {
49
        $this->publicApiKey = $publicApiKey;
50
        $this->privateApiKey = $privateApiKey;
51
    }
52
53
    /**
54
     * Fetches lists of comic characters with optional filters.
55
     *
56
     * @param CharacterFilter|null $characterFilter
57
     *
58
     * @return CharacterDataWrapper
59
     */
60
    public function getCharacters(CharacterFilter $characterFilter = null) : CharacterDataWrapper
61
    {
62
        $response = $this->call('characters', $characterFilter);
63
64
        $formattedResponse = $this->formatResponse($response, CharacterDataWrapper::class);
65
66
        return $formattedResponse;
67
    }
68
69
    /**
70
     * This method fetches a single character resource.
71
     *
72
     * @param int $id
73
     *
74
     * @return CharacterDataWrapper
75
     */
76 View Code Duplication
    public function getCharacter(int $id) : CharacterDataWrapper
0 ignored issues
show
Duplication introduced by
This method 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...
77
    {
78
        $response = $this->call('characters/' . $id);
79
80
        $formattedResponse = $this->formatResponse($response, CharacterDataWrapper::class);
81
82
        return $formattedResponse;
83
    }
84
85
    /**
86
     * Fetches lists of comics containing a specific character, with optional filters.
87
     *
88
     * @param int $id
89
     * @param ComicFilter $comicFilter
90
     *
91
     * @return ComicDataWrapper
92
     */
93 View Code Duplication
    public function getComicsForCharacter(int $id, ComicFilter $comicFilter = null) : ComicDataWrapper
0 ignored issues
show
Duplication introduced by
This method 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...
94
    {
95
        $response = $this->call('characters/' . $id . '/comics', $comicFilter);
96
97
        $formattedResponse = $this->formatResponse($response, ComicDataWrapper::class);
98
99
        return $formattedResponse;
100
    }
101
102
    /**
103
     * Fetches lists of events in which a specific character appears, with optional filters.
104
     *
105
     * @param int $id
106
     * @param EventFilter $eventFilter
107
     *
108
     * @return EventDataWrapper
109
     */
110
    public function getEventsForCharacter(int $id, EventFilter $eventFilter = null) : EventDataWrapper
111
    {
112
        $response = $this->call('characters/' . $id . '/events', $eventFilter);
113
114
        $formattedResponse = $this->formatResponse($response, EventDataWrapper::class);
115
116
        return $formattedResponse;
117
    }
118
119
    /**
120
     * Fetches lists of comic series in which a specific character appears, with optional filters.
121
     *
122
     * @param int $id
123
     * @param SeriesFilter $seriesFilter
124
     *
125
     * @return SeriesDataWrapper
126
     */
127 View Code Duplication
    public function getSeriesForCharacter(int $id, SeriesFilter $seriesFilter = null) : SeriesDataWrapper
0 ignored issues
show
Duplication introduced by
This method 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...
128
    {
129
        $response = $this->call('characters/' . $id . '/series', $seriesFilter);
130
131
        $formattedResponse = $this->formatResponse($response, SeriesDataWrapper::class);
132
133
        return $formattedResponse;
134
    }
135
136
    /**
137
     * Fetches lists of comic stories featuring a specific character with optional filters.
138
     *
139
     * @param int $id
140
     * @param StoryFilter $storyFilter
141
     *
142
     * @return StoryDataWrapper
143
     */
144 View Code Duplication
    public function getStoriesForCharacter(int $id, StoryFilter $storyFilter = null) : StoryDataWrapper
0 ignored issues
show
Duplication introduced by
This method 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...
145
    {
146
        $response = $this->call('characters/' . $id . '/stories', $storyFilter);
147
148
        $formattedResponse = $this->formatResponse($response, StoryDataWrapper::class);
149
150
        return $formattedResponse;
151
    }
152
153
    /**
154
     * Fetches lists of comics with optional filters.
155
     *
156
     * @param ComicFilter|null $comicFilter
157
     *
158
     * @return ComicDataWrapper
159
     */
160 View Code Duplication
    public function getComics(ComicFilter $comicFilter = null) : ComicDataWrapper
0 ignored issues
show
Duplication introduced by
This method 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...
161
    {
162
        $response = $this->call('comics', $comicFilter);
163
164
        $formattedResponse = $this->formatResponse($response, ComicDataWrapper::class);
165
166
        return $formattedResponse;
167
    }
168
169
    /**
170
     * This method fetches a single comic resource.
171
     *
172
     * @param int $id
173
     *
174
     * @return ComicDataWrapper
175
     */
176 View Code Duplication
    public function getComic(int $id) : ComicDataWrapper
0 ignored issues
show
Duplication introduced by
This method 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...
177
    {
178
        $response = $this->call('comics/' . $id);
179
180
        $formattedResponse = $this->formatResponse($response, ComicDataWrapper::class);
181
182
        return $formattedResponse;
183
    }
184
185
    /**
186
     * Fetches lists of characters which appear in a specific comic with optional filters.
187
     *
188
     * @param int $id
189
     * @param CharacterFilter $characterFilter
190
     *
191
     * @return CharacterDataWrapper
192
     */
193 View Code Duplication
    public function getCharactersForComic(int $id, CharacterFilter $characterFilter = null) : CharacterDataWrapper
0 ignored issues
show
Duplication introduced by
This method 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...
194
    {
195
        $response = $this->call('comics/' . $id . '/characters', $characterFilter);
196
197
        $formattedResponse = $this->formatResponse($response, CharacterDataWrapper::class);
198
199
        return $formattedResponse;
200
    }
201
202
    /**
203
     * Fetches lists of comic creators whose work appears in a specific comic, with optional filters.
204
     *
205
     * @param int $id
206
     * @param CreatorFilter $creatorFilter
207
     *
208
     * @return CreatorDataWrapper
209
     */
210 View Code Duplication
    public function getCreatorsForComics(int $id, CreatorFilter $creatorFilter = null) : CreatorDataWrapper
0 ignored issues
show
Duplication introduced by
This method 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...
211
    {
212
        $response = $this->call('comics/' . $id . '/creators', $creatorFilter);
213
214
        $formattedResponse = $this->formatResponse($response, CreatorDataWrapper::class);
215
216
        return $formattedResponse;
217
    }
218
219
    /**
220
     * Fetches lists of events in which a specific comic appears, with optional filters.
221
     *
222
     * @param int $id
223
     * @param EventFilter $eventFilter
224
     *
225
     * @return EventDataWrapper
226
     */
227
    public function getEventsForComics(int $id, EventFilter $eventFilter = null) : EventDataWrapper
228
    {
229
        $response = $this->call('comics/' . $id . '/events', $eventFilter);
230
231
        $formattedResponse = $this->formatResponse($response, EventDataWrapper::class);
232
233
        return $formattedResponse;
234
    }
235
236
    /**
237
     * Fetches lists of comic stories in a specific comic issue, with optional filters.
238
     *
239
     * @param int $id
240
     * @param EventFilter $storyFilter
241
     *
242
     * @return StoryDataWrapper
243
     */
244 View Code Duplication
    public function getStoriesForComics(int $id, EventFilter $storyFilter = null) : StoryDataWrapper
0 ignored issues
show
Duplication introduced by
This method 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...
245
    {
246
        $response = $this->call('comics/' . $id . '/stories', $storyFilter);
247
248
        $formattedResponse = $this->formatResponse($response, StoryDataWrapper::class);
249
250
        return $formattedResponse;
251
    }
252
253
    /**
254
     * Fetches lists of events with optional filters.
255
     *
256
     * @param EventFilter|null $eventFilter
257
     *
258
     * @return EventDataWrapper
259
     */
260
    public function getEvents(EventFilter $eventFilter = null) : EventDataWrapper
261
    {
262
        $response = $this->call('events', $eventFilter);
263
264
        $formattedResponse = $this->formatResponse($response, EventDataWrapper::class);
265
266
        return $formattedResponse;
267
    }
268
269
    /**
270
     * This method fetches a single event resource.
271
     *
272
     * @param int $id
273
     *
274
     * @return EventDataWrapper
275
     */
276
    public function getEvent(int $id) : EventDataWrapper
277
    {
278
        $response = $this->call('events/' . $id);
279
280
        $formattedResponse = $this->formatResponse($response, EventDataWrapper::class);
281
282
        return $formattedResponse;
283
    }
284
285
    /**
286
     * Fetches lists of characters which appear in a specific event, with optional filters.
287
     *
288
     * @param int $id
289
     * @param CharacterFilter $characterFilter
290
     *
291
     * @return CharacterDataWrapper
292
     */
293 View Code Duplication
    public function getCharactersForEvent(int $id, CharacterFilter $characterFilter = null) : CharacterDataWrapper
0 ignored issues
show
Duplication introduced by
This method 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...
294
    {
295
        $response = $this->call('events/' . $id . '/characters', $characterFilter);
296
297
        $formattedResponse = $this->formatResponse($response, CharacterDataWrapper::class);
298
299
        return $formattedResponse;
300
    }
301
302
    /**
303
     * Fetches lists of comics which take place during a specific event, with optional filters.
304
     *
305
     * @param int $id
306
     * @param ComicFilter $comicFilter
307
     *
308
     * @return ComicDataWrapper
309
     */
310 View Code Duplication
    public function getComicsForEvent(int $id, ComicFilter $comicFilter = null) : ComicDataWrapper
0 ignored issues
show
Duplication introduced by
This method 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...
311
    {
312
        $response = $this->call('events/' . $id . '/comics', $comicFilter);
313
314
        $formattedResponse = $this->formatResponse($response, ComicDataWrapper::class);
315
316
        return $formattedResponse;
317
    }
318
319
    /**
320
     * Fetches lists of comic creators whose work appears in a specific event, with optional filters.
321
     *
322
     * @param int $id
323
     * @param CreatorFilter $creatorFilter
324
     *
325
     * @return CreatorDataWrapper
326
     */
327 View Code Duplication
    public function getCreatorsForEvent(int $id, CreatorFilter $creatorFilter = null) : CreatorDataWrapper
0 ignored issues
show
Duplication introduced by
This method 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...
328
    {
329
        $response = $this->call('events/' . $id . '/creators', $creatorFilter);
330
331
        $formattedResponse = $this->formatResponse($response, CreatorDataWrapper::class);
332
333
        return $formattedResponse;
334
    }
335
336
    /**
337
     * Fetches lists of comic series in which a specific event takes place, with optional filters.
338
     *
339
     * @param int $id
340
     * @param SeriesFilter $seriesFilter
341
     *
342
     * @return SeriesDataWrapper
343
     */
344 View Code Duplication
    public function getSeriesForEvent(int $id, SeriesFilter $seriesFilter = null) : SeriesDataWrapper
0 ignored issues
show
Duplication introduced by
This method 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...
345
    {
346
        $response = $this->call('events/' . $id . '/series', $seriesFilter);
347
348
        $formattedResponse = $this->formatResponse($response, SeriesDataWrapper::class);
349
350
        return $formattedResponse;
351
    }
352
353
    /**
354
     * Fetches lists of comic stories from a specific event, with optional filters.
355
     *
356
     * @param int $id
357
     * @param StoryFilter $storyFilter
358
     *
359
     * @return StoryDataWrapper
360
     */
361 View Code Duplication
    public function getStoriesForEvent(int $id, StoryFilter $storyFilter = null) : StoryDataWrapper
0 ignored issues
show
Duplication introduced by
This method 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...
362
    {
363
        $response = $this->call('events/' . $id . '/stories', $storyFilter);
364
365
        $formattedResponse = $this->formatResponse($response, StoryDataWrapper::class);
366
367
        return $formattedResponse;
368
    }
369
370
    /**
371
     * Fetches lists of comic creators with optional filters.
372
     *
373
     * @param CreatorFilter|null $creatorFilter
374
     *
375
     * @return CreatorDataWrapper
376
     */
377 View Code Duplication
    public function getCreators(CreatorFilter $creatorFilter = null) : CreatorDataWrapper
0 ignored issues
show
Duplication introduced by
This method 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...
378
    {
379
        $response = $this->call('creators', $creatorFilter);
380
381
        $formattedResponse = $this->formatResponse($response, CreatorDataWrapper::class);
382
383
        return $formattedResponse;
384
    }
385
386
    /**
387
     * This method fetches a single creator resource.
388
     *
389
     * @param int $id
390
     *
391
     * @return CreatorDataWrapper
392
     */
393 View Code Duplication
    public function getCreator(int $id) : CreatorDataWrapper
0 ignored issues
show
Duplication introduced by
This method 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...
394
    {
395
        $response = $this->call('creators/' . $id);
396
397
        $formattedResponse = $this->formatResponse($response, CreatorDataWrapper::class);
398
399
        return $formattedResponse;
400
    }
401
402
    /**
403
     * Fetches lists of events featuring the work of a specific creator with optional filters.
404
     *
405
     * @param int $id
406
     * @param CreatorFilter $creatorFilter
407
     *
408
     * @return CreatorDataWrapper
409
     */
410 View Code Duplication
    public function getComicsForCreator(int $id, CreatorFilter $creatorFilter = null) : CreatorDataWrapper
0 ignored issues
show
Duplication introduced by
This method 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...
411
    {
412
        $response = $this->call('creators/' . $id . '/comics', $creatorFilter);
413
414
        $formattedResponse = $this->formatResponse($response, CreatorDataWrapper::class);
415
416
        return $formattedResponse;
417
    }
418
419
    /**
420
     * Fetches lists of comic series in which a specific creator's work appears, with optional filters.
421
     *
422
     * @param int $id
423
     * @param SeriesFilter $seriesFilter
424
     *
425
     * @return SeriesDataWrapper
426
     */
427 View Code Duplication
    public function getSeriesForCreator(int $id, SeriesFilter $seriesFilter = null) : SeriesDataWrapper
0 ignored issues
show
Duplication introduced by
This method 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...
428
    {
429
        $response = $this->call('creators/' . $id . '/series', $seriesFilter);
430
431
        $formattedResponse = $this->formatResponse($response, SeriesDataWrapper::class);
432
433
        return $formattedResponse;
434
    }
435
436
    /**
437
     * Fetches lists of comic stories by a specific creator with optional filters.
438
     *
439
     * @param int $id
440
     * @param StoryFilter $storyFilter
441
     *
442
     * @return StoryDataWrapper
443
     */
444 View Code Duplication
    public function getStoriesForCreator(int $id, StoryFilter $storyFilter = null) : StoryDataWrapper
0 ignored issues
show
Duplication introduced by
This method 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...
445
    {
446
        $response = $this->call('creators/' . $id . '/stories', $storyFilter);
447
448
        $formattedResponse = $this->formatResponse($response, StoryDataWrapper::class);
449
450
        return $formattedResponse;
451
    }
452
453
    /**
454
     * Fetches lists of comic series with optional filters.
455
     *
456
     * @param SeriesFilter|null $seriesFilter
457
     *
458
     * @return SeriesDataWrapper
459
     */
460 View Code Duplication
    public function getSeries(SeriesFilter $seriesFilter = null) : SeriesDataWrapper
0 ignored issues
show
Duplication introduced by
This method 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...
461
    {
462
        $response = $this->call('series', $seriesFilter);
463
464
        $formattedResponse = $this->formatResponse($response, SeriesDataWrapper::class);
465
466
        return $formattedResponse;
467
    }
468
469
    /**
470
     * This method fetches a single comic series resource.
471
     *
472
     * @param int $id
473
     *
474
     * @return SeriesDataWrapper
475
     */
476 View Code Duplication
    public function getASeries(int $id) : SeriesDataWrapper
0 ignored issues
show
Duplication introduced by
This method 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...
477
    {
478
        $response = $this->call('series/' . $id);
479
480
        $formattedResponse = $this->formatResponse($response, SeriesDataWrapper::class);
481
482
        return $formattedResponse;
483
    }
484
485
    /**
486
     * Fetches lists of characters which appear in specific series, with optional filters.
487
     *
488
     * @param int $id
489
     * @param CharacterFilter $characterFilter
490
     *
491
     * @return CharacterDataWrapper
492
     */
493 View Code Duplication
    public function getCharactersForSeries(int $id, CharacterFilter $characterFilter = null) : CharacterDataWrapper
0 ignored issues
show
Duplication introduced by
This method 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...
494
    {
495
        $response = $this->call('series/' . $id . '/characters', $characterFilter);
496
497
        $formattedResponse = $this->formatResponse($response, CharacterDataWrapper::class);
498
499
        return $formattedResponse;
500
    }
501
502
    /**
503
     * Fetches lists of comics which are published as part of a specific series, with optional filters.
504
     *
505
     * @param int $id
506
     * @param ComicFilter $comicFilter
507
     *
508
     * @return ComicDataWrapper
509
     */
510 View Code Duplication
    public function getComicsForSeries(int $id, ComicFilter $comicFilter = null) : ComicDataWrapper
0 ignored issues
show
Duplication introduced by
This method 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...
511
    {
512
        $response = $this->call('series/' . $id . '/comics', $comicFilter);
513
514
        $formattedResponse = $this->formatResponse($response, ComicDataWrapper::class);
515
516
        return $formattedResponse;
517
    }
518
519
    /**
520
     * Fetches lists of comic creators whose work appears in a specific series, with optional filters.
521
     *
522
     * @param int $id
523
     * @param CreatorFilter $creatorFilter
524
     *
525
     * @return CreatorDataWrapper
526
     */
527 View Code Duplication
    public function getCreatorsForSeries(int $id, CreatorFilter $creatorFilter = null) : CreatorDataWrapper
0 ignored issues
show
Duplication introduced by
This method 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...
528
    {
529
        $response = $this->call('series/' . $id . '/creators', $creatorFilter);
530
531
        $formattedResponse = $this->formatResponse($response, CreatorDataWrapper::class);
532
533
        return $formattedResponse;
534
    }
535
536
    /**
537
     * Fetches lists of events which occur in a specific series, with optional filters.
538
     *
539
     * @param int $id
540
     * @param EventFilter $eventFilter
541
     *
542
     * @return EventDataWrapper
543
     */
544
    public function getEventsForSeries(int $id, EventFilter $eventFilter = null) : EventDataWrapper
545
    {
546
        $response = $this->call('series/' . $id . '/events', $eventFilter);
547
548
        $formattedResponse = $this->formatResponse($response, EventDataWrapper::class);
549
550
        return $formattedResponse;
551
    }
552
553
    /**
554
     * Fetches lists of comic stories from a specific series with optional filters.
555
     *
556
     * @param int $id
557
     * @param StoryFilter $storyFilter
558
     *
559
     * @return StoryDataWrapper
560
     */
561 View Code Duplication
    public function getStoriesForSeries(int $id, StoryFilter $storyFilter = null) : StoryDataWrapper
0 ignored issues
show
Duplication introduced by
This method 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...
562
    {
563
        $response = $this->call('series/' . $id . '/stories', $storyFilter);
564
565
        $formattedResponse = $this->formatResponse($response, StoryDataWrapper::class);
566
567
        return $formattedResponse;
568
    }
569
570
    /**
571
     * Fetches lists of comic stories with optional filters.
572
     *
573
     * @param StoryFilter|null $storyFilter
574
     *
575
     * @return StoryDataWrapper
576
     */
577 View Code Duplication
    public function getStories(StoryFilter $storyFilter = null) : StoryDataWrapper
0 ignored issues
show
Duplication introduced by
This method 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...
578
    {
579
        $response = $this->call('stories', $storyFilter);
580
581
        $formattedResponse = $this->formatResponse($response, StoryDataWrapper::class);
582
583
        return $formattedResponse;
584
    }
585
586
    /**
587
     * This method fetches a single comic story resource.
588
     *
589
     * @param int $id
590
     *
591
     * @return StoryDataWrapper
592
     */
593 View Code Duplication
    public function getStory(int $id) : StoryDataWrapper
0 ignored issues
show
Duplication introduced by
This method 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...
594
    {
595
        $response = $this->call('stories/' . $id);
596
597
        $formattedResponse = $this->formatResponse($response, StoryDataWrapper::class);
598
599
        return $formattedResponse;
600
    }
601
602
    /**
603
     * Fetches lists of comic characters appearing in a single story, with optional filters.
604
     *
605
     * @param int $id
606
     * @param CharacterFilter $characterFilter
607
     *
608
     * @return CharacterDataWrapper
609
     */
610 View Code Duplication
    public function getCharactersForStory(int $id, CharacterFilter $characterFilter = null) : CharacterDataWrapper
0 ignored issues
show
Duplication introduced by
This method 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...
611
    {
612
        $response = $this->call('stories/' . $id . '/characters', $characterFilter);
613
614
        $formattedResponse = $this->formatResponse($response, CharacterDataWrapper::class);
615
616
        return $formattedResponse;
617
    }
618
619
    /**
620
     * Fetches lists of comics in which a specific story appears, with optional filters.
621
     *
622
     * @param int $id
623
     * @param ComicFilter $comicFilter
624
     *
625
     * @return ComicDataWrapper
626
     */
627 View Code Duplication
    public function getComicsForStory(int $id, ComicFilter $comicFilter = null) : ComicDataWrapper
0 ignored issues
show
Duplication introduced by
This method 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...
628
    {
629
        $response = $this->call('stories/' . $id . '/comics', $comicFilter);
630
631
        $formattedResponse = $this->formatResponse($response, ComicDataWrapper::class);
632
633
        return $formattedResponse;
634
    }
635
636
    /**
637
     * Fetches lists of comic creators whose work appears in a specific story, with optional filters.
638
     *
639
     * @param int $id
640
     * @param CreatorFilter $creatorFilter
641
     *
642
     * @return CreatorDataWrapper
643
     */
644 View Code Duplication
    public function getCreatorsForStory(int $id, CreatorFilter $creatorFilter = null) : CreatorDataWrapper
0 ignored issues
show
Duplication introduced by
This method 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...
645
    {
646
        $response = $this->call('stories/' . $id . '/creators', $creatorFilter);
647
648
        $formattedResponse = $this->formatResponse($response, CreatorDataWrapper::class);
649
650
        return $formattedResponse;
651
    }
652
653
    /**
654
     * Fetches lists of events in which a specific story appears, with optional filters.
655
     *
656
     * @param int $id
657
     * @param EventFilter $eventFilter
658
     *
659
     * @return EventDataWrapper
660
     */
661
    public function getEventsForStory(int $id, EventFilter $eventFilter = null) : EventDataWrapper
662
    {
663
        $response = $this->call('stories/' . $id . '/events', $eventFilter);
664
665
        $formattedResponse = $this->formatResponse($response, EventDataWrapper::class);
666
667
        return $formattedResponse;
668
    }
669
670
    /**
671
     * Fetches lists of comic series in which the specified story takes place.
672
     *
673
     * @param int $id
674
     * @param SeriesFilter $seriesFilter
675
     *
676
     * @return SeriesDataWrapper
677
     */
678 View Code Duplication
    public function getSeriesForStory(int $id, SeriesFilter $seriesFilter = null) : SeriesDataWrapper
0 ignored issues
show
Duplication introduced by
This method 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...
679
    {
680
        $response = $this->call('stories/' . $id . '/series', $seriesFilter);
681
682
        $formattedResponse = $this->formatResponse($response, SeriesDataWrapper::class);
683
684
        return $formattedResponse;
685
    }
686
687
    /**
688
     * @param string $operation
689
     * @param object|null $query
690
     *
691
     * @return Response
692
     */
693
    private function call(string $operation, $query = null) : Response
694
    {
695
        $url = $this->baseUrl . $operation;
696
697
        $params = array();
698
        if (!empty($query)) {
699
            $params = get_object_vars($query);
700
        }
701
702
        return $this->send($url, $params);
703
    }
704
705
    /**
706
     * @param string $url
707
     * @param array $params
708
     *
709
     * @return Response
710
     */
711
    private function send(string $url, array $params = array()) : Response
712
    {
713
        $client = new GuzzleClient();
714
715
        $query = [
716
            'ts' => time(),
717
            'apikey' => $this->publicApiKey,
718
            'hash' => md5(time() . $this->privateApiKey . $this->publicApiKey),
719
        ];
720
721
        foreach (array_filter($params) as $key => $value) {
722
            $query[$key] = $value;
723
        }
724
725
        try {
726
            return $client->request('GET', $url, ['query' => $query]);
727
        } catch (ClientException $e) {
728
            if ($e->hasResponse()) {
729
                throw new ClientException($e->getMessage(), $e->getRequest());
730
            }
731
        }
732
    }
733
734
    /**
735
     * @param Response $response
736
     * @param string $dataWrapper
737
     *
738
     * @return Object
739
     */
740
    private function formatResponse(Response $response, string $dataWrapper)
741
    {
742
        $serializer = SerializerBuilder::create()
743
            ->addMetadataDir(__DIR__ . '/../Serializer', 'Ikoene\MarvelApiBundle')
744
            ->build();
745
746
        return $serializer->deserialize($response->getBody()->getContents(), $dataWrapper, 'json');
747
    }
748
}
749