Passed
Push — develop ( 0943c0...98f868 )
by Daniel
01:59 queued 23s
created

Bookwhen::events()   F

Complexity

Conditions 32
Paths 4124

Size

Total Lines 188
Code Lines 104

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 1056

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 32
eloc 104
c 1
b 0
f 0
nc 4124
nop 13
dl 0
loc 188
ccs 0
cts 102
cp 0
crap 1056
rs 0

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