Passed
Push — main ( 19d97c...3a0d8d )
by Daryl
02:38
created

ProductionSeason::lastPerformanceDate()   A

Complexity

Conditions 5
Paths 7

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 5.2

Importance

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