SleeperClient::getApiInstance()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 8
rs 10
ccs 5
cts 5
cp 1
crap 2
1
<?php
2
3
namespace SchoppAx\Sleeper;
4
5
use SchoppAx\Sleeper\Http\Client;
6
7
class SleeperClient {
8
  private $client;
9
10 17
  public function __construct($mock = NULL)
11
  {
12 17
    $this->client = new Client($mock);
13 17
  }
14
15
  /**
16
   * @param string $method
17
   * @param string $parameters
18
   *
19
   * @method class avatars() retrieves avatar images for users and leagues
20
   * @method class drafts() retrieves all drafts by a user or league
21
   * @method class leagues() retrieves all leagues
22
   * @method class players() retrieves all players
23
   * @method class users() retrieve user object by name or id
24
   *
25
   * @throws BadMethodCallException
26
   */
27 17
  public function __call($method, array $parameters = [])
28
  {
29 17
    return $this->getApiInstance($method);
30
  }
31
32 17
  protected function getApiInstance($method): object
33
  {
34 17
    $class = "\\SchoppAx\\Sleeper\\Api\\".ucwords($method);
35
36 17
    if (class_exists($class)) {
37 16
        return new $class($this->client);
38
    }
39 1
    throw new \BadMethodCallException("Undefined method [{$method}] called.");
40
  }
41
42
}
43