Passed
Pull Request — develop (#83)
by
unknown
19:12 queued 04:07
created

Bookwhen::event()   B

Complexity

Conditions 7
Paths 9

Size

Total Lines 96
Code Lines 58

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 58
c 1
b 0
f 0
nc 9
nop 6
dl 0
loc 96
rs 7.983

How to fix   Long Method   

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:

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;
0 ignored issues
show
Bug introduced by
The type InShore\Bookwhen\Domain\ClassPass was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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
    private null | Client $client;
24
25
    /**
26
     *
27
     * @var unknown
0 ignored issues
show
Bug introduced by
The type InShore\Bookwhen\unknown was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
28
     */
29
    public Attachment $attachment;
30
31
    /**
32
     *
33
     * @var unknown
34
     */
35
    public array $attachments = [];
36
37
    /**
38
     *
39
     * @var unknown
40
     */
41
    public ClassPass $classPass;
42
43
    /**
44
     *
45
     * @var unknown
46
     */
47
    public array $classPasses = [];
48
49
    /**
50
     *
51
     * @var unknown
52
     */
53
    public Event $event;
54
55
    /**
56
     *
57
     * @var unknown
58
     */
59
    public array $events = [];
60
61
    /**
62
     *
63
     * @var unknown
64
     */
65
    private array $filters = [];
66
    
67
    /**
68
     *
69
     */
70
    public readonly Location $location;
71
72
    /**
73
     *
74
     * @var unknown
75
     */
76
    private array $includes = [];
77
    /**
78
79
     */
80
    public Ticket $ticket;
81
82
    /**
83
84
     */
85
    public array $tickets = [];
86
87
    /**
88
        *
89
     */
90
    public $locations = [];
91
92
93
    /** @var string The path to the log file */
94
    private $logFile;
0 ignored issues
show
introduced by
The private property $logFile is not used, and could be removed.
Loading history...
95
96
    /** @var object loging object. */
97
    private $logger;
0 ignored issues
show
introduced by
The private property $logger is not used, and could be removed.
Loading history...
98
99
    /** @var string the logging level. */
100
    private string $logLevel;
0 ignored issues
show
introduced by
The private property $logLevel is not used, and could be removed.
Loading history...
101
102
103
104
    /**
105
     * Creates a new Bookwhen Client with the given API token.
106
     * @todo logging
107
     */
108
    public function __construct(
109
        private $validator = new Validator()
110
    ) {
111
        //         $this->logFile = $logFile;
112
        //         $this->logLevel = $logLevel;
113
        //         $this->logger = new Logger('inShore Bookwhen API');
114
        //         $this->logger->pushHandler(new StreamHandler($this->logFile, $this->logLevel));
115
        $this->client = BookwhenApi::client($_ENV['INSHORE_BOOKWHEN_API_KEY']);
116
    }
117
118
    /**
119
     *
120
     * {@inheritDoc}
121
     * @see \InShore\Bookwhen\Interfaces\ClientInterface::attachment()
122
     * @todo all attachment properties
123
     */
124
    public function attachment(string $attachmentId): Attachment
125
    {
126
        if (!$this->validator->validId($attachmentId, 'attachment')) {
127
            throw new ValidationException('attachmentId', $attachmentId);
128
        }
129
130
        $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

130
        $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...
131
132
        return $this->attachment = new Attachment(
0 ignored issues
show
Documentation Bug introduced by
It seems like new InShore\Bookwhen\Dom...id, $attachment->title) of type InShore\Bookwhen\Domain\Attachment is incompatible with the declared type InShore\Bookwhen\unknown of property $attachment.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
Bug introduced by
The call to InShore\Bookwhen\Domain\Attachment::__construct() has too few arguments starting with fileSizeBytes. ( Ignorable by Annotation )

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

132
        return $this->attachment = /** @scrutinizer ignore-call */ new Attachment(

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...
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
        }
154
155
        if (!is_null($fileName) && !$this->validator->validFileName($fileName)) {
156
            throw new ValidationException('file name', $fileName);
157
        }
158
159
        if (!is_null($fileType) && !$this->validator->validFileType($fileType)) {
160
            throw new ValidationException('file type', $fileType);
161
        }
162
163
        $attachments = $this->client->attachments()->list();
164
165
        foreach ($attachments->data as $attachment) {
166
            array_push($this->attachment, new Attachment(
0 ignored issues
show
Bug introduced by
$this->attachment of type InShore\Bookwhen\Domain\Attachment is incompatible with the type array expected by parameter $array of array_push(). ( Ignorable by Annotation )

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

166
            array_push(/** @scrutinizer ignore-type */ $this->attachment, new Attachment(
Loading history...
Bug introduced by
The call to InShore\Bookwhen\Domain\Attachment::__construct() has too few arguments starting with fileUrl. ( Ignorable by Annotation )

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

166
            array_push($this->attachment, /** @scrutinizer ignore-call */ new Attachment(

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...
167
                $attachment->id,
168
            ));
169
        }
170
171
        return $this->attachments;
172
    }
173
174
    /**
175
     *
176
     * {@inheritDoc}
177
     * @see \InShore\Bookwhen\Interfaces\ClientInterface::getClassPass()
178
     * @todo
179
     */
180
    public function classPass(string $classPassId): ClassPass
181
    {
182
        //         $this->logger->debug(__METHOD__ . '(' . var_export(func_get_args(), true) . ')');
183
184
        //       if (!$this->validator->validId($classPassId, 'classPass')) {
185
        //           throw new ValidationException('classPassId', $classPassId);
186
        //      }
187
188
        $classPass = $this->client->classPasses()->retrieve($classPassId);
189
190
        return new ClassPass(
191
            $classPass->details,
192
            $classPass->id,
193
            $classPass->number_available,
194
            $classPass->title,
195
            $classPass->usage_allowance,
196
            $classPass->usage_type,
197
            $classPass->use_restricted_for_days
198
        );
199
    }
200
201
    /**
202
     *
203
     * {@inheritDoc}
204
     * @see \InShore\Bookwhen\Interfaces\ClientInterface::getClassPasses()
205
     * @todo break params on to multiplper lines..
206
     */
207
    public function classPasses(
208
        $title = null,
209
        $detail = null,
210
        $usageType = null,
211
        $cost = null,
212
        $usageAllowance = null,
213
        $useRestrictedForDays = null
214
    ): array {
215
216
        //$this->logger->debug(__METHOD__ . '(' . var_export(func_get_args(), true) . ')');
217
218
        if (!is_null($title) && !$this->validator->validTitle($title)) {
219
            throw new ValidationException('title', $title);
220
        }
221
222
        // @todo remaingin validation
223
224
        $classPasses = $this->client->classPasses()->list([]);
0 ignored issues
show
Unused Code introduced by
The call to InShore\Bookwhen\Resources\ClassPasses::list() has too many arguments starting with array(). ( Ignorable by Annotation )

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

224
        $classPasses = $this->client->classPasses()->/** @scrutinizer ignore-call */ list([]);

This check compares calls to functions or methods with their respective definitions. If the call has more 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...
225
226
        foreach ($classPasses->data as $classPass) {
227
            array_push($this->classPasses, new classPasses(
0 ignored issues
show
Bug introduced by
The type InShore\Bookwhen\classPasses was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
228
                $ticket->details,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $ticket seems to be never defined.
Loading history...
229
                $ticket->id,
230
                $ticket->title
231
            ));
232
        }
233
        return $this->classPasses;
234
    }
235
236
    /**
237
     *
238
     * {@inheritDoc}
239
     * @see \InShore\Bookwhen\Interfaces\BookwhenInterface::event()
240
     * @todo filters.
241
     */
242
    public function event(
243
        string $eventId, 
244
        bool $attachments = false,
245
        bool $location = false,
246
        bool $tickets = false,
247
        bool $ticketsClassPasses = false,
248
        bool $ticketsEventslocation = false
249
    ): Event
250
    {
251
        //$this->logger->debug(__METHOD__ . '(' . var_export(func_get_args(), true) . ')');
252
253
        if (!$this->validator->validId($eventId, 'event')) {
254
            throw new ValidationException('eventId', $eventId);
255
        }
256
257
        $event = $this->client->events()->retrieve($eventId);
258
            
259
        $eventAttachments = [];
260
        $eventTickets = [];
261
        
262
        // attachments
263
        if($attachments) {
264
            foreach ($event->attachments as $eventAttachment) {
265
                $attachment = $this->client->attachments()->retrieve($eventAttachment['id']);
266
                array_push($eventAttachments, new Attachment(
0 ignored issues
show
Bug introduced by
The call to InShore\Bookwhen\Domain\Attachment::__construct() has too few arguments starting with fileSizeBytes. ( Ignorable by Annotation )

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

266
                array_push($eventAttachments, /** @scrutinizer ignore-call */ new Attachment(

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...
267
                    $attachment->id,
268
                    $attachment->title,
269
                ));
270
            }
271
        }
272
273
        // location
274
        // @todo resolve dynamic type
275
        if(!$location) {
276
            $eventLocation = new Location(
277
                null,
278
                null,
279
                $event->locationId
280
            );
281
        }
282
        else {
283
            $location = $this->client->locations()->retrieve($event->locationId);
284
            $eventLocation = new Location(
285
                $location->addressText,
286
                $location->additionalInfo,
287
                $location->id,
288
                $location->latitude,
289
                $location->longitude,
290
                $location->mapUrl,
291
                $location->zoom
292
            );
293
        }
294
        
295
        // tickets
296
        if($tickets) {
297
            foreach ($event->tickets as $eventTicket) {
298
                $ticket = $this->client->tickets()->retrieve($eventTicket['id']);
299
                array_push($eventTickets, new Ticket(
300
                    $ticket->available,
301
                    $ticket->availableFrom,
302
                    $ticket->availableTo,
303
                    $ticket->builtBasketUrl,
304
                    $ticket->builtBasketIframeUrl,
305
                    $ticket->courseTicket,
306
                    $ticket->details,
307
                    $ticket->groupTicket,
308
                    $ticket->groupMin,
309
                    $ticket->groupMax,
310
                    $ticket->id,
311
                    $ticket->numberIssued,
312
                    $ticket->numberTaken,
313
                    $ticket->title
314
                ));
315
            }
316
        }
317
        
318
        // ticketsClassPasses
319
        // @todo
320
        
321
        // ticketsEvents
322
        // @todo
323
        
324
        return $this->event = new Event(
0 ignored issues
show
Documentation Bug introduced by
It seems like new InShore\Bookwhen\Dom...e, $event->waitingList) of type InShore\Bookwhen\Domain\Event is incompatible with the declared type InShore\Bookwhen\unknown of property $event.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
325
            $event->allDay,
326
            $eventAttachments,
327
            $event->attendeeCount,
328
            $event->attendeeLimit,
329
            $event->details,
330
            $event->endAt,
331
            $event->id,
332
            $eventLocation,
333
            $event->maxTicketsPerBooking,
334
            $event->startAt,
335
            $eventTickets,
336
            $event->title,
337
            $event->waitingList
338
         );
339
    }
340
341
    /**
342
     *
343
     * {@inheritDoc}
344
     * @see \InShore\Bookwhen\Interfaces\ClientInterface::getEvents()
345
     */
346
    public function Events(
347
        $calendar = false, 
348
        $entry = false, 
349
        $location = [], 
350
        $tags = [],
351
        $title = [], 
352
        $detail = [], 
353
        $from = null, 
354
        $to = null, 
355
        $includeAttachments = false,
356
        $includeLocation = false,
357
        $includeTickets = false, 
358
        $includeTicketsClassPasses = false,
359
        $includeTicketsEvents = false
360
    ): array {
361
362
        //$this->logger->debug(__METHOD__ . '(' . var_export(func_get_args(), true) . ')');
363
364
        // Validate $calendar
365
        // @todo details required
366
        
367
        // Validate $detail
368
        if (!empty($detail)) {
369
            if (!is_array($detail)) {
370
                throw new ValidationException('detail', implode(' ', $detail));
371
            } else {
372
                $detail = array_unique($detail);
373
                foreach($detail as $item) {
374
                    if (!$this->validator->validLocation($item)) {
375
                        throw new ValidationException('detail', $item);
376
                    }
377
                }
378
                $this->filters['filter[detail]'] = implode(',', $detail);
379
            }
380
        }
381
382
        // Validate $entry
383
        // @todo details required
384
        
385
        // Validate $from;
386
        if (!empty($from)) {
387
            if (!$this->validator->validFrom($from, $to)) {
388
                throw new ValidationException('from', $from . '-' . $to);
389
            } else {
390
                $this->filters['filter[from]'] = $from;
391
            }
392
        }
393
394
        // Validate $location
395
        if (!empty($location)) {
396
            if (!is_array($location)) {
397
                throw new ValidationException('location', implode(' ', $title));
398
            } else {
399
                $location = array_unique($location);
400
                foreach($location as $item) {
401
                    if (!$this->validator->validLocation($item)) {
402
                        throw new ValidationException('location', $item);
403
                    }
404
                }
405
                $this->filters['filter[location]'] = implode(',', $location);
406
            }
407
        }
408
        
409
        // Validate $tags.
410
        if (!empty($tags)) {
411
            if (!is_array($tags)) {
412
                throw new ValidationException('tags', implode(' ', $tags));
413
            } else {
414
                $tags = array_unique($tags);
415
                foreach ($tags as $tag) {
416
                    if (!empty($tag) && !$this->validator->validTag($tag)) {
417
                        throw new ValidationException('tag', $tag);
418
                    }
419
                }
420
            }
421
            $this->filters['filter[tag]'] = implode(',', $tags);
422
        }
423
424
        // Validate $title;
425
        if (!empty($title)) {
426
            if (!is_array($title)) {
427
                throw new ValidationException('title', implode(' ', $title));
428
            } else {
429
                $title = array_unique($title);
430
                foreach($title as $item) {
431
                    if (!$this->validator->validTitle($item)) {
432
                        throw new ValidationException('title', $item);
433
                    }
434
                }
435
                $this->filters['filter[title]'] = implode(',', $title);
436
            }
437
        }
438
        
439
        // Validate $to;
440
        if (!empty($to)) {
441
            if (!$this->validator->validTo($to, $from)) {
442
                throw new ValidationException('to', $to . '-' . $from);
443
            } else {
444
                $this->filters['filter[to]'] = $to;
445
            }
446
        }
447
        
448
        // Validate $includeAttachments;      
449
        if (!$this->validator->validInclude($includeAttachments)) {
450
            throw new ValidationException('includeAttachments', $includeAttachments);
451
        } else {
452
            if($includeAttachments) {
453
                array_push($this->includes, 'attachments');
454
            }
455
        }
456
        
457
        // Validate $includeTickets;
458
        if (!$this->validator->validInclude($includeLocation)) {
459
            throw new ValidationException('includeLocation', $includeLocation);
460
        } else {
461
            if($includeLocation) {
462
                array_push($this->includes, 'location');
463
            }
464
        }
465
        
466
        // Validate $includeTickets;
467
        if (!$this->validator->validInclude($includeTickets)) {
468
            throw new ValidationException('includeTickets', $includeTickets);
469
        } else {
470
            if($includeTickets) {
471
                array_push($this->includes, 'tickets');
472
            }
473
        }
474
        
475
        // Validate $includeTicketsEvents;
476
        if (!$this->validator->validInclude($includeTicketsEvents)) {
477
            throw new ValidationException('includeTicketsEvents', $includeTicketsEvents);
478
        } else {
479
            if($includeTickets) {
480
                array_push($this->includes, 'tickets.events');
481
            }
482
        }
483
        
484
        // Validate $includeTicketsClassPasses;
485
        if (!$this->validator->validInclude($includeTicketsClassPasses)) {
486
            throw new ValidationException('includeTicketsClassPasses', $includeTicketsClassPasses);
487
        } else {
488
            if($includeTicketsClassPasses) {
489
                array_push($this->includes, 'tickets.class_passes');
490
            }
491
        }
492
        
493
        $events = $this->client->events()->list(array_merge($this->filters, ['include' => implode(',', $this->includes)]));
494
        
495
        $eventAttachments = [];
496
        
497
        $eventTickets = [];
498
499
        foreach ($events->data as $event) {
500
            array_push($this->events, new Event(
501
                $event->allDay,
502
                $eventAttachments,
503
                $event->attendeeCount,
504
                $event->attendeeLimit,
505
                $event->details,
506
                $event->endAt,
507
                $event->id,
508
                new Location( 
509
                    null,
510
                    null, 
511
                    $event->locationId,
512
                ),
513
                $event->maxTicketsPerBooking,
514
                $event->startAt,
515
                $eventTickets,
516
                $event->title,
517
                $event->waitingList
518
            ));
519
        }
520
521
        return $this->events;
522
    }
523
524
    /*
525
     *
526
     * {@inheritDoc}
527
     * @see \InShore\Bookwhen\Interfaces\ClientInterface::getLocation()
528
     */
529
    public function location(string $locationId): Location
530
    {
531
532
        if (!$this->validator->validId($locationId, 'location')) {
533
            throw new ValidationException('locationId', $locationId);
534
        }
535
536
        $location = $this->client->locations()->retrieve($locationId);
537
538
        return $this->location = new Location(
0 ignored issues
show
Bug introduced by
The property location is declared read-only in InShore\Bookwhen\Bookwhen.
Loading history...
539
            $location->additionalInfo,
540
            $location->addressText,
541
            $location->id,
542
            $location->latitude,
543
            $location->longitude,
544
            $location->mapUrl,
545
            $location->zoom
546
        );
547
    }
548
549
    /**
550
     *
551
     * {@inheritDoc}
552
     * @see \InShore\Bookwhen\Interfaces\ClientInterface::getLocations()
553
     * @todo validate params.
554
     */
555
    public function locations(
556
        null | string $addressText = null,
557
        null | string $additionalInfo = null
558
    ): array {
559
560
        // $this->logger->debug(__METHOD__ . '(' . var_export(func_get_args(), true) . ')');
561
562
        if (!$this->validator->validId($eventId, 'event')) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $eventId seems to be never defined.
Loading history...
563
            throw new ValidationException('eventId', $eventId);
564
        }
565
566
        $locations = $this->client->locations()->list();
567
568
        foreach ($locations->data as $location) {
569
            array_push($this->locations, new Location(
570
                $location->additionalInfo,
571
                $location->addressText,
572
                $location->id,
573
                $location->latitude,
574
                $location->longitude,
575
                $location->mapUrl,
576
                $location->zoom
577
            ));
578
        }
579
580
        return $this->locations;
581
582
    }
583
584
    /**
585
     * Set Debug.
586
     * @deprecated
587
     */
588
    public function setLogging($level)
589
    {
590
        $this->logging = $level;
0 ignored issues
show
Bug Best Practice introduced by
The property logging does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
591
    }
592
593
     /**
594
     * Sets the token for all future new instances
595
     * @deprecated
596
     * @param $token string The API access token, as obtained on diffbot.com/dev.
597
     */
598
    public static function setToken($token)
599
    {
600
        $validator = new Validator();
601
        if (!$validator->validToken($token)) {
602
            throw new \InvalidArgumentException('Invalid Token.');
603
        }
604
        self::$token = $token;
0 ignored issues
show
Bug Best Practice introduced by
The property token does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
605
    }
606
607
    /**
608
     * {@inheritDoc}
609
     * @see \InShore\Bookwhen\Interfaces\BookWhenInterface::ticket()
610
     */
611
    public function ticket($ticketId): Ticket
612
    {
613
        if (!$this->validator->validId($ticketId, 'ticket')) {
614
            throw new ValidationException('ticketId', $ticketId);
615
        }
616
617
        $ticket = $this->client->tickets()->retrieve($ticketId);
618
619
        return $this->ticket = new Ticket(
620
            $ticket->available,
621
            $ticket->availableFrom,
622
            $ticket->availableTo,
623
            $ticket->builtBasketUrl,
624
            $ticket->builtBasketIframeUrl,
625
            $ticket->courseTicket,
626
            $ticket->details,
627
            $ticket->groupTicket,
628
            $ticket->groupMin,
629
            $ticket->groupMax,
630
            $ticket->id,
631
            $ticket->numberIssued,
632
            $ticket->numberTaken,
633
            $ticket->title
634
        );
635
    }
636
637
    /**
638
     * {@inheritDoc}
639
     * @see \InShore\Bookwhen\Interfaces\BookWhenInterface::tickets()
640
     * @todo includes
641
     */
642
    public function tickets(string $eventId): array
643
    {
644
        // $this->logger->debug(__METHOD__ . '(' . var_export(func_get_args(), true) . ')');
645
646
        if (!$this->validator->validId($eventId, 'event')) {
647
            throw new ValidationException('eventId', $eventId);
648
        }
649
650
        $tickets = $this->client->tickets()->list([
651
            'event_id' => $eventId,
652
            'include' => 'events.tickets'
653
        ]);
654
655
        foreach ($tickets->data as $ticket) {
656
            array_push($this->tickets, new Ticket(
657
                $ticket->available,
658
                $ticket->availableFrom,
659
                $ticket->availableTo,
660
                $ticket->builtBasketUrl,
661
                $ticket->builtBasketIframeUrl,
662
                $ticket->courseTicket,
663
                $ticket->details,
664
                $ticket->groupTicket,
665
                $ticket->groupMin,
666
                $ticket->groupMax,
667
                $ticket->id,
668
                $ticket->numberIssued,
669
                $ticket->numberTaken,
670
                $ticket->title
671
            ));
672
        }
673
674
        return $this->tickets;
675
676
    }
677
}
678