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