SleeperClient   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 4
eloc 8
c 3
b 0
f 0
dl 0
loc 33
ccs 10
cts 10
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getApiInstance() 0 8 2
A __construct() 0 3 1
A __call() 0 3 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