Passed
Push — develop ( 71f723...91d1f8 )
by Daniel
03:02 queued 01:09
created

Bookwhen::attachments()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 28
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 2

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 2
eloc 15
nc 2
nop 3
dl 0
loc 28
ccs 17
cts 17
cp 1
crap 2
rs 9.7666
c 3
b 0
f 0
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
     */
135 3
    public function addFilter(string $filter, null | string $value, string $validator): void
136
    {
137
138 3
        if (!is_null($value) && !$this->validator->$validator($value)) {
139
            throw new ValidationException($filter, $value);
140
        } else {
141 3
            $this->filters['filter[' . $filter . ']'] = $value;
142
        }
143
    }
144
145
    /**
146
     *
147
     * {@inheritDoc}
148
     * @see \InShore\Bookwhen\Interfaces\ClientInterface::attachment()
149
     * @todo all attachment properties
150
     */
151 3
    public function attachment(string $attachmentId): Attachment
152
    {
153 3
        if (!$this->validator->validId($attachmentId, 'attachment')) {
154 2
            throw new ValidationException('attachmentId', $attachmentId);
155
        }
156
157 1
        $attachment = $this->client->attachments()->retrieve($attachmentId);
158
159 1
        return $this->attachment = new Attachment(
160 1
            $attachment->contentType,
161 1
            $attachment->fileUrl,
162 1
            $attachment->fileSizeBytes,
163 1
            $attachment->fileSizeText,
164 1
            $attachment->fileName,
165 1
            $attachment->fileType,
166 1
            $attachment->id,
167 1
            $attachment->title,
168 1
        );
169
    }
170
171
    /**
172
     *
173
     * {@inheritDoc}
174
     *
175
     * @see \InShore\Bookwhen\Interfaces\BookwhenInterface::attachment()
176
     */
177 1
    public function attachments(
178
        string $title = null,
179
        string $fileName = null,
180
        string $fileType = null
181
    ): array {
182
183 1
        $this->addFilter('title', $title, 'validTitle');
184
185 1
        $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
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 1
                $attachment->title
201 1
            ));
202
        }
203
204 1
        return $this->attachments;
205
    }
206
207
    /**
208
     *
209
     * {@inheritDoc}
210
     * @see \InShore\Bookwhen\Interfaces\ClientInterface::getClassPass()
211
     * @todo
212
     */
213 1
    public function classPass(string $classPassId): ClassPass
214
    {
215
216 1
        if (!$this->validator->validId($classPassId, 'classPass')) {
217
            throw new ValidationException('classPassId', $classPassId);
218
        }
219
220 1
        $classPass = $this->client->classPasses()->retrieve($classPassId);
221
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 1
        );
231
    }
232
233
    /**
234
     *
235
     * {@inheritDoc}
236
     * @see \InShore\Bookwhen\Interfaces\ClientInterface::getClassPasses()
237
     */
238 1
    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 1
        $this->addFilter('detail', $detail, 'validDetails');
248
249 1
        $this->addFilter('title', $title, 'validTitle');
250
251 1
        $this->addFilter('usage_allowance', $usageAllowance, 'validUsageAllowance');
252
253 1
        $this->addFilter('usage_type', $usageType, 'validUsageType');
254
255 1
        $this->addFilter('use_restricted_for_days', $useRestrictedForDays, 'validUseRestrictedForDays');
256
257 1
        $classPasses = $this->client->classPasses()->list($this->filters);
258
259 1
        foreach ($classPasses->data as $classPass) {
260 1
            array_push($this->classPasses, new ClassPass(
261 1
                $classPass->details,
262 1
                $classPass->id,
263 1
                $classPass->numberAvailable,
264 1
                $classPass->title,
265 1
                $classPass->usageAllowance,
266 1
                $classPass->usageType,
267 1
                $classPass->useRestrictedForDays,
268 1
            ));
269
        }
270 1
        return $this->classPasses;
271
    }
272
273
    /**
274
     *
275
     * {@inheritDoc}
276
     * @see \InShore\Bookwhen\Interfaces\BookwhenInterface::event()
277
     */
278 2
    public function event(
279
        string $eventId,
280
        bool $includeAttachments = false,
281
        bool $includeLocation = false,
282
        bool $includeTickets = false,
283
        bool $includeTicketsClassPasses = false,
284
        bool $includeTicketsEvents = false
285
    ): Event {
286
287 2
        if (!$this->validator->validId($eventId, 'event')) {
288
            throw new ValidationException('eventId', $eventId);
289
        }
290
291
        // Validate $includeAttachments;
292 2
        if (!$this->validator->validInclude($includeAttachments)) {
293
            throw new ValidationException('includeAttachments', $includeAttachments);
294
        }
295
296
        // Validate $includeTickets;
297 2
        if (!$this->validator->validInclude($includeLocation)) {
298
            throw new ValidationException('includeLocation', $includeLocation);
299
        }
300
301
        // Validate $includeTickets;
302 2
        if (!$this->validator->validInclude($includeTickets)) {
303
            throw new ValidationException('includeTickets', $includeTickets);
304
        }
305
306
        // Validate $includeTicketsEvents;
307 2
        if (!$this->validator->validInclude($includeTicketsEvents)) {
308
            throw new ValidationException('includeTicketsEvents', $includeTicketsEvents);
309
        }
310
311
        // Validate $includeTicketsClassPasses;
312 2
        if (!$this->validator->validInclude($includeTicketsClassPasses)) {
313
            throw new ValidationException('includeTicketsClassPasses', $includeTicketsClassPasses);
314
        }
315
316 2
        $includesMapping = [
317 2
            'attachments' => $includeAttachments,
318 2
            'location' => $includeLocation,
319 2
            'tickets' => $includeTickets,
320 2
            'tickets.events' => $includeTicketsEvents,
321 2
            'tickets.class_passes' => $includeTicketsClassPasses,
322 2
        ];
323
324 2
        $this->includes = array_keys(array_filter($includesMapping, function ($value) {
325 2
            return $value;
326 2
        }));
327
328 2
        $event = $this->client->events()->retrieve($eventId, ['include' => implode(',', $this->includes)]);
329
330
        // attachments
331 2
        $eventAttachments = [];
332
333 2
        foreach ($event->attachments as $eventAttachment) {
334
            $attachment = $this->client->attachments()->retrieve($eventAttachment->id);
335
            array_push($eventAttachments, new Attachment(
336
                $attachment->contentType,
337
                $attachment->fileUrl,
338
                $attachment->fileSizeBytes,
339
                $attachment->fileSizeText,
340
                $attachment->fileName,
341
                $attachment->fileType,
342
                $attachment->id,
343
                $attachment->title
344
            ));
345
        }
346
347
        // eventTickets
348 2
        $eventTickets = [];
349 2
        foreach ($event->tickets as $ticket) {
350 2
            array_push($eventTickets, new Ticket(
351 2
                $ticket->available,
352 2
                $ticket->availableFrom,
353 2
                $ticket->availableTo,
354 2
                $ticket->builtBasketUrl,
355 2
                $ticket->builtBasketIframeUrl,
356 2
                $ticket->cost,
357 2
                $ticket->courseTicket,
358 2
                $ticket->details,
359 2
                $ticket->groupTicket,
360 2
                $ticket->groupMin,
361 2
                $ticket->groupMax,
362 2
                $ticket->id,
363 2
                $ticket->numberIssued,
364 2
                $ticket->numberTaken,
365 2
                $ticket->title
366 2
            ));
367
        }
368
369
        // ticketsClassPasses
370
        // @todo
371
372 2
        return $this->event = new Event(
373 2
            $event->allDay,
374 2
            $eventAttachments,
375 2
            $event->attendeeCount,
376 2
            $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
    }
396
397
    /**
398
     *
399
     * {@inheritDoc}
400
     * @see \InShore\Bookwhen\Interfaces\ClientInterface::getEvents()
401
     */
402 1
    public function events(
403
        $calendar = false,
404
        $entry = false,
405
        $location = [],
406
        $tags = [],
407
        $title = [],
408
        $detail = [],
409
        $from = null,
410
        $to = null,
411
        bool $includeAttachments = false,
412
        bool $includeLocation = false,
413
        bool $includeTickets = false,
414
        bool $includeTicketsClassPasses = false,
415
        bool $includeTicketsEvents = false
416
    ): array {
417
418
        //$this->logger->debug(__METHOD__ . '(' . var_export(func_get_args(), true) . ')');
419
420
        // Validate $calendar
421
        // @todo details required
422
423
        // Validate $detail
424 1
        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
                        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 1
        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 1
        if (!empty($location)) {
452
            if (!is_array($location)) {
453
                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 1
        if (!empty($tags)) {
467
            if (!is_array($tags)) {
468
                throw new ValidationException('tags', implode(' ', $tags));
469
            } else {
470
                $tags = array_unique($tags);
471
                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
        // Validate $title;
481 1
        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
        // Validate $to;
496 1
        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 1
        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 1
        if (!$this->validator->validInclude($includeTicketsEvents)) {
516
            throw new ValidationException('includeTicketsEvents', $includeTicketsEvents);
517
        }
518
519
        // Validate $includeTicketsClassPasses;
520 1
        if (!$this->validator->validInclude($includeTicketsClassPasses)) {
521
            throw new ValidationException('includeTicketsClassPasses', $includeTicketsClassPasses);
522
        }
523
524 1
        $includesMapping = [
525 1
            'location' => $includeLocation,
526 1
            'tickets' => $includeTickets,
527 1
            'tickets.events' => $includeTicketsEvents,
528 1
            'tickets.class_passes' => $includeTicketsClassPasses,
529 1
        ];
530
531 1
        $this->includes = array_keys(array_filter($includesMapping, function ($value) {
532 1
            return $value;
533 1
        }));
534
535 1
        $events = $this->client->events()->list(array_merge($this->filters, ['include' => implode(',', $this->includes)]));
536
537 1
        foreach ($events->data as $event) {
538
539 1
            $eventTickets = [];
540 1
            foreach ($event->tickets as $ticket) {
541 1
                array_push($eventTickets, new Ticket(
542 1
                    $ticket->available,
543 1
                    $ticket->availableFrom,
544 1
                    $ticket->availableTo,
545 1
                    $ticket->builtBasketUrl,
546 1
                    $ticket->builtBasketIframeUrl,
547 1
                    $ticket->cost,
548 1
                    $ticket->courseTicket,
549 1
                    $ticket->details,
550 1
                    $ticket->groupTicket,
551 1
                    $ticket->groupMin,
552 1
                    $ticket->groupMax,
553 1
                    $ticket->id,
554 1
                    $ticket->numberIssued,
555 1
                    $ticket->numberTaken,
556 1
                    $ticket->title
557 1
                ));
558
            }
559
560 1
            array_push($this->events, new Event(
561 1
                $event->allDay,
562 1
                $event->attachments,
563 1
                $event->attendeeCount,
564 1
                $event->attendeeLimit,
565 1
                $event->details,
566 1
                $event->endAt,
567 1
                $event->id,
568 1
                new Location(
569 1
                    $event->location->additionalInfo,
570 1
                    $event->location->addressText,
571 1
                    $event->location->id,
572 1
                    $event->location->latitude,
573 1
                    $event->location->longitude,
574 1
                    $event->location->mapUrl,
575 1
                    $event->location->zoom
576 1
                ),
577 1
                $event->maxTicketsPerBooking,
578 1
                $event->startAt,
579 1
                $eventTickets,
580 1
                $event->title,
581 1
                $event->waitingList
582 1
            ));
583
        }
584
585 1
        return $this->events;
586
    }
587
588
    /*
589
     *
590
     * {@inheritDoc}
591
     * @see \InShore\Bookwhen\Interfaces\ClientInterface::getLocation()
592
     */
593 1
    public function location(string $locationId): Location
594
    {
595
596 1
        if (!$this->validator->validId($locationId, 'location')) {
597
            throw new ValidationException('locationId', $locationId);
598
        }
599
600 1
        $location = $this->client->locations()->retrieve($locationId);
601
602 1
        return $this->location = new Location(
603 1
            $location->additionalInfo,
604 1
            $location->addressText,
605 1
            $location->id,
606 1
            $location->latitude,
607 1
            $location->longitude,
608 1
            $location->mapUrl,
609 1
            $location->zoom
610 1
        );
611
    }
612
613
    /**
614
     *
615
     */
616 1
    public function locations(
617
        null | string $addressText = null,
618
        null | string $additionalInfo = null
619
    ): array {
620
621 1
        $this->addFilter('additional_info', $additionalInfo, 'validAdditionalInfo');
622
623 1
        $this->addFilter('address_text', $addressText, 'validAddressText');
624
625 1
        $locations = $this->client->locations()->list($this->filters);
626
627 1
        foreach ($locations->data as $location) {
628 1
            array_push($this->locations, new Location(
629 1
                $location->additionalInfo,
630 1
                $location->addressText,
631 1
                $location->id,
632 1
                $location->latitude,
633 1
                $location->longitude,
634 1
                $location->mapUrl,
635 1
                $location->zoom
636 1
            ));
637
        }
638
639 1
        return $this->locations;
640
641
    }
642
643
//     /**
644
//      * Set Debug.
645
//      * @deprecated
646
//      */
647
//     public function setLogging($level)
648
//     {
649
//         $this->logLevel = $level;
650
//     }
651
652
    /**
653
     * {@inheritDoc}
654
     * @see \InShore\Bookwhen\Interfaces\BookWhenInterface::ticket()
655
     * class_passes
656
     */
657 1
    public function ticket(
658
        string $ticketId,
659
        bool $includeClassPasses = false,
660
        bool $includeEvents = false,
661
        bool $includeEventsAttachments = false,
662
        bool $includeEventsLocation = false,
663
        bool $includeEventsTickets = false
664
    ): Ticket {
665
666
        // ticketId
667 1
        if (!$this->validator->validId($ticketId, 'ticket')) {
668
            throw new ValidationException('ticketId', $ticketId);
669
        }
670
671
        // Validate $includeClassPasses;
672 1
        if (!$this->validator->validInclude($includeClassPasses)) {
673
            throw new ValidationException('includeClassPasses', $includeClassPasses);
674
        }
675
676
        // Validate $includeEvents;
677 1
        if (!$this->validator->validInclude($includeEvents)) {
678
            throw new ValidationException('includeEvents', $includeEvents);
679
        }
680
681
        // Validate $includeAttachments;
682 1
        if (!$this->validator->validInclude($includeEventsAttachments)) {
683
            throw new ValidationException('includeEventssAttachments', $includeEventsAttachments);
684
        }
685
686
        // Validate $includeEventsLocation;
687 1
        if (!$this->validator->validInclude($includeEventsLocation)) {
688
            throw new ValidationException('includeEventsLocation', $includeEventsLocation);
689
        }
690
691
        // Validate $includeEventsTickets;
692 1
        if (!$this->validator->validInclude($includeEventsTickets)) {
693
            throw new ValidationException('includeEventsTickets', $includeEventsTickets);
694
        }
695
696 1
        $includesMapping = [
697 1
            'class_passes' => $includeClassPasses,
698 1
            'events' => $includeEvents,
699 1
            'events.attachments' => $includeEventsAttachments,
700 1
            'events.location' => $includeEventsLocation,
701 1
            'events.tickets' => $includeEventsTickets,
702 1
        ];
703
704 1
        $this->includes = array_keys(array_filter($includesMapping, function ($value) {
705 1
            return $value;
706 1
        }));
707
708 1
        $ticket = $this->client->tickets()->retrieve($ticketId);
709 1
        return $this->ticket = new Ticket(
710 1
            $ticket->available,
711 1
            $ticket->availableFrom,
712 1
            $ticket->availableTo,
713 1
            $ticket->builtBasketUrl,
714 1
            $ticket->builtBasketIframeUrl,
715 1
            $ticket->cost,
716 1
            $ticket->courseTicket,
717 1
            $ticket->details,
718 1
            $ticket->groupTicket,
719 1
            $ticket->groupMin,
720 1
            $ticket->groupMax,
721 1
            $ticket->id,
722 1
            $ticket->numberIssued,
723 1
            $ticket->numberTaken,
724 1
            $ticket->title
725 1
        );
726
    }
727
728
    /**
729
     * {@inheritDoc}
730
     * @see \InShore\Bookwhen\Interfaces\BookWhenInterface::tickets()
731
     * @todo includes
732
     */
733 1
    public function tickets(
734
        string $eventId,
735
        bool $includeClassPasses = false,
736
        bool $includeEvents = false,
737
        bool $includeEventsAttachments = false,
738
        bool $includeEventsLocation = false,
739
        bool $includeEventsTickets = false
740
    ): array {
741
742
        // $this->logger->debug(__METHOD__ . '(' . var_export(func_get_args(), true) . ')');
743
744 1
        if (!$this->validator->validId($eventId, 'event')) {
745
            throw new ValidationException('eventId', $eventId);
746
        }
747
748
        // Validate $includeClassPasses;
749 1
        if (!$this->validator->validInclude($includeClassPasses)) {
750
            throw new ValidationException('includeClassPasses', $includeClassPasses);
751
        }
752
753
        // Validate $includeEvents;
754 1
        if (!$this->validator->validInclude($includeEvents)) {
755
            throw new ValidationException('includeEvents', $includeEvents);
756
        }
757
758
        // Validate $includeAttachments;
759 1
        if (!$this->validator->validInclude($includeEventsAttachments)) {
760
            throw new ValidationException('includeEventssAttachments', $includeEventsAttachments);
761
        }
762
763
        // Validate $includeEventsLocation;
764 1
        if (!$this->validator->validInclude($includeEventsLocation)) {
765
            throw new ValidationException('includeEventsLocation', $includeEventsLocation);
766
        }
767
768
        // Validate $includeEventsTickets;
769 1
        if (!$this->validator->validInclude($includeEventsTickets)) {
770
            throw new ValidationException('includeEventsTickets', $includeEventsTickets);
771
        }
772
773 1
        $includesMapping = [
774 1
            'class_passes' => $includeClassPasses,
775 1
            'events' => $includeEvents,
776 1
            'events.attachments' => $includeEventsAttachments,
777 1
            'events.location' => $includeEventsLocation,
778 1
            'events.tickets' => $includeEventsTickets,
779 1
        ];
780
781 1
        $this->includes = array_keys(array_filter($includesMapping, function ($value) {
782 1
            return $value;
783 1
        }));
784
785 1
        $tickets = $this->client->tickets()->list(array_merge(['event_id' => $eventId], ['include' => implode(',', $this->includes)]));
786
787 1
        foreach ($tickets->data as $ticket) {
788 1
            array_push($this->tickets, new Ticket(
789 1
                $ticket->available,
790 1
                $ticket->availableFrom,
791 1
                $ticket->availableTo,
792 1
                $ticket->builtBasketUrl,
793 1
                $ticket->builtBasketIframeUrl,
794 1
                $ticket->cost,
795 1
                $ticket->courseTicket,
796 1
                $ticket->details,
797 1
                $ticket->groupTicket,
798 1
                $ticket->groupMin,
799 1
                $ticket->groupMax,
800 1
                $ticket->id,
801 1
                $ticket->numberIssued,
802 1
                $ticket->numberTaken,
803 1
                $ticket->title
804 1
            ));
805
        }
806
807 1
        return $this->tickets;
808
809
    }
810
811
}
812