Bookwhen::events()   F
last analyzed

Complexity

Conditions 29
Paths 668

Size

Total Lines 198
Code Lines 114

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 65
CRAP Score 79.8528

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 29
eloc 114
c 3
b 0
f 0
nc 668
nop 13
dl 0
loc 198
ccs 65
cts 107
cp 0.6075
crap 79.8528
rs 0.3688

How to fix   Long Method    Complexity    Many Parameters   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace InShore\Bookwhen;
6
7
use InShore\Bookwhen\BookwhenApi;
8
use InShore\Bookwhen\Client;
9
use InShore\Bookwhen\Domain\Attachment;
10
use InShore\Bookwhen\Domain\ClassPass;
11
use InShore\Bookwhen\Domain\Event;
12
use InShore\Bookwhen\Domain\Location;
13
use InShore\Bookwhen\Domain\Ticket;
14
use InShore\Bookwhen\Exceptions\ConfigurationException;
15
use InShore\Bookwhen\Exceptions\ValidationException;
16
use InShore\Bookwhen\Interfaces\BookwhenInterface;
17
use InShore\Bookwhen\Validator;
18
use Monolog\Level;
19
use Monolog\Logger;
20
use Monolog\Handler\StreamHandler;
21
22
final class Bookwhen implements BookwhenInterface
23
{
24
    /**
25
     *
26
     */
27
    public Attachment $attachment;
28
29
    /**
30
     *
31
     */
32
    public array $attachments = [];
33
34
    /**
35
     *
36
     */
37
    public Client $client;
38
39
    /**
40
     *
41
     */
42
    public ClassPass $classPass;
43
44
    /**
45
     *
46
     */
47
    public array $classPasses = [];
48
49
    /**
50
     *
51
     */
52
    public Event $event;
53
54
    /**
55
     *
56
     */
57
    public array $events = [];
58
59
    /**
60
     *
61
     */
62
    private array $filters = [];
63
64
    /**
65
     *
66
     */
67
    public Location $location;
68
69
    /**
70
     *
71
     */
72
    public array $includes = [];
73
74
    /**
75
     *
76
     */
77
    public Ticket $ticket;
78
79
    /**
80
     *
81
     */
82
    public array $tickets = [];
83
84
    /**
85
     *
86
     */
87
    public $locations = [];
88
89
90
    /** @var string The path to the log file */
91
    //private $logFile;
92
93
    /** @var object loging object. */
94
    //private $logger;
95
96
    /** @var string the logging level. */
97
    //private string $logLevel;
98
99
    /**
100
     * Creates a new Bookwhen Client with the given API token.
101
     * @throws ConfigurationException
102
     * @todo logging
103
     */
104 20
    public function __construct(
105
        string $apiKey = null,
106
        Client $client = null,
107
        private $validator = new Validator()
108
    ) {
109
        //         $this->logFile = $logFile;
110
        //         $this->logLevel = $logLevel;
111
        //         $this->logger = new Logger('inShore Bookwhen API');
112
        //         $this->logger->pushHandler(new StreamHandler($this->logFile, $this->logLevel));
113
        try {
114 20
            if(!is_null($client)) {
115 11
                $this->client = $client;
116
            } else {
117 9
                $this->client = !is_null($apiKey)
118 9
                ? BookwhenApi::client($apiKey)
119 1
                : (array_key_exists('INSHORE_BOOKWHEN_API_KEY', $_ENV)
120
                    ? BookwhenApi::client($_ENV['INSHORE_BOOKWHEN_API_KEY'])
121 20
                    : throw new ConfigurationException());
122
            }
123 1
        } catch (\TypeError $e) {
124
            throw new ConfigurationException(); // @todo message
125
        }
126
    }
127
128
    /**
129
     *
130
     * @param string $filter
131
     * @param string $value
132
     * @param string $validator
133
     * @throws ValidationException
134 3
     */
135
    public function addFilter(string $filter, null | string $value, string $validator): void
136 3
    {
137 2
138
        if (!is_null($value) && !$this->validator->$validator($value)) {
139
            throw new ValidationException($filter, $value);
140 1
        } else {
141
            $this->filters['filter[' . $filter . ']'] = $value;
142 1
        }
143 1
    }
144 1
145 1
    /**
146 1
     *
147 1
     * {@inheritDoc}
148 1
     * @see \InShore\Bookwhen\Interfaces\ClientInterface::attachment()
149 1
     * @todo all attachment properties
150 1
     */
151 1
    public function attachment(string $attachmentId): Attachment
152
    {
153
        if (!$this->validator->validId($attachmentId, 'attachment')) {
154
            throw new ValidationException('attachmentId', $attachmentId);
155
        }
156
157
        $attachment = $this->client->attachments()->retrieve($attachmentId);
158
159
        return $this->attachment = new Attachment(
160 1
            $attachment->contentType,
161
            $attachment->fileUrl,
162
            $attachment->fileSizeBytes,
163
            $attachment->fileSizeText,
164
            $attachment->fileName,
165
            $attachment->fileType,
166
            $attachment->id,
167 1
            $attachment->title,
168
        );
169
    }
170
171
    /**
172
     *
173
     * {@inheritDoc}
174
     *
175 1
     * @see \InShore\Bookwhen\Interfaces\BookwhenInterface::attachment()
176
     */
177
    public function attachments(
178 1
        string $title = null,
179
        string $fileName = null,
180
        string $fileType = null
181 1
    ): array {
182
183
        $this->addFilter('title', $title, 'validTitle');
184 1
185
        $this->addFilter('file_name', $fileName, 'validFileName');
186
187 1
        $this->addFilter('file_type', $fileType, 'validFileType');
188
189 1
        $attachments = $this->client->attachments()->list($this->filters);
190 1
191 1
        foreach ($attachments->data as $attachment) {
192 1
            array_push($this->attachments, new Attachment(
193 1
                $attachment->contentType,
194 1
                $attachment->fileUrl,
195 1
                $attachment->fileSizeBytes,
196 1
                $attachment->fileSizeText,
197 1
                $attachment->fileName,
198 1
                $attachment->fileType,
199 1
                $attachment->id,
200
                $attachment->title
201
            ));
202 1
        }
203
204
        return $this->attachments;
205
    }
206
207
    /**
208
     *
209
     * {@inheritDoc}
210
     * @see \InShore\Bookwhen\Interfaces\ClientInterface::getClassPass()
211 1
     * @todo
212
     */
213
    public function classPass(string $classPassId): ClassPass
214
    {
215 1
216
        if (!$this->validator->validId($classPassId, 'classPass')) {
217
            throw new ValidationException('classPassId', $classPassId);
218
        }
219 1
220
        $classPass = $this->client->classPasses()->retrieve($classPassId);
221 1
222 1
        return new ClassPass(
223 1
            $classPass->details,
224 1
            $classPass->id,
225 1
            $classPass->numberAvailable,
226 1
            $classPass->title,
227 1
            $classPass->usageAllowance,
228 1
            $classPass->usageType,
229 1
            $classPass->useRestrictedForDays
230
        );
231
    }
232
233
    /**
234
     *
235
     * {@inheritDoc}
236
     * @see \InShore\Bookwhen\Interfaces\ClientInterface::getClassPasses()
237 1
     */
238
    public function classPasses(
239
        $cost = null,
240
        $detail = null,
241
        $title = null,
242
        $usageAllowance = null,
243
        $usageType = null,
244
        $useRestrictedForDays = null
245
    ): array {
246
247
        $this->addFilter('detail', $detail, 'validDetails');
248 1
249
        $this->addFilter('title', $title, 'validTitle');
250
251 1
        $this->addFilter('usage_allowance', $usageAllowance, 'validUsageAllowance');
252
253
        $this->addFilter('usage_type', $usageType, 'validUsageType');
254 1
255
        $this->addFilter('use_restricted_for_days', $useRestrictedForDays, 'validUseRestrictedForDays');
256
257 1
        $classPasses = $this->client->classPasses()->list($this->filters);
258
259
        foreach ($classPasses->data as $classPass) {
260 1
            array_push($this->classPasses, new ClassPass(
261
                $classPass->details,
262
                $classPass->id,
263 1
                $classPass->numberAvailable,
264
                $classPass->title,
265
                $classPass->usageAllowance,
266 1
                $classPass->usageType,
267
                $classPass->useRestrictedForDays,
268
            ));
269 1
        }
270
        return $this->classPasses;
271
    }
272 1
273
    /**
274
     *
275 1
     * {@inheritDoc}
276
     * @see \InShore\Bookwhen\Interfaces\BookwhenInterface::event()
277
     */
278 1
    public function event(
279
        string $eventId,
280 1
        bool $includeAttachments = false,
281 1
        bool $includeLocation = false,
282 1
        bool $includeTickets = false,
283 1
        bool $includeTicketsClassPasses = false,
284 1
        bool $includeTicketsEvents = false
285 1
    ): Event {
286 1
287 1
        if (!$this->validator->validId($eventId, 'event')) {
288 1
            throw new ValidationException('eventId', $eventId);
289 1
        }
290
291 1
        // Validate $includeAttachments;
292
        if (!$this->validator->validInclude($includeAttachments)) {
293
            throw new ValidationException('includeAttachments', $includeAttachments);
294
        }
295
296
        // Validate $includeTickets;
297
        if (!$this->validator->validInclude($includeLocation)) {
298
            throw new ValidationException('includeLocation', $includeLocation);
299 2
        }
300
301
        // Validate $includeTickets;
302
        if (!$this->validator->validInclude($includeTickets)) {
303
            throw new ValidationException('includeTickets', $includeTickets);
304
        }
305
306
        // Validate $includeTicketsEvents;
307
        if (!$this->validator->validInclude($includeTicketsEvents)) {
308
            throw new ValidationException('includeTicketsEvents', $includeTicketsEvents);
309 2
        }
310
311
        // Validate $includeTicketsClassPasses;
312
        if (!$this->validator->validInclude($includeTicketsClassPasses)) {
313
            throw new ValidationException('includeTicketsClassPasses', $includeTicketsClassPasses);
314 2
        }
315
316
        $includesMapping = [
317
            'attachments' => $includeAttachments,
318 2
            'location' => $includeLocation,
319
            'tickets' => $includeTickets,
320
            'tickets.events' => $includeTicketsEvents,
321
            'tickets.class_passes' => $includeTicketsClassPasses,
322
        ];
323 2
324
        $this->includes = array_keys(array_filter($includesMapping, function ($value) {
325
            return $value;
326 2
        }));
327
328
        $event = $this->client->events()->retrieve($eventId, ['include' => implode(',', $this->includes)]);
329
330
        // attachments
331 2
        $eventAttachments = [];
332
333
        foreach ($event->attachments as $eventAttachment) {
334
            $attachment = $this->client->attachments()->retrieve($eventAttachment->id);
335 2
            array_push($eventAttachments, new Attachment(
336
                $attachment->contentType,
337
                $attachment->fileUrl,
338
                $attachment->fileSizeBytes,
339
                $attachment->fileSizeText,
340 2
                $attachment->fileName,
341
                $attachment->fileType,
342
                $attachment->id,
343
                $attachment->title
344 2
            ));
345
        }
346
347
        // eventTickets
348
        $eventTickets = [];
349 2
        foreach ($event->tickets as $ticket) {
350
            array_push($eventTickets, new Ticket(
351
                $ticket->available,
352
                $ticket->availableFrom,
353 2
                $ticket->availableTo,
354
                $ticket->builtBasketUrl,
355
                $ticket->builtBasketIframeUrl,
356
                $ticket->cost,
357 2
                $ticket->courseTicket,
358
                $ticket->details,
359
                $ticket->groupTicket,
360 2
                $ticket->groupMin,
361
                $ticket->groupMax,
362 2
                $ticket->id,
363
                $ticket->numberIssued,
364
                $ticket->numberTaken,
365
                $ticket->title
366
            ));
367
        }
368
369
        // ticketsClassPasses
370
        // @todo
371
372
        return $this->event = new Event(
373
            $event->allDay,
374
            $eventAttachments,
375
            $event->attendeeCount,
376
            $event->attendeeLimit,
377 2
            $event->details,
378 2
            $event->endAt,
379 2
            $event->id,
380 2
            new Location(
381 2
                $event->location->additionalInfo,
382 2
                $event->location->addressText,
383 2
                $event->location->id,
384 2
                $event->location->latitude,
385 2
                $event->location->longitude,
386 2
                $event->location->mapUrl,
387 2
                $event->location->zoom
388 2
            ),
389 2
            $event->maxTicketsPerBooking,
390 2
            $event->startAt,
391 2
            $eventTickets,
392 2
            $event->title,
393 2
            $event->waitingList
394 2
        );
395 2
    }
396
397
    /**
398
     *
399
     * {@inheritDoc}
400
     * @see \InShore\Bookwhen\Interfaces\ClientInterface::getEvents()
401 2
     */
402 2
    public function events(
403 2
        $calendar = false,
404 2
        $entry = false,
405 2
        $location = [],
406 2
        $tags = [],
407 2
        $title = [],
408 2
        $detail = [],
409 2
        $from = null,
410 2
        $to = null,
411 2
        bool $includeAttachments = false,
412 2
        bool $includeLocation = false,
413 2
        bool $includeTickets = false,
414 2
        bool $includeTicketsClassPasses = false,
415 2
        bool $includeTicketsEvents = false
416 2
    ): array {
417 2
418 2
        //$this->logger->debug(__METHOD__ . '(' . var_export(func_get_args(), true) . ')');
419 2
420 2
        // Validate $calendar
421 2
        // @todo details required
422 2
423 2
        // Validate $detail
424
        if (!empty($detail)) {
425
            if (!is_array($detail)) {
426
                throw new ValidationException('detail', implode(' ', $detail));
427
            } else {
428
                $detail = array_unique($detail);
429
                foreach ($detail as $item) {
430
                    if (!$this->validator->validLocation($item)) {
431 1
                        throw new ValidationException('detail', $item);
432
                    }
433
                }
434
                $this->filters['filter[detail]'] = implode(',', $detail);
435
            }
436
        }
437
438
        // Validate $entry
439
        // @todo details required
440
441
        // Validate $from;
442
        if (!empty($from)) {
443
            if (!$this->validator->validFrom($from, $to)) {
444
                throw new ValidationException('from', $from . '-' . $to);
445
            } else {
446
                $this->filters['filter[from]'] = $from;
447
            }
448
        }
449
450
        // Validate $location
451
        if (!empty($location)) {
452
            if (!is_array($location)) {
453 1
                throw new ValidationException('location', implode(' ', $title));
454
            } else {
455
                $location = array_unique($location);
456
                foreach ($location as $item) {
457
                    if (!$this->validator->validLocation($item)) {
458
                        throw new ValidationException('location', $item);
459
                    }
460
                }
461
                $this->filters['filter[location]'] = implode(',', $location);
462
            }
463
        }
464
465
        // Validate $tags.
466
        if (!empty($tags)) {
467
            if (!is_array($tags)) {
468
                throw new ValidationException('tags', implode(' ', $tags));
469
            } else {
470
                $tags = array_unique($tags);
471 1
                foreach ($tags as $tag) {
472
                    if (!empty($tag) && !$this->validator->validTag($tag)) {
473
                        throw new ValidationException('tag', $tag);
474
                    }
475
                }
476
            }
477
            $this->filters['filter[tag]'] = implode(',', $tags);
478
        }
479
480 1
        // Validate $title;
481
        if (!empty($title)) {
482
            if (!is_array($title)) {
483
                throw new ValidationException('title', implode(' ', $title));
484
            } else {
485
                $title = array_unique($title);
486
                foreach ($title as $item) {
487
                    if (!$this->validator->validTitle($item)) {
488
                        throw new ValidationException('title', $item);
489
                    }
490
                }
491
                $this->filters['filter[title]'] = implode(',', $title);
492
            }
493
        }
494
495 1
        // Validate $to;
496
        if (!empty($to)) {
497
            if (!$this->validator->validTo($to, $from)) {
498
                throw new ValidationException('to', $to . '-' . $from);
499
            } else {
500
                $this->filters['filter[to]'] = $to;
501
            }
502
        }
503
504
        // Validate $includeTickets;
505
        if (!$this->validator->validInclude($includeLocation)) {
506
            throw new ValidationException('includeLocation', $includeLocation);
507
        }
508
509
        // Validate $includeTickets;
510 1
        if (!$this->validator->validInclude($includeTickets)) {
511
            throw new ValidationException('includeTickets', $includeTickets);
512
        }
513
514
        // Validate $includeTicketsEvents;
515
        if (!$this->validator->validInclude($includeTicketsEvents)) {
516
            throw new ValidationException('includeTicketsEvents', $includeTicketsEvents);
517
        }
518
519
        // Validate $includeTicketsClassPasses;
520
        if (!$this->validator->validInclude($includeTicketsClassPasses)) {
521
            throw new ValidationException('includeTicketsClassPasses', $includeTicketsClassPasses);
522
        }
523
524
        $includesMapping = [
525 1
            'location' => $includeLocation,
526
            'tickets' => $includeTickets,
527
            'tickets.events' => $includeTicketsEvents,
528
            'tickets.class_passes' => $includeTicketsClassPasses,
529
        ];
530
531
        $this->includes = array_keys(array_filter($includesMapping, function ($value) {
532
            return $value;
533
        }));
534 1
535
        $events = $this->client->events()->list(array_merge($this->filters, ['include' => implode(',', $this->includes)]));
536
537 1
        foreach ($events->data as $event) {
538
539
            $eventAttachments = [];
540
            foreach ($event->attachments as $attachment) {
541
                array_push($eventAttachments, new Attachment(
542 1
                    $attachment->contentType,
543
                    $attachment->fileUrl,
544
                    $attachment->fileSizeBytes,
545
                    $attachment->fileSizeText,
546 1
                    $attachment->fileName,
547
                    $attachment->fileType,
548
                    $attachment->id,
549
                    $attachment->title
550
                ));
551 1
            }
552
553
            $eventTickets = [];
554
            foreach ($event->tickets as $ticket) {
555 1
                array_push($eventTickets, new Ticket(
556
                    $ticket->available,
557
                    $ticket->availableFrom,
558
                    $ticket->availableTo,
559
                    $ticket->builtBasketUrl,
560 1
                    $ticket->builtBasketIframeUrl,
561
                    $ticket->cost,
562
                    $ticket->courseTicket,
563
                    $ticket->details,
564 1
                    $ticket->groupTicket,
565
                    $ticket->groupMin,
566
                    $ticket->groupMax,
567
                    $ticket->id,
568 1
                    $ticket->numberIssued,
569
                    $ticket->numberTaken,
570 1
                    $ticket->title
571
                ));
572 1
            }
573 1
574 1
            array_push($this->events, new Event(
575 1
                $event->allDay,
576 1
                $eventAttachments,
577 1
                $event->attendeeCount,
578 1
                $event->attendeeLimit,
579 1
                $event->details,
580 1
                $event->endAt,
581 1
                $event->id,
582 1
                new Location(
583 1
                    $event->location->additionalInfo,
584 1
                    $event->location->addressText,
585 1
                    $event->location->id,
586 1
                    $event->location->latitude,
587 1
                    $event->location->longitude,
588 1
                    $event->location->mapUrl,
589 1
                    $event->location->zoom
590 1
                ),
591
                $event->maxTicketsPerBooking,
592
                $event->startAt,
593 1
                $eventTickets,
594 1
                $event->title,
595 1
                $event->waitingList
596 1
            ));
597 1
        }
598 1
599 1
        return $this->events;
600 1
    }
601 1
602 1
    /*
603 1
     *
604 1
     * {@inheritDoc}
605 1
     * @see \InShore\Bookwhen\Interfaces\ClientInterface::getLocation()
606 1
     */
607 1
    public function location(string $locationId): Location
608 1
    {
609 1
610 1
        if (!$this->validator->validId($locationId, 'location')) {
611 1
            throw new ValidationException('locationId', $locationId);
612 1
        }
613 1
614 1
        $location = $this->client->locations()->retrieve($locationId);
615 1
616
        return $this->location = new Location(
617
            $location->additionalInfo,
618 1
            $location->addressText,
619
            $location->id,
620
            $location->latitude,
621
            $location->longitude,
622
            $location->mapUrl,
623
            $location->zoom
624
        );
625
    }
626 1
627
    /**
628
     *
629 1
     */
630
    public function locations(
631
        null | string $addressText = null,
632
        null | string $additionalInfo = null
633 1
    ): array {
634
635 1
        $this->addFilter('additional_info', $additionalInfo, 'validAdditionalInfo');
636 1
637 1
        $this->addFilter('address_text', $addressText, 'validAddressText');
638 1
639 1
        $locations = $this->client->locations()->list($this->filters);
640 1
641 1
        foreach ($locations->data as $location) {
642 1
            array_push($this->locations, new Location(
643 1
                $location->additionalInfo,
644
                $location->addressText,
645
                $location->id,
646
                $location->latitude,
647
                $location->longitude,
648
                $location->mapUrl,
649 1
                $location->zoom
650
            ));
651
        }
652
653
        return $this->locations;
654
655
    }
656 1
657
//     /**
658
//      * Set Debug.
659
//      * @deprecated
660
//      */
661
//     public function setLogging($level)
662
//     {
663 1
//         $this->logLevel = $level;
664
//     }
665
666
    /**
667
     * {@inheritDoc}
668
     * @see \InShore\Bookwhen\Interfaces\BookWhenInterface::ticket()
669
     * class_passes
670 1
     */
671
    public function ticket(
672 1
        string $ticketId,
673 1
        bool $includeClassPasses = false,
674 1
        bool $includeEvents = false,
675 1
        bool $includeEventsAttachments = false,
676 1
        bool $includeEventsLocation = false,
677 1
        bool $includeEventsTickets = false
678 1
    ): Ticket {
679 1
680 1
        // ticketId
681 1
        if (!$this->validator->validId($ticketId, 'ticket')) {
682
            throw new ValidationException('ticketId', $ticketId);
683
        }
684 1
685
        // Validate $includeClassPasses;
686
        if (!$this->validator->validInclude($includeClassPasses)) {
687
            throw new ValidationException('includeClassPasses', $includeClassPasses);
688
        }
689
690
        // Validate $includeEvents;
691
        if (!$this->validator->validInclude($includeEvents)) {
692
            throw new ValidationException('includeEvents', $includeEvents);
693
        }
694
695
        // Validate $includeAttachments;
696
        if (!$this->validator->validInclude($includeEventsAttachments)) {
697
            throw new ValidationException('includeEventssAttachments', $includeEventsAttachments);
698
        }
699
700
        // Validate $includeEventsLocation;
701
        if (!$this->validator->validInclude($includeEventsLocation)) {
702 1
            throw new ValidationException('includeEventsLocation', $includeEventsLocation);
703
        }
704
705
        // Validate $includeEventsTickets;
706
        if (!$this->validator->validInclude($includeEventsTickets)) {
707
            throw new ValidationException('includeEventsTickets', $includeEventsTickets);
708
        }
709
710
        $includesMapping = [
711
            'class_passes' => $includeClassPasses,
712 1
            'events' => $includeEvents,
713
            'events.attachments' => $includeEventsAttachments,
714
            'events.location' => $includeEventsLocation,
715
            'events.tickets' => $includeEventsTickets,
716
        ];
717 1
718
        $this->includes = array_keys(array_filter($includesMapping, function ($value) {
719
            return $value;
720
        }));
721 1
722
        $ticket = $this->client->tickets()->retrieve($ticketId);
723
        return $this->ticket = new Ticket(
724
            $ticket->available,
725
            $ticket->availableFrom,
726 1
            $ticket->availableTo,
727
            $ticket->builtBasketUrl,
728
            $ticket->builtBasketIframeUrl,
729 1
            $ticket->cost,
730
            $ticket->courseTicket,
731
            $ticket->details,
732
            $ticket->groupTicket,
733
            $ticket->groupMin,
734 1
            $ticket->groupMax,
735
            $ticket->id,
736
            $ticket->numberIssued,
737 1
            $ticket->numberTaken,
738
            $ticket->title
739
        );
740
    }
741
742 1
    /**
743
     * {@inheritDoc}
744
     * @see \InShore\Bookwhen\Interfaces\BookWhenInterface::tickets()
745 1
     * @todo includes
746
     */
747
    public function tickets(
748
        string $eventId,
749
        bool $includeClassPasses = false,
750 1
        bool $includeEvents = false,
751
        bool $includeEventsAttachments = false,
752
        bool $includeEventsLocation = false,
753 1
        bool $includeEventsTickets = false
754
    ): array {
755
756
        // $this->logger->debug(__METHOD__ . '(' . var_export(func_get_args(), true) . ')');
757 1
758 1
        if (!$this->validator->validId($eventId, 'event')) {
759 1
            throw new ValidationException('eventId', $eventId);
760 1
        }
761 1
762 1
        // Validate $includeClassPasses;
763 1
        if (!$this->validator->validInclude($includeClassPasses)) {
764 1
            throw new ValidationException('includeClassPasses', $includeClassPasses);
765 1
        }
766 1
767 1
        // Validate $includeEvents;
768 1
        if (!$this->validator->validInclude($includeEvents)) {
769 1
            throw new ValidationException('includeEvents', $includeEvents);
770 1
        }
771 1
772 1
        // Validate $includeAttachments;
773 1
        if (!$this->validator->validInclude($includeEventsAttachments)) {
774 1
            throw new ValidationException('includeEventssAttachments', $includeEventsAttachments);
775
        }
776
777
        // Validate $includeEventsLocation;
778
        if (!$this->validator->validInclude($includeEventsLocation)) {
779
            throw new ValidationException('includeEventsLocation', $includeEventsLocation);
780
        }
781
782 1
        // Validate $includeEventsTickets;
783
        if (!$this->validator->validInclude($includeEventsTickets)) {
784
            throw new ValidationException('includeEventsTickets', $includeEventsTickets);
785
        }
786
787
        $includesMapping = [
788
            'class_passes' => $includeClassPasses,
789
            'events' => $includeEvents,
790
            'events.attachments' => $includeEventsAttachments,
791
            'events.location' => $includeEventsLocation,
792
            'events.tickets' => $includeEventsTickets,
793 1
        ];
794
795
        $this->includes = array_keys(array_filter($includesMapping, function ($value) {
796
            return $value;
797
        }));
798 1
799
        $tickets = $this->client->tickets()->list(array_merge(['event_id' => $eventId], ['include' => implode(',', $this->includes)]));
800
801
        foreach ($tickets->data as $ticket) {
802 1
            array_push($this->tickets, new Ticket(
803
                $ticket->available,
804
                $ticket->availableFrom,
805
                $ticket->availableTo,
806
                $ticket->builtBasketUrl,
807 1
                $ticket->builtBasketIframeUrl,
808
                $ticket->cost,
809
                $ticket->courseTicket,
810
                $ticket->details,
811 1
                $ticket->groupTicket,
812
                $ticket->groupMin,
813
                $ticket->groupMax,
814
                $ticket->id,
815
                $ticket->numberIssued,
816 1
                $ticket->numberTaken,
817
                $ticket->title
818
            ));
819
        }
820 1
821
        return $this->tickets;
822
823
    }
824
825
}
826