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

Client::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

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