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

ProductionSeason   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Test Coverage

Coverage 81.82%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 26
dl 0
loc 64
ccs 18
cts 22
cp 0.8182
rs 10
c 2
b 0
f 0
wmc 11

3 Methods

Rating   Name   Duplication   Size   Complexity  
A performances() 0 3 1
A firstPerformanceDate() 0 18 5
A lastPerformanceDate() 0 18 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
/**
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