Passed
Push — master ( fe4a41...f4c116 )
by Peter
32s
created

Client   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 7
dl 0
loc 68
ccs 30
cts 30
cp 1
rs 10

7 Methods

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