Seasons   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 94.12%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 45
ccs 16
cts 17
cp 0.9412
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A getById() 0 8 2
A get() 0 11 2
1
<?php
2
3
namespace Clubdeuce\Tessitura\Resources;
4
5
use Exception;
6
use GuzzleHttp\Client;
7
use GuzzleHttp\Exception\GuzzleException;
8
9
/**
10
 * @link https://www.tessituranetwork.com/REST_v151/TessituraService/HELP/RESOURCES/SEASONS.HTM
11
 */
12
class Seasons
13
{
14
    public const RESOURCE = 'ReferenceData/Seasons';
15
16
    protected Client $client;
17
18 2
    public function __construct(?Client $client = null)
19
    {
20 2
        if (empty($client)) {
21
            $client = new Client();
22
        }
23
24 2
        $this->client = $client;
25
    }
26
27
    /**
28
     * @link https://www.tessituranetwork.com/REST_v151/TessituraService/HELP/API/GET_REFERENCEDATA_SEASONS_ID_FI.HTM
29
     * @throws Exception
30
     */
31 1
    public function getById(int $id): Season
32
    {
33
        try {
34 1
            $response = $this->client->get(sprintf('%s/%s', self::RESOURCE, $id));
35
36 1
            return new Season(json_decode($response->getBody()->getContents(), true));
37 1
        } catch (GuzzleException $e) {
38 1
            throw new Exception($e->getMessage());
39
        }
40
    }
41
42
    /**
43
     * @return Season[]
44
     * @throws Exception
45
     */
46 1
    public function get(): array
47
    {
48
        try {
49 1
            $response = $this->client->get(self::RESOURCE);
50 1
            $data     = json_decode($response->getBody()->getContents(), true);
51
52 1
            return array_map(function (array $season) {
53 1
                return new Season($season);
54 1
            }, $data);
55 1
        } catch (GuzzleException $e) {
56 1
            throw new Exception($e->getMessage());
57
        }
58
    }
59
}
60