Passed
Push — master ( fd66bc...1c0213 )
by Ax
05:30
created

Leagues::losersBracket()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SchoppAx\Sleeper\Api;
4
5
use SchoppAx\Sleeper\Api\Utility\Validation;
6
7
class Leagues extends Api
8
{
9
10
  /**
11
   * @param string $leagueId
12
   * @return array
13
   * @throws ClientException if status code <> 200
14 4
   * @throws Exception if response body equals null
15
   */
16 4
  public function find(string $leagueId): array
17
  {
18
    return $this->get('league/' . $leagueId);
19
  }
20
21
  /**
22
   * @param string $userId
23
   * @param int $season
24
   * @param string[optional] $sport default is nfl
25
   * @return array
26
   * @throws InvalidArgumentException if params doesn't match
27 1
   * @throws ClientException if status code <> 200
28
   * @throws Exception if response body equals null
29 1
   */
30
  public function byUser(string $userId, int $season, string $sport = 'nfl'): array
31
  {
32
    if(!Validation::between($season, 2015, date("Y")) || !Validation::contains(['nfl'], $sport)) {
0 ignored issues
show
Bug introduced by
date('Y') of type string is incompatible with the type integer expected by parameter $max of SchoppAx\Sleeper\Api\Utility\Validation::between(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

32
    if(!Validation::between($season, 2015, /** @scrutinizer ignore-type */ date("Y")) || !Validation::contains(['nfl'], $sport)) {
Loading history...
33
      throw new \InvalidArgumentException("byUser function only accepts seasons since 2015 and sport type 'nfl'. Inputs were: {$season}, {$sport}");
34
    }
35
36
    return $this->get('user/' . $userId . '/leagues/'. $sport .'/' . $season);
37
  }
38
39
  /**
40 1
   * @param string $leagueId
41
   * @param int $week
42 1
   * @return array
43
   * @throws InvalidArgumentException if params doesn't match
44
   * @throws ClientException if status code <> 200
45
   * @throws Exception if response body equals null
46
   */
47
  public function matchups(string $leagueId, int $week): array
48
  {
49
    if(!Validation::between($week, 1, 16)) {
50
      throw new \InvalidArgumentException("matchups function only accepts weeks between 1 and 16. Input was: {$week}");
51 1
    }
52
53 1
    return $this->get('league/' . $leagueId . '/matchups/' . $week);
54
  }
55
56
  /**
57
   * @param string[optional] $sport default is nfl
58
   * @return array
59
   * @throws InvalidArgumentException if params doesn't match
60
   * @throws ClientException if status code <> 200
61
   * @throws Exception if response body equals null
62 1
   */
63
  public function state(string $sport = 'nfl'): array
64 1
  {
65
    $supported = ['nfl', 'nba', 'lcs'];
66
    if(!Validation::contains($supported, $sport)) {
67
      $strSupported = join(", ", $supported);
68
      throw new \InvalidArgumentException("state function only accepts sports like {$strSupported}. Input was: {$sport}");
69
    }
70
71
    return $this->get('state/'. $sport);
72
  }
73 1
74
  /**
75 1
   * @param string $leagueId
76
   * @return array
77
   * @throws ClientException if status code <> 200
78
   * @throws Exception if response body equals null
79
   */
80
  public function users(string $leagueId): array
81
  {
82
    return $this->get('league/' . $leagueId . '/users');
83
  }
84
85
  /**
86
   * @param string $leagueId
87
   * @return array
88
   * @throws ClientException if status code <> 200
89
   * @throws Exception if response body equals null
90
   */
91
  public function rosters(string $leagueId): array
92
  {
93
    return $this->get('league/' . $leagueId . '/rosters');
94
  }
95
96
  /**
97
   * @param string $leagueId
98
   * @return array
99
   * @throws ClientException if status code <> 200
100
   * @throws Exception if response body equals null
101
   */
102
  public function winnersBracket(string $leagueId): array
103
  {
104
    return $this->get('league/' . $leagueId . '/winners_bracket');
105
  }
106
107
  /**
108
   * @param string $leagueId
109
   * @return array
110
   * @throws ClientException if status code <> 200
111
   * @throws Exception if response body equals null
112
   */
113
  public function losersBracket(string $leagueId): array
114
  {
115
    return $this->get('league/' . $leagueId . '/losers_bracket');
116
  }
117
118
  /**
119
   * @param string $leagueId
120
   * @param int $round
121
   * @return array
122
   * @throws InvalidArgumentException if params doesn't match
123
   * @throws ClientException if status code <> 200
124
   * @throws Exception if response body equals null
125
   */
126
  public function transactions(string $leagueId, int $round): array
127
  {
128
    if(!Validation::between($round, 1, 16)) {
129
      throw new \InvalidArgumentException("transactions function only accepts rounds between 1 and 16. Input was: {$round}");
130
    }
131
132
    return $this->get('league/' . $leagueId . '/transactions/' . $round);
133
  }
134
135
  /**
136
   * @param string $leagueId
137
   * @return array
138
   * @throws ClientException if status code <> 200
139
   * @throws Exception if response body equals null
140
   */
141
  public function tradedPicks(string $leagueId): array
142
  {
143
    return $this->get('league/' . $leagueId . '/traded_picks');
144
  }
145
146
}
147