Passed
Pull Request — develop (#105)
by
unknown
15:03
created

Bookwhen::setToken()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 7
rs 10
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\ValidationException;
15
use InShore\Bookwhen\Interfaces\BookwhenInterface;
16
use InShore\Bookwhen\Validator;
17
use Monolog\Level;
18
use Monolog\Logger;
19
use Monolog\Handler\StreamHandler;
20
21
final class Bookwhen implements BookwhenInterface
22
{
23
    /**
24
     *
25
     */
26
    private null | Client $client;
27
28
    /**
29
     *
30
     */
31
    public Attachment $attachment;
32
33
    /**
34
     *
35
     */
36
    public array $attachments = [];
37
38
    /**
39
     *
40
     */
41
    public ClassPass $classPass;
42
43
    /**
44
     *
45
     */
46
    public array $classPasses = [];
47
48
    /**
49
     *
50
     */
51
    public Event $event;
52
53
    /**
54
     *
55
     */
56
    public array $events = [];
57
58
    /**
59
     *
60
     */
61
    private array $filters = [];
62
63
    /**
64
     *
65
     */
66
    public Location $location;
67
68
    /**
69
     *
70
     */
71
    private array $includes = [];
72
73
    /**
74
     *
75
     */
76
    public Ticket $ticket;
77
78
    /**
79
     *
80
     */
81
    public array $tickets = [];
82
83
    /**
84
     *
85
     */
86
    public $locations = [];
87
88
89
    /** @var string The path to the log file */
90
    private $logFile;
0 ignored issues
show
introduced by
The private property $logFile is not used, and could be removed.
Loading history...
91
92
    /** @var object loging object. */
93
    private $logger;
0 ignored issues
show
introduced by
The private property $logger is not used, and could be removed.
Loading history...
94
95
    /** @var string the logging level. */
96
    private string $logLevel;
97
98
    /**
99
     * Creates a new Bookwhen Client with the given API token.
100
     * @todo logging
101
     */
102
    public function __construct(
103
        private $validator = new Validator()
104
    ) {
105
        //         $this->logFile = $logFile;
106
        //         $this->logLevel = $logLevel;
107
        //         $this->logger = new Logger('inShore Bookwhen API');
108
        //         $this->logger->pushHandler(new StreamHandler($this->logFile, $this->logLevel));
109
        $this->client = BookwhenApi::client($_ENV['INSHORE_BOOKWHEN_API_KEY']);
110
    }
111
112
    /**
113
     *
114
     * {@inheritDoc}
115
     * @see \InShore\Bookwhen\Interfaces\ClientInterface::attachment()
116
     * @todo all attachment properties
117
     */
118
    public function attachment(string $attachmentId): Attachment
119
    {
120
        if (!$this->validator->validId($attachmentId, 'attachment')) {
121
            throw new ValidationException('attachmentId', $attachmentId);
122
        }
123
124
        $attachment = $this->client->attachments()->retrieve($attachmentId);
0 ignored issues
show
Bug introduced by
The method attachments() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

124
        $attachment = $this->client->/** @scrutinizer ignore-call */ attachments()->retrieve($attachmentId);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
125
126
        return $this->attachment = new Attachment(
127
            $attachment->contentType,
128
            $attachment->fileUrl,
129
            $attachment->fileSizeBytes,
130
            $attachment->fileSizeText,
131
            $attachment->fileName,
132
            $attachment->fileType,
133
            $attachment->id,
134
            $attachment->title,
135
        );
136
    }
137
138
    /**
139
     *
140
     * {@inheritDoc}
141
     * @see \InShore\Bookwhen\Interfaces\BookwhenInterface::attachment()
142
     * @todo
143
     */
144
    public function attachments(
145
        string $title = null,
146
        string $fileName = null,
147
        string $fileType = null
148
    ): array {
149
        //$this->logger->debug(__METHOD__ . '(' . var_export(func_get_args(), true) . ')');
150
151
        if (!is_null($title) && !$this->validator->validTitle($title)) {
152
            throw new ValidationException('title', $title);
153
        } else {
154
            $this->filters['filter[title]'] = $title;
155
        }
156
157
        if (!is_null($fileName) && !$this->validator->validFileName($fileName)) {
158
            throw new ValidationException('file name', $fileName);
159
        } else {
160
            $this->filters['filter[file_name]'] = $fileName;
161
        }
162
163
        if (!is_null($fileType) && !$this->validator->validFileType($fileType)) {
164
            throw new ValidationException('file type', $fileType);
165
        } else {
166
            $this->filters['filter[file_type]'] = $fileType;
167
        }
168
169
        $attachments = $this->client->attachments()->list($this->filters);
170
171
        foreach ($attachments->data as $attachment) {
172
            array_push($this->attachments, new Attachment(
173
                $attachment->contentType,
174
                $attachment->fileUrl,
175
                $attachment->fileSizeBytes,
176
                $attachment->fileSizeText,
177
                $attachment->fileName,
178
                $attachment->fileType,
179
                $attachment->id,
180
                $attachment->title
181
            ));
182
        }
183
184
        return $this->attachments;
185
    }
186
187
    /**
188
     *
189
     * {@inheritDoc}
190
     * @see \InShore\Bookwhen\Interfaces\ClientInterface::getClassPass()
191
     * @todo
192
     */
193
    public function classPass(string $classPassId): ClassPass
194
    {
195
        //         $this->logger->debug(__METHOD__ . '(' . var_export(func_get_args(), true) . ')');
196
197
        if (!$this->validator->validId($classPassId, 'classPass')) {
198
            throw new ValidationException('classPassId', $classPassId);
199
        }
200
201
        $classPass = $this->client->classPasses()->retrieve($classPassId);
202
203
        return new ClassPass(
204
            $classPass->details,
205
            $classPass->id,
206
            $classPass->numberAvailable,
207
            $classPass->title,
208
            $classPass->usageAllowance,
209
            $classPass->usageType,
210
            $classPass->useRestrictedForDays
211
        );
212
    }
213
214
    /**
215
     *
216
     * {@inheritDoc}
217
     * @see \InShore\Bookwhen\Interfaces\ClientInterface::getClassPasses()
218
     * @todo break params on to multiplper lines..
219
     */
220
    public function classPasses(
221
        $cost = null,
222
        $detail = null,
223
        $title = null,
224
        $usageAllowance = null,
225
        $usageType = null,
226
        $useRestrictedForDays = null
227
    ): array {
228
229
        //$this->logger->debug(__METHOD__ . '(' . var_export(func_get_args(), true) . ')');
230
231
        if (!is_null($detail) && !$this->validator->validDetails($detail)) {
232
            throw new ValidationException('detail', $detail);
233
        } else {
234
            $this->filters['filter[detail]'] = $detail;
235
        }
236
237
        if (!is_null($title) && !$this->validator->validTitle($title)) {
238
            throw new ValidationException('title', $title);
239
        } else {
240
            $this->filters['filter[title]'] = $title;
241
        }
242
243
        if (!is_null($usageAllowance) && !$this->validator->validUsageAllowance($usageAllowance)) {
244
            throw new ValidationException('usageAllowance', $usageAllowance);
245
        } else {
246
            $this->filters['filter[usage_allowance]'] = $usageAllowance;
247
        }
248
249
        if (!is_null($usageType) && !$this->validator->validUsageType($usageType)) {
250
            throw new ValidationException('usageType', $usageType);
251
        } else {
252
            $this->filters['filter[usage_type]'] = $usageType;
253
        }
254
255
        if (!is_null($useRestrictedForDays) && !$this->validator->validUseRestrictedForDays($useRestrictedForDays)) {
256
            throw new ValidationException('useRestrictedForDays', $useRestrictedForDays);
257
        } else {
258
            $this->filters['filter[use_restricted_for_days]'] = $useRestrictedForDays;
259
        }
260
261
        $classPasses = $this->client->classPasses()->list($this->filters);
262
263
        foreach ($classPasses->data as $classPass) {
264
            array_push($this->classPasses, new ClassPass(
265
                $classPass->details,
266
                $classPass->id,
267
                $classPass->numberAvailable,
268
                $classPass->title,
269
                $classPass->usageAllowance,
270
                $classPass->usageType,
271
                $classPass->useRestrictedForDays,
272
            ));
273
        }
274
        return $this->classPasses;
275
    }
276
277
    /**
278
     *
279
     * {@inheritDoc}
280
     * @see \InShore\Bookwhen\Interfaces\BookwhenInterface::event()
281
     * @todo filters.
282
     */
283
    public function event(
284
        string $eventId,
285
        bool $includeAttachments = false,
286
        bool $includeLocation = false,
287
        bool $includeTickets = false,
288
        bool $includeTicketsClassPasses = false,
289
        bool $includeTicketsEvents = false
290
    ): Event {
291
        //$this->logger->debug(__METHOD__ . '(' . var_export(func_get_args(), true) . ')');
292
293
        if (!$this->validator->validId($eventId, 'event')) {
294
            throw new ValidationException('eventId', $eventId);
295
        }
296
297
        // Validate $includeAttachments;
298
        if (!$this->validator->validInclude($includeAttachments)) {
299
            throw new ValidationException('includeAttachments', $includeAttachments);
300
        }
301
302
        if($includeAttachments) {
303
            array_push($this->includes, 'attachments');
304
        }
305
306
        // Validate $includeTickets;
307
        if (!$this->validator->validInclude($includeLocation)) {
308
            throw new ValidationException('includeLocation', $includeLocation);
309
        }
310
        if($includeLocation) {
311
            array_push($this->includes, 'location');
312
        }
313
314
        // Validate $includeTickets;
315
        if (!$this->validator->validInclude($includeTickets)) {
316
            throw new ValidationException('includeTickets', $includeTickets);
317
        }
318
319
        if($includeTickets) {
320
            array_push($this->includes, 'tickets');
321
        }
322
323
        // Validate $includeTicketsEvents;
324
        if (!$this->validator->validInclude($includeTicketsEvents)) {
325
            throw new ValidationException('includeTicketsEvents', $includeTicketsEvents);
326
        }
327
328
        if($includeTicketsEvents) {
329
            array_push($this->includes, 'tickets.events');
330
        }
331
332
        // Validate $includeTicketsClassPasses;
333
        if (!$this->validator->validInclude($includeTicketsClassPasses)) {
334
            throw new ValidationException('includeTicketsClassPasses', $includeTicketsClassPasses);
335
        }
336
337
        if($includeTicketsClassPasses) {
338
            array_push($this->includes, 'tickets.class_passes');
339
        }
340
341
        $event = $this->client->events()->retrieve($eventId, ['include' => implode(',', $this->includes)]);
342
343
        // attachments
344
        $eventAttachments = [];
345
346
        foreach ($event->attachments as $eventAttachment) {
347
            $attachment = $this->client->attachments()->retrieve($eventAttachment['id']);
348
            array_push($eventAttachments, new Attachment(
349
                $attachment->contentType,
350
                $attachment->fileUrl,
351
                $attachment->fileSizeBytes,
352
                $attachment->fileSizeText,
353
                $attachment->fileName,
354
                $attachment->fileType,
355
                $attachment->id,
356
                $attachment->title
357
            ));
358
        }
359
360
        // eventTickets
361
        $eventTickets = [];
362
        foreach($event->tickets as $ticket) {
363
            array_push($eventTickets, new Ticket(
0 ignored issues
show
Bug introduced by
The call to InShore\Bookwhen\Domain\Ticket::__construct() has too few arguments starting with title. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

363
            array_push($eventTickets, /** @scrutinizer ignore-call */ new Ticket(

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
364
                $ticket->available,
365
                $ticket->availableFrom,
366
                $ticket->availableTo,
367
                $ticket->builtBasketUrl,
368
                $ticket->builtBasketIframeUrl,
369
                $ticket->courseTicket,
370
                $ticket->details,
371
                $ticket->groupTicket,
372
                $ticket->groupMin,
373
                $ticket->groupMax,
374
                $ticket->id,
375
                $ticket->numberIssued,
376
                $ticket->numberTaken,
377
                $ticket->title
378
            ));
379
        }
380
381
        // ticketsClassPasses
382
        // @todo
383
384
        // ticketsEvents
385
        // @todo
386
387
        return $this->event = new Event(
388
            $event->allDay,
389
            $eventAttachments,
390
            $event->attendeeCount,
391
            $event->attendeeLimit,
392
            $event->details,
393
            $event->endAt,
394
            $event->id,
395
            new Location(
396
                $event->location->addressText,
397
                $event->location->additionalInfo,
398
                $event->location->id,
399
                $event->location->latitude,
400
                $event->location->longitude,
401
                $event->location->mapUrl,
402
                $event->location->zoom
403
            ),
404
            $event->maxTicketsPerBooking,
405
            $event->startAt,
406
            $eventTickets,
407
            $event->title,
408
            $event->waitingList
409
        );
410
    }
411
412
    /**
413
     *
414
     * {@inheritDoc}
415
     * @see \InShore\Bookwhen\Interfaces\ClientInterface::getEvents()
416
     */
417
    public function events(
418
        $calendar = false,
419
        $entry = false,
420
        $location = [],
421
        $tags = [],
422
        $title = [],
423
        $detail = [],
424
        $from = null,
425
        $to = null,
426
        bool $includeAttachments = false,
427
        bool $includeLocation = false,
428
        bool $includeTickets = false,
429
        bool $includeTicketsClassPasses = false,
430
        bool $includeTicketsEvents = false
431
    ): array {
432
433
        //$this->logger->debug(__METHOD__ . '(' . var_export(func_get_args(), true) . ')');
434
435
        // Validate $calendar
436
        // @todo details required
437
438
        // Validate $detail
439
        if (!empty($detail)) {
440
            if (!is_array($detail)) {
441
                throw new ValidationException('detail', implode(' ', $detail));
442
            } else {
443
                $detail = array_unique($detail);
444
                foreach($detail as $item) {
445
                    if (!$this->validator->validLocation($item)) {
446
                        throw new ValidationException('detail', $item);
447
                    }
448
                }
449
                $this->filters['filter[detail]'] = implode(',', $detail);
450
            }
451
        }
452
453
        // Validate $entry
454
        // @todo details required
455
456
        // Validate $from;
457
        if (!empty($from)) {
458
            if (!$this->validator->validFrom($from, $to)) {
459
                throw new ValidationException('from', $from . '-' . $to);
460
            } else {
461
                $this->filters['filter[from]'] = $from;
462
            }
463
        }
464
465
        // Validate $location
466
        if (!empty($location)) {
467
            if (!is_array($location)) {
468
                throw new ValidationException('location', implode(' ', $title));
469
            } else {
470
                $location = array_unique($location);
471
                foreach($location as $item) {
472
                    if (!$this->validator->validLocation($item)) {
473
                        throw new ValidationException('location', $item);
474
                    }
475
                }
476
                $this->filters['filter[location]'] = implode(',', $location);
477
            }
478
        }
479
480
        // Validate $tags.
481
        if (!empty($tags)) {
482
            if (!is_array($tags)) {
483
                throw new ValidationException('tags', implode(' ', $tags));
484
            } else {
485
                $tags = array_unique($tags);
486
                foreach ($tags as $tag) {
487
                    if (!empty($tag) && !$this->validator->validTag($tag)) {
488
                        throw new ValidationException('tag', $tag);
489
                    }
490
                }
491
            }
492
            $this->filters['filter[tag]'] = implode(',', $tags);
493
        }
494
495
        // Validate $title;
496
        if (!empty($title)) {
497
            if (!is_array($title)) {
498
                throw new ValidationException('title', implode(' ', $title));
499
            } else {
500
                $title = array_unique($title);
501
                foreach($title as $item) {
502
                    if (!$this->validator->validTitle($item)) {
503
                        throw new ValidationException('title', $item);
504
                    }
505
                }
506
                $this->filters['filter[title]'] = implode(',', $title);
507
            }
508
        }
509
510
        // Validate $to;
511
        if (!empty($to)) {
512
            if (!$this->validator->validTo($to, $from)) {
513
                throw new ValidationException('to', $to . '-' . $from);
514
            } else {
515
                $this->filters['filter[to]'] = $to;
516
            }
517
        }
518
519
        // Validate $includeTickets;
520
        if (!$this->validator->validInclude($includeLocation)) {
521
            throw new ValidationException('includeLocation', $includeLocation);
522
        }
523
        if($includeLocation) {
524
            array_push($this->includes, 'location');
525
        }
526
527
        // Validate $includeTickets;
528
        if (!$this->validator->validInclude($includeTickets)) {
529
            throw new ValidationException('includeTickets', $includeTickets);
530
        }
531
532
        if($includeTickets) {
533
            array_push($this->includes, 'tickets');
534
        }
535
536
        // Validate $includeTicketsEvents;
537
        if (!$this->validator->validInclude($includeTicketsEvents)) {
538
            throw new ValidationException('includeTicketsEvents', $includeTicketsEvents);
539
        }
540
541
        if($includeTicketsEvents) {
542
            array_push($this->includes, 'tickets.events');
543
        }
544
545
        // Validate $includeTicketsClassPasses;
546
        if (!$this->validator->validInclude($includeTicketsClassPasses)) {
547
            throw new ValidationException('includeTicketsClassPasses', $includeTicketsClassPasses);
548
        }
549
550
        if($includeTicketsClassPasses) {
551
            array_push($this->includes, 'tickets.class_passes');
552
        }
553
554
        $events = $this->client->events()->list(array_merge($this->filters, ['include' => implode(',', $this->includes)]));
555
556
        foreach ($events->data as $event) {
557
558
            $eventTickets = [];
559
            foreach($event->tickets as $ticket) {
560
                array_push($eventTickets, new Ticket(
0 ignored issues
show
Bug introduced by
The call to InShore\Bookwhen\Domain\Ticket::__construct() has too few arguments starting with title. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

560
                array_push($eventTickets, /** @scrutinizer ignore-call */ new Ticket(

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
561
                    $ticket->available,
562
                    $ticket->availableFrom,
563
                    $ticket->availableTo,
564
                    $ticket->builtBasketUrl,
565
                    $ticket->builtBasketIframeUrl,
566
                    $ticket->courseTicket,
567
                    $ticket->details,
568
                    $ticket->groupTicket,
569
                    $ticket->groupMin,
570
                    $ticket->groupMax,
571
                    $ticket->id,
572
                    $ticket->numberIssued,
573
                    $ticket->numberTaken,
574
                    $ticket->title
575
                ));
576
            }
577
578
            array_push($this->events, new Event(
579
                $event->allDay,
580
                $event->attachments,
581
                $event->attendeeCount,
582
                $event->attendeeLimit,
583
                $event->details,
584
                $event->endAt,
585
                $event->id,
586
                new Location(
587
                    $event->location->addressText,
588
                    $event->location->additionalInfo,
589
                    $event->location->id,
590
                    $event->location->latitude,
591
                    $event->location->longitude,
592
                    $event->location->mapUrl,
593
                    $event->location->zoom
594
                ),
595
                $event->maxTicketsPerBooking,
596
                $event->startAt,
597
                $eventTickets,
598
                $event->title,
599
                $event->waitingList
600
            ));
601
        }
602
603
        return $this->events;
604
    }
605
606
    /*
607
     *
608
     * {@inheritDoc}
609
     * @see \InShore\Bookwhen\Interfaces\ClientInterface::getLocation()
610
     */
611
    public function location(string $locationId): Location
612
    {
613
614
        if (!$this->validator->validId($locationId, 'location')) {
615
            throw new ValidationException('locationId', $locationId);
616
        }
617
618
        $location = $this->client->locations()->retrieve($locationId);
619
620
        return $this->location = new Location(
621
            $location->additionalInfo,
622
            $location->addressText,
623
            $location->id,
624
            $location->latitude,
625
            $location->longitude,
626
            $location->mapUrl,
627
            $location->zoom
628
        );
629
    }
630
631
    /**
632
     *
633
     */
634
    public function locations(
635
        null | string $addressText = null,
636
        null | string $additionalInfo = null
637
    ): array {
638
639
        // $this->logger->debug(__METHOD__ . '(' . var_export(func_get_args(), true) . ')');
640
641
        if (!empty($additionalInfo)) {
642
            if (!$this->validator->validAdditionalInfo($additionalInfo, 'additionalInfo')) {
643
                throw new ValidationException('additionalInfo', $additionalInfo);
644
            }
645
            $this->filters['filter[additional_info]'] = $additionalInfo;
646
        }
647
648
        if (!empty($addressText)) {
649
            if (!$this->validator->validAddressText($addressText, 'addressText')) {
650
                throw new ValidationException('addressText', $addressText);
651
            }
652
            $this->filters['filter[address_text]'] = $addressText;
653
        }
654
655
        $locations = $this->client->locations()->list($this->filters);
656
657
        foreach ($locations->data as $location) {
658
            array_push($this->locations, new Location(
659
                $location->additionalInfo,
660
                $location->addressText,
661
                $location->id,
662
                $location->latitude,
663
                $location->longitude,
664
                $location->mapUrl,
665
                $location->zoom
666
            ));
667
        }
668
669
        return $this->locations;
670
671
    }
672
673
    /**
674
     * Set Debug.
675
     * @deprecated
676
     */
677
    public function setLogging($level)
678
    {
679
        $this->logLevel = $level;
680
    }
681
682
    /**
683
     * {@inheritDoc}
684
     * @see \InShore\Bookwhen\Interfaces\BookWhenInterface::ticket()
685
     * class_passes
686
     */
687
    public function ticket(
688
        string $ticketId,
689
        bool $includeClassPasses = false,
690
        bool $includeEvents = false,
691
        bool $includeEventsAttachments = false,
692
        bool $includeEventsLocation = false,
693
        bool $includeEventsTickets = false
694
    ): Ticket {
695
696
        // ticketId
697
        if (!$this->validator->validId($ticketId, 'ticket')) {
698
            throw new ValidationException('ticketId', $ticketId);
699
        }
700
701
        // Validate $includeClassPasses;
702
        if (!$this->validator->validInclude($includeClassPasses)) {
703
            throw new ValidationException('includeClassPasses', $includeClassPasses);
704
        }
705
706
        if($includeClassPasses) {
707
            array_push($this->includes, 'class_passes');
708
        }
709
710
        // Validate $includeEvents;
711
        if (!$this->validator->validInclude($includeEvents)) {
712
            throw new ValidationException('includeEvents', $includeEvents);
713
        }
714
        if($includeEvents) {
715
            array_push($this->includes, 'events');
716
        }
717
718
        // Validate $includeAttachments;
719
        if (!$this->validator->validInclude($includeEventsAttachments)) {
720
            throw new ValidationException('includeEventssAttachments', $includeEventsAttachments);
721
        }
722
        if($includeEventsAttachments) {
723
            array_push($this->includes, 'events.attachments');
724
        }
725
726
        // Validate $includeEventsLocation;
727
        if (!$this->validator->validInclude($includeEventsLocation)) {
728
            throw new ValidationException('includeEventsLocation', $includeEventsLocation);
729
        }
730
        if($includeEventsLocation) {
731
            array_push($this->includes, 'events.location');
732
        }
733
734
        // Validate $includeEventsTickets;
735
        if (!$this->validator->validInclude($includeEventsTickets)) {
736
            throw new ValidationException('includeEventsTickets', $includeEventsTickets);
737
        }
738
        if($includeEventsTickets) {
739
            array_push($this->includes, 'events.tickets');
740
        }
741
742
        $ticket = $this->client->tickets()->retrieve($ticketId);
743
        return $this->ticket = new Ticket(
744
            $ticket->available,
745
            $ticket->availableFrom,
746
            $ticket->availableTo,
747
            $ticket->builtBasketUrl,
748
            $ticket->builtBasketIframeUrl,
749
            $ticket->cost,
750
            $ticket->courseTicket,
751
            $ticket->details,
752
            $ticket->groupTicket,
753
            $ticket->groupMin,
754
            $ticket->groupMax,
755
            $ticket->id,
756
            $ticket->numberIssued,
757
            $ticket->numberTaken,
758
            $ticket->title
759
        );
760
    }
761
762
    /**
763
     * {@inheritDoc}
764
     * @see \InShore\Bookwhen\Interfaces\BookWhenInterface::tickets()
765
     * @todo includes
766
     */
767
    public function tickets(
768
        string $eventId,
769
        bool $includeClassPasses = false,
770
        bool $includeEvents = false,
771
        bool $includeEventsAttachments = false,
772
        bool $includeEventsLocation = false,
773
        bool $includeEventsTickets = false
774
    ): array {
775
776
        // $this->logger->debug(__METHOD__ . '(' . var_export(func_get_args(), true) . ')');
777
778
        if (!$this->validator->validId($eventId, 'event')) {
779
            throw new ValidationException('eventId', $eventId);
780
        }
781
782
        // Validate $includeClassPasses;
783
        if (!$this->validator->validInclude($includeClassPasses)) {
784
            throw new ValidationException('includeClassPasses', $includeClassPasses);
785
        }
786
787
        if($includeClassPasses) {
788
            array_push($this->includes, 'class_passes');
789
        }
790
791
        // Validate $includeEvents;
792
        if (!$this->validator->validInclude($includeEvents)) {
793
            throw new ValidationException('includeEvents', $includeEvents);
794
        }
795
796
        if($includeEvents) {
797
            array_push($this->includes, 'events');
798
        }
799
800
        // Validate $includeAttachments;
801
        if (!$this->validator->validInclude($includeEventsAttachments)) {
802
            throw new ValidationException('includeEventssAttachments', $includeEventsAttachments);
803
        }
804
805
        if($includeEventsAttachments) {
806
            array_push($this->includes, 'events.attachments');
807
        }
808
809
        // Validate $includeEventsLocation;
810
        if (!$this->validator->validInclude($includeEventsLocation)) {
811
            throw new ValidationException('includeEventsLocation', $includeEventsLocation);
812
        }
813
814
        if($includeEventsLocation) {
815
            array_push($this->includes, 'events.location');
816
        }
817
818
        // Validate $includeEventsTickets;
819
        if (!$this->validator->validInclude($includeEventsTickets)) {
820
            throw new ValidationException('includeEventsTickets', $includeEventsTickets);
821
        }
822
823
        if($includeEventsTickets) {
824
            array_push($this->includes, 'events.tickets');
825
        }
826
827
        $tickets = $this->client->tickets()->list(array_merge(['event_id' => $eventId], ['include' => implode(',', $this->includes)]));
828
829
        foreach ($tickets->data as $ticket) {
830
            array_push($this->tickets, new Ticket(
831
                $ticket->available,
832
                $ticket->availableFrom,
833
                $ticket->availableTo,
834
                $ticket->builtBasketUrl,
835
                $ticket->builtBasketIframeUrl,
836
                $ticket->cost,
837
                $ticket->courseTicket,
838
                $ticket->details,
839
                $ticket->groupTicket,
840
                $ticket->groupMin,
841
                $ticket->groupMax,
842
                $ticket->id,
843
                $ticket->numberIssued,
844
                $ticket->numberTaken,
845
                $ticket->title
846
            ));
847
        }
848
849
        return $this->tickets;
850
851
    }
852
}
853