Test Failed
Pull Request — main (#12)
by
unknown
03:55 queued 01:33
created

ProductionSeason::response()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Clubdeuce\Tessitura\Resources;
4
5
use Clubdeuce\Tessitura\Base\Base;
6
use DateTime;
7
use DateTimeZone;
8
use Exception;
9
use InvalidArgumentException;
10
11
class ProductionSeason extends Base
12
{
13
14
    /**
15
     * @var string[]
16
     */
17
    protected array $_response = [];
18
19
    /**
20
     * @var Performance[]
21
     */
22
    protected array $_performances = [];
23
24
    /**
25
     * Get the response data for this production season.
26
     *
27
     * @return array The response data
28
     */
29
    public function response(): array
30 4
    {
31
        return $this->_response;
32
    }
33 4
34 1
    /**
35 1
     * @throws InvalidArgumentException
36
     */
37
    public function first_performance_date(string $timezone = 'America/New_York'): DateTime|bool
38 3
    {
39
        try {
40 2
            $timezone = new DateTimeZone($timezone);
41
        } catch (Exception $e) {
42
            throw new InvalidArgumentException($e->getMessage());
43
        }
44
45
        if ($date = isset($this->response()['FirstPerformanceDate']) ? $this->response()['FirstPerformanceDate'] : false) {
46 1
            try {
47
                return DateTime::createFromFormat(' Y-m-d\TG:i:sp', $date, $timezone);
48
            } catch (Exception $e) {
49
                trigger_error($e->getMessage(), E_USER_ERROR);
50
            }
51
        }
52 3
53
        return false;
54
    }
55 3
56 1
    /**
57 1
     * @throws InvalidArgumentException
58
     */
59
    public function last_performance_date(string $timezone = 'America/New_York'): DateTime|bool
60 2
    {
61
        try {
62 1
            $timezone = new DateTimeZone($timezone);
63
        } catch (Exception $e) {
64
            throw new InvalidArgumentException($e->getMessage());
65
        }
66
67
        if ($date = isset($this->response()['LastPerformanceDate']) ? $this->response()['LastPerformanceDate'] : false) {
68 1
            try {
69
                return DateTime::createFromFormat(' Y-m-d\TG:i:sp', $date, $timezone);
70
            } catch (Exception $e) {
71
                trigger_error($e->getMessage(), E_USER_ERROR);
72
            }
73
        }
74 1
75
        return false;
76 1
    }
77
78
    /**
79
     * @return Performance[]
80
     */
81
    public function performances(): array
82
    {
83
        return $this->_performances;
84
    }
85
86
}
87