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

ProductionSeason   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 25
dl 0
loc 73
ccs 16
cts 20
cp 0.8
rs 10
c 3
b 0
f 0
wmc 12

4 Methods

Rating   Name   Duplication   Size   Complexity  
A response() 0 3 1
A performances() 0 3 1
A last_performance_date() 0 17 5
A first_performance_date() 0 17 5
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