Passed
Pull Request — main (#15)
by
unknown
02:23
created

Performance   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Test Coverage

Coverage 95%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 35
c 3
b 0
f 0
dl 0
loc 98
ccs 38
cts 40
cp 0.95
rs 10
wmc 20

10 Methods

Rating   Name   Duplication   Size   Complexity  
A facilityId() 0 11 3
A facilityDescription() 0 11 3
A startTime() 0 6 2
A statusId() 0 3 1
A date() 0 15 4
A description() 0 4 1
A doorsOpen() 0 10 3
A title() 0 3 1
A productionSeasonId() 0 3 1
A id() 0 3 1
1
<?php
2
3
namespace Clubdeuce\Tessitura\Resources;
4
5
use Clubdeuce\Tessitura\Base\Base;
6
use DateInterval;
7
use DateTime;
8
use DateTimeZone;
9
use Exception;
10
use Throwable;
11
12
class Performance extends Base
13
{
14
15
    protected DateTime $_date;
16
17 1
    public function title(): string
18
    {
19 1
        return $this->_extraArgs['PerformanceDescription'] ?? '';
20
    }
21
22 1
    public function productionSeasonId(): int
23
    {
24 1
        return $this->_extraArgs['ProductionSeason']['Id'] ?? 0;
25
    }
26
27 1
    public function id(): int
28
    {
29 1
        return intval($this->_extraArgs['PerformanceId'] ?? 0);
30
    }
31
32 1
    public function description(): string
33
    {
34
35 1
        return (string)$this->_extraArgs['PerformanceDescription'];
36
37
    }
38
39 3
    public function doorsOpen(): ?DateTime
40
    {
41 3
        if (!isset($this->_extraArgs['DoorsOpen'])) {
42 1
            return null;
43
        }
44
45
        try {
46 2
            return new DateTime($this->_extraArgs['DoorsOpen']);
47 1
        } catch (Throwable $e) {
48 1
            return null;
49
        }
50
    }
51
52 4
    public function facilityId(): int
53
    {
54 4
        if (!isset($this->_extraArgs['Facility'])) {
55 1
            return 0;
56
        }
57
58 3
        if (!isset($this->_extraArgs['Facility']['Id'])) {
59
            return 0;
60
        }
61
62 3
        return intval($this->_extraArgs['Facility']['Id']);
63
    }
64
65 3
    public function facilityDescription(): string
66
    {
67 3
        if (!isset($this->_extraArgs['Facility'])) {
68
            return '';
69
        }
70
71 3
        if (!isset($this->_extraArgs['Facility']['Description'])) {
72 1
            return '';
73
        }
74
75 2
        return $this->_extraArgs['Facility']['Description'];
76
    }
77
78 4
    public function startTime(): ?DateTime
79
    {
80
        try {
81 4
            return $this->date();
82 1
        } catch (Exception $e) {
83 1
            return null;
84
        }
85
    }
86
87
    /**
88
     * @throws Exception
89
     */
90 7
    public function date(string $timezone = 'America/New_York'): ?DateTime
91
    {
92 7
        if (isset($this->_date)) {
93 1
            return $this->_date;
94
        }
95
96 6
        if (isset($this->_extraArgs['PerformanceDate'])) {
97
            try {
98 4
                return new DateTime($this->_extraArgs['PerformanceDate'], new DateTimeZone($timezone));
99 1
            } catch (Exception $e) {
100 1
                throw new Exception("Unable to convert performance date into DateTime object: {$e->getMessage()}", E_USER_WARNING);
101
            }
102
        }
103
104 2
        return null;
105
    }
106
107 1
    public function statusId(): int
108
    {
109 1
        return intval($this->_extraArgs['PerformanceStatus']['Id']);
110
    }
111
112
}
113