Leagues::rosters()   A
last analyzed

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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
ccs 0
cts 0
cp 0
crap 2
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
    if(!Validation::contains($this->sports, $sport)) {
66
      $strSupported = join(", ", $this->sports);
67
      throw new \InvalidArgumentException("state function only accepts sports like {$strSupported}. Input was: {$sport}");
68
    }
69
70
    return $this->get('state/'. $sport);
71
  }
72
73 1
  /**
74
   * @param string $leagueId
75 1
   * @return array
76
   * @throws ClientException if status code <> 200
77
   * @throws Exception if response body equals null
78
   */
79
  public function users(string $leagueId): array
80
  {
81
    return $this->get('league/' . $leagueId . '/users');
82
  }
83
84
  /**
85
   * @param string $leagueId
86
   * @return array
87
   * @throws ClientException if status code <> 200
88
   * @throws Exception if response body equals null
89
   */
90
  public function rosters(string $leagueId): array
91
  {
92
    return $this->get('league/' . $leagueId . '/rosters');
93
  }
94
95
  /**
96
   * @param string $leagueId
97
   * @return array
98
   * @throws ClientException if status code <> 200
99
   * @throws Exception if response body equals null
100
   */
101
  public function winnersBracket(string $leagueId): array
102
  {
103
    return $this->get('league/' . $leagueId . '/winners_bracket');
104
  }
105
106
  /**
107
   * @param string $leagueId
108
   * @return array
109
   * @throws ClientException if status code <> 200
110
   * @throws Exception if response body equals null
111
   */
112
  public function losersBracket(string $leagueId): array
113
  {
114
    return $this->get('league/' . $leagueId . '/losers_bracket');
115
  }
116
117
  /**
118
   * @param string $leagueId
119
   * @param int $round
120
   * @return array
121
   * @throws InvalidArgumentException if params doesn't match
122
   * @throws ClientException if status code <> 200
123
   * @throws Exception if response body equals null
124
   */
125
  public function transactions(string $leagueId, int $round): array
126
  {
127
    if(!Validation::between($round, 1, 16)) {
128
      throw new \InvalidArgumentException("transactions function only accepts rounds between 1 and 16. Input was: {$round}");
129
    }
130
131
    return $this->get('league/' . $leagueId . '/transactions/' . $round);
132
  }
133
134
  /**
135
   * @param string $leagueId
136
   * @return array
137
   * @throws ClientException if status code <> 200
138
   * @throws Exception if response body equals null
139
   */
140
  public function tradedPicks(string $leagueId): array
141
  {
142
    return $this->get('league/' . $leagueId . '/traded_picks');
143
  }
144
145
}
146