Players   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A all() 0 3 1
A trending() 0 15 5
1
<?php
2
3
namespace SchoppAx\Sleeper\Api;
4
5
use SchoppAx\Sleeper\Api\Utility\Validation;
6
7
class Players extends Api
8
{
9
  /**
10
   * Fetch all players (nfl only)
11
   *
12
   * @return array
13
   * @throws ClientException if status code <> 200
14 1
   * @throws Exception if response body equals null
15
   */
16 1
  public function all(): array
17
  {
18
    return $this->get('players/nfl');
19
  }
20
21
  /**
22
   * Get a list of trending players based on adds or drops
23
   *
24
   * @param string $type
25
   * @param string $sport
26
   * @param int $hours
27
   * @param int $limit
28
   *
29
   * @return array
30
   * @throws InvalidArgumentException if params doesn't match
31
   * @throws ClientException if status code <> 200
32
   * @throws Exception if response body equals null
33
   */
34
  public function trending(string $type, string $sport = 'nfl', int $hours = 24, int $limit = 25): array
35
  {
36
    $type = strtolower($type);
37
    if(!Validation::contains(['add', 'drop'], $type)) {
38
      throw new \InvalidArgumentException("trending function only accepts type 'add' or 'drop'. Input was: {$type}");
39
    } elseif(!Validation::contains($this->sports, $sport)) {
40
      $strSupported = join(", ", $this->sports);
41
      throw new \InvalidArgumentException("trending function only accepts sports like {$strSupported}. Input was: {$sport}");
42
    } elseif(!Validation::between($hours, 1, 24)) {
43
      throw new \InvalidArgumentException("trending function only accepts hours between 1 and 24. Input was: {$hours}");
44
    } elseif(!Validation::between($limit, 1, 200)) {
45
      throw new \InvalidArgumentException("trending function only accepts limits between 1 and 200. Input was: {$limit}");
46
    }
47
48
    return $this->get('players/'. $sport .'/trending/'. $type .'?lookback_hours='. $hours .'&limit='. $limit);
49
  }
50
51
}
52