Passed
Pull Request — main (#15)
by
unknown
02:23
created

ProductionSeason   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Test Coverage

Coverage 76.92%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 30
c 2
b 0
f 0
dl 0
loc 71
ccs 20
cts 26
cp 0.7692
rs 10
wmc 13

3 Methods

Rating   Name   Duplication   Size   Complexity  
A performances() 0 3 1
A last_performance_date() 0 21 6
A first_performance_date() 0 21 6
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
use Throwable;
11
12
/**
13
 * @method string[] response()
14
 */
15
class ProductionSeason extends Base
16
{
17
18
    /**
19
     * @var string[]
20
     */
21
    protected array $_response = [];
22
23
    /**
24
     * @var Performance[]
25
     */
26
    protected array $_performances = [];
27
28
    /**
29
     * @throws InvalidArgumentException
30
     */
31 4
    public function first_performance_date(string $timezone = 'America/New_York'): DateTime|bool
32
    {
33
        try {
34 4
            $timezone = new DateTimeZone($timezone);
35 1
        } catch (Exception $e) {
36 1
            throw new InvalidArgumentException($e->getMessage());
37
        }
38
39 3
        if ($date = isset($this->response()['FirstPerformanceDate']) ? $this->response()['FirstPerformanceDate'] : false) {
40
            try {
41 2
                $result = DateTime::createFromFormat(' Y-m-d\TG:i:sp', $date, $timezone);
42 2
                if ($result === false) {
43
                    throw new Exception("Invalid date format for FirstPerformanceDate");
44
                }
45 2
                return $result;
46
            } catch (Throwable $e) {
47
                throw new Exception("Unable to parse FirstPerformanceDate: " . $e->getMessage());
48
            }
49
        }
50
51 1
        return false;
52
    }
53
54
    /**
55
     * @throws InvalidArgumentException
56
     */
57 3
    public function last_performance_date(string $timezone = 'America/New_York'): DateTime|bool
58
    {
59
        try {
60 3
            $timezone = new DateTimeZone($timezone);
61 1
        } catch (Exception $e) {
62 1
            throw new InvalidArgumentException($e->getMessage());
63
        }
64
65 2
        if ($date = isset($this->response()['LastPerformanceDate']) ? $this->response()['LastPerformanceDate'] : false) {
66
            try {
67 1
                $result = DateTime::createFromFormat(' Y-m-d\TG:i:sp', $date, $timezone);
68 1
                if ($result === false) {
69
                    throw new Exception("Invalid date format for LastPerformanceDate");
70
                }
71 1
                return $result;
72
            } catch (Throwable $e) {
73
                throw new Exception("Unable to parse LastPerformanceDate: " . $e->getMessage());
74
            }
75
        }
76
77 1
        return false;
78
    }
79
80
    /**
81
     * @return Performance[]
82
     */
83 1
    public function performances(): array
84
    {
85 1
        return $this->_performances;
86
    }
87
88
}
89