Completed
Push — master ( e99512...934009 )
by Peter
01:49
created

Client   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 7
dl 0
loc 65
ccs 25
cts 30
cp 0.8333
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 0 9 1
A getStatus() 0 7 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 PtrTn\Battlerite\Dto\Match;
7
use PtrTn\Battlerite\Dto\Matches;
8
use PtrTn\Battlerite\Dto\Player;
9
use PtrTn\Battlerite\Dto\Players;
10
use PtrTn\Battlerite\Dto\Status;
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 8
    public function __construct(ApiClient $apiClient)
23
    {
24 8
        $this->apiClient = $apiClient;
25 8
    }
26
27
    public static function create(string $apiKey): Client
28
    {
29
        return new Client(
30
            new ApiClient(
31
                $apiKey,
32
                new GuzzleClient()
33
            )
34
        );
35
    }
36
37 1
    public function getStatus(): Status
38
    {
39 1
        $responseData = $this->apiClient->sendRequestToEndPoint(
40 1
            '/status'
41
        );
42 1
        return Status::createFromArray($responseData['data']);
43
    }
44
45 3
    public function getMatches(MatchesQuery $query = null): Matches
46
    {
47 3
        $responseData = $this->apiClient->sendRequestToEndPoint(
48 3
            '/shards/global/matches',
49 3
            $query
50
        );
51 3
        return Matches::createFromArray($responseData['data']);
52
    }
53
54 1
    public function getMatch(string $matchId): Match
55
    {
56 1
        $responseData = $this->apiClient->sendRequestToEndPoint(
57 1
            '/shards/global/matches/' . $matchId
58
        );
59 1
        return Match::createFromArray($responseData['data']);
60
    }
61
62 2
    public function getPlayers(PlayersQuery $query = null): Players
63
    {
64 2
        $responseData = $this->apiClient->sendRequestToEndPoint(
65 2
            '/shards/global/players',
66 2
            $query
67
        );
68 2
        return Players::createFromArray($responseData['data']);
69
    }
70
71 1
    public function getPlayer(string $playerId): Player
72
    {
73 1
        $responseData = $this->apiClient->sendRequestToEndPoint(
74 1
            '/shards/global/players/' . $playerId
75
        );
76 1
        return Player::createFromArray($responseData['data']);
77
    }
78
}
79