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

Client::getPlayer()   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 1
crap 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