Passed
Push — master ( 39dd2f...8ee4e9 )
by Rafal
03:50
created

Client   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getClient() 0 8 2
A __construct() 0 3 1
A getGames() 0 9 1
1
<?php
2
3
namespace App\GameApi\Business\WorldCupSfgIo\Client;
4
5
use GuzzleHttp\Client as GuzzleHttpClient;
6
7
8
class Client implements ClientInterface
9
{
10
    private const URL = 'https://worldcup.sfg.io/';
11
    private const GAMES = '/matches/today';
12
13
    /**
14
     * @var GuzzleHttpClient
15
     */
16
    private $client;
17
18
    /**
19
     * @var ParserInterface
20
     */
21
    private $parser;
22
23
    /**
24
     * @param ParserInterface $parser
25
     */
26
    public function __construct(ParserInterface $parser)
27
    {
28
        $this->parser = $parser;
29
    }
30
31
    /**
32
     * @return \App\GameApi\Persistence\DataProvider\GameResult[]
33
     */
34
    public function getGames() : array
35
    {
36
        $res = $this->getClient()->get(self::GAMES, $this->options);
0 ignored issues
show
Bug Best Practice introduced by
The property options does not exist on App\GameApi\Business\WorldCupSfgIo\Client\Client. Did you maybe forget to declare it?
Loading history...
37
        $gameInfo = (array)json_decode(
38
            (string)$res->getBody()->getContents(),
39
            true
40
        );
41
42
        return $this->parser->get($gameInfo);
43
    }
44
45
    /**
46
     * @return GuzzleHttpClient
47
     */
48
    private function getClient() : GuzzleHttpClient
49
    {
50
        if ($this->client === null) {
51
            $this->client = new GuzzleHttpClient([
52
                'base_uri' => self::URL
53
            ]);
54
        }
55
        return $this->client;
56
    }
57
}