SleeperClient::__call()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
ccs 2
cts 2
cp 1
crap 1
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