Client   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 63
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A getTeams() 0 6 1
A getClient() 0 8 2
A getGames() 0 6 1
1
<?php
2
3
4
namespace App\GameApi\Business\ApiFootballData;
5
6
7
use GuzzleHttp\Client as GuzzleHttpClient;
8
9
class Client implements ClientInterface
10
{
11
    private const TEAMS = '/v1/competitions/467/teams';
12
    private const GAMES = '/v1/competitions/467/fixtures';
13
14
    /**
15
     * @var GuzzleHttpClient
16
     */
17
    private $client;
18
19
    /**
20
     * @var array
21
     */
22
    private $options = [];
23
24
    /**
25
     */
26
    public function __construct()
27
    {
28
        if (null !== getenv('API_FOOTBALL_DATA')) {
29
            $this->options = [
30
                'headers' => [
31
                    'X-Auth-Token' => getenv('API_FOOTBALL_DATA')
32
                ]
33
            ];
34
        }
35
    }
36
37
    /**
38
     * @return array
39
     */
40
    public function getTeams() : array
41
    {
42
        $res = $this->getClient()->get(self::TEAMS, $this->options);
43
        return (array)json_decode(
44
            (string)$res->getBody()->getContents(),
45
            true
46
        );
47
    }
48
49
    /**
50
     * @return array
51
     */
52
    public function getGames() : array
53
    {
54
        $res = $this->getClient()->get(self::GAMES, $this->options);
55
        return (array)json_decode(
56
            (string)$res->getBody()->getContents(),
57
            true
58
        );
59
    }
60
61
    /**
62
     * @return GuzzleHttpClient
63
     */
64
    private function getClient()
65
    {
66
        if ($this->client === null) {
67
            $this->client = new GuzzleHttpClient([
68
                'base_uri' => 'http://api.football-data.org/'
69
            ]);
70
        }
71
        return $this->client;
72
    }
73
}