Passed
Push — master ( 8c3235...4c6ee6 )
by Ax
05:21
created

Players::trending()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 2
nop 4
dl 0
loc 8
ccs 0
cts 0
cp 0
crap 12
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SchoppAx\Sleeper\Api;
4
5
class Players extends Api
6
{
7
  /**
8
   * Fetch all players (nfl only)
9
   *
10
   * @return array
11
   * @throws ClientException if status code <> 200
12
   * @throws Exception if response body equals null
13
   */
14 1
  public function all(): array
15
  {
16 1
    return $this->get('players/nfl');
17
  }
18
19
  /**
20
   * Get a list of trending players based on adds or drops
21
   *
22
   * @param string $type
23
   * @param string $sport
24
   * @param string $hours
25
   * @param string $limit
26
   *
27
   * @return array
28
   * @throws InvalidArgumentException if params doesn't match
29
   * @throws ClientException if status code <> 200
30
   * @throws Exception if response body equals null
31
   */
32
  public function trending(string $type, string $sport = 'nfl', int $hours = 24, int $limit = 25): array
33
  {
34
    $type = strtolower($type);
35
    if($type !== 'add' && $type !== 'drop') {
36
      throw new \InvalidArgumentException('trending function only accepts type "add" or "drop". Input was: '. $type);
37
    }
38
39
    return $this->get('players/'. $sport .'/trending/'. $type .'?lookback_hours='. $hours .'&limit='. $limit);
40
  }
41
42
}
43