Api   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 11
c 2
b 0
f 0
dl 0
loc 28
ccs 10
cts 10
cp 1
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get() 0 11 3
1
<?php
2
3
namespace SchoppAx\Sleeper\Api;
4
5
use SchoppAx\Sleeper\Http\Client;
6
7
abstract class Api
8
{
9
    private $client;
10
    protected $sports;
11 16
12
    public function __construct(Client $client)
13 16
    {
14 16
      $this->client = $client;
15
      $this->sports = ['nfl', 'nba', 'lcs'];
16
    }
17
18
19
    /**
20
     * @param string $path
21
     * @return mixed (json) of called api resource
22 16
     * @throws Exception
23
     */
24 16
    protected function get(string $path)
25
    {
26 15
      $response = $this->client->request('GET', $path);
27 1
28 14
      if ($response->getStatusCode() !== 200) {
29 1
        throw new \Exception('Client error: `GET '. $path .'` resulted in a '. $response->getStatusCode() .' response');
30
      } elseif ($response->getBody()->getSize() === 0) {
31
        throw new \Exception('Client error: `GET '. $path .'` resulted in a empty response body');
32 13
      }
33
34
      return json_decode($response->getBody(), true);
35
    }
36
37
}
38