Passed
Push — master ( 782176...fdfe0b )
by Peter
44s
created

Client   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 9

Test Coverage

Coverage 89.47%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 1
cbo 9
dl 0
loc 87
ccs 34
cts 38
cp 0.8947
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A create() 0 12 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 getTeams() 0 8 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\Dto\Teams\Teams;
12
use PtrTn\Battlerite\Factory\DetailedPlayerFactory;
13
use PtrTn\Battlerite\Query\Matches\MatchesQuery;
14
use PtrTn\Battlerite\Query\Players\PlayersQuery;
15
use PtrTn\Battlerite\Query\Teams\TeamsQuery;
16
use PtrTn\Battlerite\Repository\DataMappingRepository;
17
18
/**
19
 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
20
 */
21
class Client
22
{
23
    /**
24
     * @var ApiClient
25
     */
26
    private $apiClient;
27
    /**
28
     * @var DetailedPlayerFactory
29
     */
30
    private $detailedPlayerFactory;
31
32 30
    public function __construct(
33
        ApiClient $apiClient,
34
        DetailedPlayerFactory $detailedPlayerFactory
35
    ) {
36 30
        $this->apiClient = $apiClient;
37 30
        $this->detailedPlayerFactory = $detailedPlayerFactory;
38 30
    }
39
40
    /**
41
     * Create default API client setup
42
     * @todo, move this method to a factory or possibly a builder class.
43
     */
44 1
    public static function create(string $apiKey): self
45
    {
46 1
        return new self(
47 1
            new ApiClient(
48 1
                $apiKey,
49 1
                new GuzzleClient()
50
            ),
51 1
            new DetailedPlayerFactory(
52 1
                new DataMappingRepository()
53
            )
54
        );
55
    }
56
57 1
    public function getStatus(): Status
58
    {
59 1
        $responseData = $this->apiClient->sendRequestToEndPoint(
60 1
            '/status'
61
        );
62 1
        return Status::createFromArray($responseData['data']);
63
    }
64
65 8
    public function getMatches(MatchesQuery $query = null): Matches
66
    {
67 8
        $responseData = $this->apiClient->sendRequestToEndPoint(
68 8
            '/shards/global/matches',
69 8
            $query
70
        );
71 8
        return Matches::createFromArray($responseData['data']);
72
    }
73
74 7
    public function getMatch(string $matchId): DetailedMatch
75
    {
76 7
        $responseData = $this->apiClient->sendRequestToEndPoint(
77 7
            '/shards/global/matches/' . $matchId
78
        );
79 7
        return DetailedMatch::createFromArray($responseData);
80
    }
81
82 5
    public function getPlayers(PlayersQuery $query = null): Players
83
    {
84 5
        $responseData = $this->apiClient->sendRequestToEndPoint(
85 5
            '/shards/global/players',
86 5
            $query
87
        );
88 5
        return Players::createFromArray($responseData['data']);
89
    }
90
91
    public function getPlayer(string $playerId): DetailedPlayer
92
    {
93
        $responseData = $this->apiClient->sendRequestToEndPoint(
94
            '/shards/global/players/' . $playerId
95
        );
96
        return $this->detailedPlayerFactory->createFromArray($responseData['data']);
97
    }
98
99 6
    public function getTeams(TeamsQuery $query = null): Teams
100
    {
101 6
        $responseData = $this->apiClient->sendRequestToEndPoint(
102 6
            '/shards/global/teams',
103 6
            $query
104
        );
105 6
        return Teams::createFromArray($responseData['data']);
106
    }
107
}
108