Completed
Pull Request — master (#6)
by Rafal
07:50 queued 03:16
created

Client::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
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 Client
16
     */
17
    private $client;
18
19
    /**
20
     * @var string
21
     */
22
    private $options = [];
23
24
    /**
25
     */
26
    public function __construct()
27
    {
28
        if (null !== getenv('API_FOOTBALL_DATA')) {
29
            $this->options = [
0 ignored issues
show
Documentation Bug introduced by
It seems like array('headers' => array...('API_FOOTBALL_DATA'))) of type array<string,array<string,string>> is incompatible with the declared type string of property $options.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
30
                'headers' => [
31
                    'X-Auth-Token' => getenv('API_FOOTBALL_DATA')
32
                ]
33
            ];
34
        }
35
    }
36
37
38
    public function getTeams()
39
    {
40
        $res = $this->getClient()->get(self::TEAMS, $this->options);
0 ignored issues
show
Bug introduced by
The method get() does not exist on App\GameApi\Business\ApiFootballData\Client. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

40
        $res = $this->getClient()->/** @scrutinizer ignore-call */ get(self::TEAMS, $this->options);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
$this->options of type string is incompatible with the type array expected by parameter $options of GuzzleHttp\Client::get(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

40
        $res = $this->getClient()->get(self::TEAMS, /** @scrutinizer ignore-type */ $this->options);
Loading history...
41
        return json_decode(
42
            (string)$res->getBody()->getContents(),
43
            true
44
        );
45
    }
46
47
    public function getGames()
48
    {
49
        $res = $this->getClient()->get(self::GAMES, $this->options);
0 ignored issues
show
Bug introduced by
$this->options of type string is incompatible with the type array expected by parameter $options of GuzzleHttp\Client::get(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

49
        $res = $this->getClient()->get(self::GAMES, /** @scrutinizer ignore-type */ $this->options);
Loading history...
50
        return json_decode(
51
            (string)$res->getBody()->getContents(),
52
            true
53
        );
54
    }
55
56
    private function getClient()
57
    {
58
        if ($this->client === null) {
59
            $this->client = new GuzzleHttpClient([
0 ignored issues
show
Documentation Bug introduced by
It seems like new GuzzleHttp\Client(ar...i.football-data.org/')) of type GuzzleHttp\Client is incompatible with the declared type App\GameApi\Business\ApiFootballData\Client of property $client.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
60
                'base_uri' => 'http://api.football-data.org/'
61
            ]);
62
        }
63
        return $this->client;
64
    }
65
}