Passed
Pull Request — main (#3)
by Daryl
02:28
created

Performance::facilityDescription()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.0416

Importance

Changes 0
Metric Value
cc 3
eloc 5
c 0
b 0
f 0
nc 3
nop 0
dl 0
loc 11
ccs 5
cts 6
cp 0.8333
crap 3.0416
rs 10
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
11
class Performance extends Base
12
{
13
14
    protected DateTime $_date;
15
16 1
    public function title(): string
17
    {
18 1
        return $this->_extraArgs['PerformanceDescription'] ?? '';
19
    }
20
21 1
    public function productionSeasonId(): int
22
    {
23 1
        return $this->_extraArgs['ProductionSeason']['Id'] ?? 0;
24
    }
25
26 1
    public function id(): int
27
    {
28 1
        return intval($this->_extraArgs['PerformanceId'] ?? 0);
29
    }
30
31 1
    public function description(): string
32
    {
33
34 1
        return (string)$this->_extraArgs['PerformanceDescription'];
35
36
    }
37
38 3
    public function doorsOpen(): ?DateTime
39
    {
40 3
        if (!isset($this->_extraArgs['DoorsOpen'])) {
41 1
            return null;
42
        }
43
44
        try {
45 2
            return new DateTime($this->_extraArgs['DoorsOpen']);
46 1
        } catch (Exception $e) {
47 1
            trigger_error($e->getMessage(), E_USER_NOTICE);
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