Completed
Push — master ( 4c98df...baa6f5 )
by Peter
01:45
created

Client   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 6
dl 0
loc 57
ccs 26
cts 26
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 0 9 1
A getMatches() 0 8 1
A getMatch() 0 7 1
A getPlayers() 0 8 1
A getPlayer() 0 7 1
1
<?php
2
3
namespace PtrTn\Battlerite;
4
5
use GuzzleHttp\Client as GuzzleClient;
6
use GuzzleHttp\ClientInterface;
7
use PtrTn\Battlerite\Dto\Match;
8
use PtrTn\Battlerite\Dto\Matches;
9
use PtrTn\Battlerite\Dto\Player;
10
use PtrTn\Battlerite\Dto\Players;
11
use PtrTn\Battlerite\Query\MatchesQuery;
12
use PtrTn\Battlerite\Query\PlayersQuery;
13
14
class Client
15
{
16
17
    /**
18
     * @var ApiClient
19
     */
20
    private $apiClient;
21
22 13
    private function __construct(ApiClient $apiClient)
23
    {
24 13
        $this->apiClient = $apiClient;
25 13
    }
26
27 13
    public static function create(string $apiKey, ?ClientInterface $httpClient = null): Client
28
    {
29 13
        return new Client(
30 13
            new ApiClient(
31 13
                $httpClient ?? new GuzzleClient(),
32 13
                $apiKey
33
            )
34
        );
35
    }
36
37 8
    public function getMatches(MatchesQuery $query = null): Matches
38
    {
39 8
        $responseData = $this->apiClient->sendRequestToEndPoint(
40 8
            '/matches',
41 8
            $query
42
        );
43 3
        return Matches::createFromArray($responseData);
44
    }
45
46 2
    public function getMatch(string $matchId): Match
47
    {
48 2
        $responseData = $this->apiClient->sendRequestToEndPoint(
49 2
            '/matches/' . $matchId
50
        );
51 1
        return Match::createFromArray($responseData['data']);
52
    }
53
54 2
    public function getPlayers(PlayersQuery $query = null): Players
55
    {
56 2
        $responseData = $this->apiClient->sendRequestToEndPoint(
57 2
            '/players',
58 2
            $query
59
        );
60 2
        return Players::createFromArray($responseData);
61
    }
62
63 1
    public function getPlayer(string $playerId): Player
64
    {
65 1
        $responseData = $this->apiClient->sendRequestToEndPoint(
66 1
            '/players/' . $playerId
67
        );
68 1
        return Player::createFromArray($responseData['data']);
69
    }
70
}
71