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

Client::getStatus()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

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