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

Season::getStartDateTime()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.2098

Importance

Changes 0
Metric Value
cc 3
eloc 7
c 0
b 0
f 0
nc 3
nop 1
dl 0
loc 13
ccs 5
cts 7
cp 0.7143
crap 3.2098
rs 10
1
<?php
2
namespace Clubdeuce\Tessitura\Resources;
3
4
use Clubdeuce\Tessitura\Base\Base;
5
use DateTime;
6
use DateTimeZone;
7
use Throwable;
8
9
class Season extends Base {
10
11 2
    public function getCreatedDateTime(string $timezone = 'America/New_York') : ?DateTime {
12
13
        // Check if 'CreatedDateTime' is present in the extra args
14 2
        if (!isset($this->extraArgs()['CreatedDateTime'])) {
15 1
            return null; // or throw an exception if required
16
        }
17
18
        try {
19 1
            $createdDateTime = new DateTime($this->extraArgs()['CreatedDateTime'], new DateTimeZone($timezone));
20
21 1
            return $createdDateTime;
22
        } catch (Throwable $e) {
23
            return null;
24
        }
25
    }
26
27 1
    public function getDescription(): string
28
    {
29 1
        return (string)$this->extraArgs()['Description'];
30
    }
31
32 2
    public function getEndDateTime(string $timezone = 'America/New_York') : ?DateTime
33
    {
34
        // Check if 'EndDateTime' is present in the extra args
35 2
        if (!isset($this->extraArgs()['EndDateTime'])) {
36 1
            return null;
37
        }
38
39
        try {
40 1
            $endDateTime = new DateTime($this->extraArgs()['EndDateTime'], new DateTimeZone($timezone));
41
42 1
            return $endDateTime;
43
        } catch (Throwable $e) {
44
            return null;
45
        }
46
    }
47
48 1
    public function getId(): int
49
    {
50 1
        return intval($this->extraArgs()['Id']);
51
    }
52
53 2
    public function getStartDateTime(string $timezone = 'America/New_York') : ?\DateTime
54
    {
55
        // Check if 'StartDateTime' is present in the extra args
56 2
        if (!isset($this->extraArgs()['StartDateTime'])) {
57 1
            return null; // or throw an exception if required
58
        }
59
60
        try {
61 1
            $startDateTime = new DateTime($this->extraArgs()['StartDateTime'], new DateTimeZone($timezone));
62
63 1
            return $startDateTime;
64
        } catch (Throwable $e) {
65
            return null;
66
        }
67
    }
68
}