Passed
Pull Request — develop (#87)
by
unknown
12:10
created

Bookwhen::event()   C

Complexity

Conditions 14
Paths 160

Size

Total Lines 131
Code Lines 53

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 14
eloc 53
c 1
b 0
f 0
nc 160
nop 6
dl 0
loc 131
rs 5.7666

How to fix   Long Method    Complexity   

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 $includeAttachments = false,
245
        bool $includeLocation = false,
246
        bool $includeTickets = false,
247
        bool $includeTicketsClassPasses = false,
248
        bool $includeTicketsEvents = false
249
    ): Event {
250
        //$this->logger->debug(__METHOD__ . '(' . var_export(func_get_args(), true) . ')');
251
252
        if (!$this->validator->validId($eventId, 'event')) {
253
            throw new ValidationException('eventId', $eventId);
254
        }
255
256
        // Validate $includeAttachments;
257
        if (!$this->validator->validInclude($includeAttachments)) {
258
            throw new ValidationException('includeAttachments', $includeAttachments);
259
        } else {
260
            if($includeAttachments) {
261
                array_push($this->includes, 'attachments');
262
            }
263
        }
264
        
265
        // Validate $includeTickets;
266
        if (!$this->validator->validInclude($includeLocation)) {
267
            throw new ValidationException('includeLocation', $includeLocation);
268
        } else {
269
            if($includeLocation) {
270
                array_push($this->includes, 'location');
271
            }
272
        }
273
        
274
        // Validate $includeTickets;
275
        if (!$this->validator->validInclude($includeTickets)) {
276
            throw new ValidationException('includeTickets', $includeTickets);
277
        } else {
278
            if($includeTickets) {
279
                array_push($this->includes, 'tickets');
280
            }
281
        }
282
        
283
        // Validate $includeTicketsEvents;
284
        if (!$this->validator->validInclude($includeTicketsEvents)) {
285
            throw new ValidationException('includeTicketsEvents', $includeTicketsEvents);
286
        } else {
287
            if($includeTicketsEvents) {
288
                array_push($this->includes, 'tickets.events');
289
            }
290
        }
291
        
292
        // Validate $includeTicketsClassPasses;
293
        if (!$this->validator->validInclude($includeTicketsClassPasses)) {
294
            throw new ValidationException('includeTicketsClassPasses', $includeTicketsClassPasses);
295
        } else {
296
            if($includeTicketsClassPasses) {
297
                array_push($this->includes, 'tickets.class_passes');
298
            }
299
        }
300
301
        $event = $this->client->events()->retrieve($eventId, ['include' => implode(',', $this->includes)]);
302
303
        $eventAttachments = []; // deprecated
304
        $eventTickets = []; // deprecated
305
306
        // attachments
307
        if($includeAttachments) {
308
//             foreach ($event->attachments as $eventAttachment) {
309
//                 $attachment = $this->client->attachments()->retrieve($eventAttachment['id']);
310
//                 array_push($eventAttachments, new Attachment(
311
//                     $attachment->contentType,
312
//                     $attachment->fileUrl,
313
//                     $attachment->fileSizeBytes,
314
//                     $attachment->fileSizeText,
315
//                     $attachment->fileName,
316
//                     $attachment->fileType,
317
//                     $attachment->id
318
//                 ));
319
//             }
320
        }
321
322
        // tickets
323
        if($includeTickets) {
324
//             foreach ($event->tickets as $eventTicket) {
325
//                 $ticket = $this->client->tickets()->retrieve($eventTicket['id']);
326
//                 array_push($eventTickets, new Ticket(
327
//                     $ticket->available,
328
//                     $ticket->availableFrom,
329
//                     $ticket->availableTo,
330
//                     $ticket->builtBasketUrl,
331
//                     $ticket->builtBasketIframeUrl,
332
//                     $ticket->courseTicket,
333
//                     $ticket->details,
334
//                     $ticket->groupTicket,
335
//                     $ticket->groupMin,
336
//                     $ticket->groupMax,
337
//                     $ticket->id,
338
//                     $ticket->numberIssued,
339
//                     $ticket->numberTaken,
340
//                     $ticket->title
341
//                 ));
342
//             }
343
        }
344
345
        // ticketsClassPasses
346
        // @todo
347
348
        // ticketsEvents
349
        // @todo
350
351
        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...
352
            $event->allDay,
353
            $eventAttachments,
354
            $event->attendeeCount,
355
            $event->attendeeLimit,
356
            $event->details,
357
            $event->endAt,
358
            $event->id,
359
            new Location(
360
                $event->location->addressText,
361
                $event->location->additionalInfo,
362
                $event->location->id,
363
                $event->location->latitude,
364
                $event->location->longitude,
365
                $event->location->mapUrl,
366
                $event->location->zoom
367
            ),
368
            $event->maxTicketsPerBooking,
369
            $event->startAt,
370
            $eventTickets,
371
            $event->title,
372
            $event->waitingList
373
        );
374
    }
375
376
    /**
377
     *
378
     * {@inheritDoc}
379
     * @see \InShore\Bookwhen\Interfaces\ClientInterface::getEvents()
380
     */
381
    public function events(
382
        $calendar = false,
383
        $entry = false,
384
        $location = [],
385
        $tags = [],
386
        $title = [],
387
        $detail = [],
388
        $from = null,
389
        $to = null,
390
        bool $includeAttachments = false,
391
        bool $includeLocation = false,
392
        bool $includeTickets = false,
393
        bool $includeTicketsClassPasses = false,
394
        bool $includeTicketsEvents = false
395
    ): array {
396
397
        //$this->logger->debug(__METHOD__ . '(' . var_export(func_get_args(), true) . ')');
398
399
        // Validate $calendar
400
        // @todo details required
401
402
        // Validate $detail
403
        if (!empty($detail)) {
404
            if (!is_array($detail)) {
405
                throw new ValidationException('detail', implode(' ', $detail));
406
            } else {
407
                $detail = array_unique($detail);
408
                foreach($detail as $item) {
409
                    if (!$this->validator->validLocation($item)) {
410
                        throw new ValidationException('detail', $item);
411
                    }
412
                }
413
                $this->filters['filter[detail]'] = implode(',', $detail);
414
            }
415
        }
416
417
        // Validate $entry
418
        // @todo details required
419
420
        // Validate $from;
421
        if (!empty($from)) {
422
            if (!$this->validator->validFrom($from, $to)) {
423
                throw new ValidationException('from', $from . '-' . $to);
424
            } else {
425
                $this->filters['filter[from]'] = $from;
426
            }
427
        }
428
429
        // Validate $location
430
        if (!empty($location)) {
431
            if (!is_array($location)) {
432
                throw new ValidationException('location', implode(' ', $title));
433
            } else {
434
                $location = array_unique($location);
435
                foreach($location as $item) {
436
                    if (!$this->validator->validLocation($item)) {
437
                        throw new ValidationException('location', $item);
438
                    }
439
                }
440
                $this->filters['filter[location]'] = implode(',', $location);
441
            }
442
        }
443
444
        // Validate $tags.
445
        if (!empty($tags)) {
446
            if (!is_array($tags)) {
447
                throw new ValidationException('tags', implode(' ', $tags));
448
            } else {
449
                $tags = array_unique($tags);
450
                foreach ($tags as $tag) {
451
                    if (!empty($tag) && !$this->validator->validTag($tag)) {
452
                        throw new ValidationException('tag', $tag);
453
                    }
454
                }
455
            }
456
            $this->filters['filter[tag]'] = implode(',', $tags);
457
        }
458
459
        // Validate $title;
460
        if (!empty($title)) {
461
            if (!is_array($title)) {
462
                throw new ValidationException('title', implode(' ', $title));
463
            } else {
464
                $title = array_unique($title);
465
                foreach($title as $item) {
466
                    if (!$this->validator->validTitle($item)) {
467
                        throw new ValidationException('title', $item);
468
                    }
469
                }
470
                $this->filters['filter[title]'] = implode(',', $title);
471
            }
472
        }
473
474
        // Validate $to;
475
        if (!empty($to)) {
476
            if (!$this->validator->validTo($to, $from)) {
477
                throw new ValidationException('to', $to . '-' . $from);
478
            } else {
479
                $this->filters['filter[to]'] = $to;
480
            }
481
        }
482
483
        // Validate $includeAttachments;
484
        if (!$this->validator->validInclude($includeAttachments)) {
485
            throw new ValidationException('includeAttachments', $includeAttachments);
486
        } else {
487
            if($includeAttachments) {
488
                array_push($this->includes, 'attachments');
489
            }
490
        }
491
492
        // Validate $includeTickets;
493
        if (!$this->validator->validInclude($includeLocation)) {
494
            throw new ValidationException('includeLocation', $includeLocation);
495
        } else {
496
            if($includeLocation) {
497
                array_push($this->includes, 'location');
498
            }
499
        }
500
501
        // Validate $includeTickets;
502
        if (!$this->validator->validInclude($includeTickets)) {
503
            throw new ValidationException('includeTickets', $includeTickets);
504
        } else {
505
            if($includeTickets) {
506
                array_push($this->includes, 'tickets');
507
            }
508
        }
509
510
        // Validate $includeTicketsEvents;
511
        if (!$this->validator->validInclude($includeTicketsEvents)) {
512
            throw new ValidationException('includeTicketsEvents', $includeTicketsEvents);
513
        } else {
514
            if($includeTicketsEvents) {
515
                array_push($this->includes, 'tickets.events');
516
            }
517
        }
518
519
        // Validate $includeTicketsClassPasses;
520
        if (!$this->validator->validInclude($includeTicketsClassPasses)) {
521
            throw new ValidationException('includeTicketsClassPasses', $includeTicketsClassPasses);
522
        } else {
523
            if($includeTicketsClassPasses) {
524
                array_push($this->includes, 'tickets.class_passes');
525
            }
526
        }
527
528
        $events = $this->client->events()->list(array_merge($this->filters, ['include' => implode(',', $this->includes)]));
529
530
        foreach ($events->data as $event) {
531
            array_push($this->events, new Event(
532
                $event->allDay,
533
                $event->attachments,
534
                $event->attendeeCount,
535
                $event->attendeeLimit,
536
                $event->details,
537
                $event->endAt,
538
                $event->id,
539
                new Location(
540
                    $event->location->addressText,
541
                    $event->location->additionalInfo,
542
                    $event->location->id,
543
                    $event->location->latitude,
544
                    $event->location->longitude,
545
                    $event->location->mapUrl,
546
                    $event->location->zoom
547
                ),
548
                $event->maxTicketsPerBooking,
549
                $event->startAt,
550
                $event->tickets,
551
                $event->title,
552
                $event->waitingList
553
            ));
554
        }
555
556
        return $this->events;
557
    }
558
559
    /*
560
     *
561
     * {@inheritDoc}
562
     * @see \InShore\Bookwhen\Interfaces\ClientInterface::getLocation()
563
     */
564
    public function location(string $locationId): Location
565
    {
566
567
        if (!$this->validator->validId($locationId, 'location')) {
568
            throw new ValidationException('locationId', $locationId);
569
        }
570
571
        $location = $this->client->locations()->retrieve($locationId);
572
573
        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...
574
            $location->additionalInfo,
575
            $location->addressText,
576
            $location->id,
577
            $location->latitude,
578
            $location->longitude,
579
            $location->mapUrl,
580
            $location->zoom
581
        );
582
    }
583
584
    /**
585
     *
586
     * {@inheritDoc}
587
     * @see \InShore\Bookwhen\Interfaces\ClientInterface::getLocations()
588
     * @todo validate params.
589
     */
590
    public function locations(
591
        null | string $addressText = null,
592
        null | string $additionalInfo = null
593
    ): array {
594
595
        // $this->logger->debug(__METHOD__ . '(' . var_export(func_get_args(), true) . ')');
596
597
        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...
598
            throw new ValidationException('eventId', $eventId);
599
        }
600
601
        $locations = $this->client->locations()->list();
602
603
        foreach ($locations->data as $location) {
604
            array_push($this->locations, new Location(
605
                $location->additionalInfo,
606
                $location->addressText,
607
                $location->id,
608
                $location->latitude,
609
                $location->longitude,
610
                $location->mapUrl,
611
                $location->zoom
612
            ));
613
        }
614
615
        return $this->locations;
616
617
    }
618
619
    /**
620
     * Set Debug.
621
     * @deprecated
622
     */
623
    public function setLogging($level)
624
    {
625
        $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...
626
    }
627
628
     /**
629
     * Sets the token for all future new instances
630
     * @deprecated
631
     * @param $token string The API access token, as obtained on diffbot.com/dev.
632
     */
633
    public static function setToken($token)
634
    {
635
        $validator = new Validator();
636
        if (!$validator->validToken($token)) {
637
            throw new \InvalidArgumentException('Invalid Token.');
638
        }
639
        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...
640
    }
641
642
    /**
643
     * {@inheritDoc}
644
     * @see \InShore\Bookwhen\Interfaces\BookWhenInterface::ticket()
645
     */
646
    public function ticket($ticketId): Ticket
647
    {
648
        if (!$this->validator->validId($ticketId, 'ticket')) {
649
            throw new ValidationException('ticketId', $ticketId);
650
        }
651
652
        $ticket = $this->client->tickets()->retrieve($ticketId);
653
654
        return $this->ticket = new Ticket(
655
            $ticket->available,
656
            $ticket->availableFrom,
657
            $ticket->availableTo,
658
            $ticket->builtBasketUrl,
659
            $ticket->builtBasketIframeUrl,
660
            $ticket->courseTicket,
661
            $ticket->details,
662
            $ticket->groupTicket,
663
            $ticket->groupMin,
664
            $ticket->groupMax,
665
            $ticket->id,
666
            $ticket->numberIssued,
667
            $ticket->numberTaken,
668
            $ticket->title
669
        );
670
    }
671
672
    /**
673
     * {@inheritDoc}
674
     * @see \InShore\Bookwhen\Interfaces\BookWhenInterface::tickets()
675
     * @todo includes
676
     */
677
    public function tickets(string $eventId): array
678
    {
679
        // $this->logger->debug(__METHOD__ . '(' . var_export(func_get_args(), true) . ')');
680
681
        if (!$this->validator->validId($eventId, 'event')) {
682
            throw new ValidationException('eventId', $eventId);
683
        }
684
685
        $tickets = $this->client->tickets()->list([
686
            'event_id' => $eventId,
687
            'include' => 'events.tickets'
688
        ]);
689
690
        foreach ($tickets->data as $ticket) {
691
            array_push($this->tickets, new Ticket(
692
                $ticket->available,
693
                $ticket->availableFrom,
694
                $ticket->availableTo,
695
                $ticket->builtBasketUrl,
696
                $ticket->builtBasketIframeUrl,
697
                $ticket->courseTicket,
698
                $ticket->details,
699
                $ticket->groupTicket,
700
                $ticket->groupMin,
701
                $ticket->groupMax,
702
                $ticket->id,
703
                $ticket->numberIssued,
704
                $ticket->numberTaken,
705
                $ticket->title
706
            ));
707
        }
708
709
        return $this->tickets;
710
711
    }
712
}
713