Configuration::timeout()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
namespace Dwr\OpenWeather;
3
4
use GuzzleHttp\Client;
5
use GuzzleHttp\ClientInterface;
6
7
class Configuration
8
{
9
    const DEFAULT_BASE_URI = 'http://api.openweathermap.org';
10
    const DEFAULT_VERSION = '/data/2.5';
11
    const DEFAULT_TIMEOUT = '3.0';
12
13
    /**
14
     * @var string
15
     */
16
    private $baseUri;
17
18
    /**
19
     * @var string
20
     */
21
    private $version;
22
23
    /**
24
     * @var string
25
     */
26
    private $timeout;
27
28
    /**
29
     * HTTP Client
30
     */
31
    private $httpClient;
32
33
    /**
34
     * @var string
35
     */
36
    private $apiKey;
37
38
    /**
39
     * Configuration constructor.
40
     * @param string $apiKey
41
     */
42
    public function __construct($apiKey)
43
    {
44
        $this->baseUri = self::DEFAULT_BASE_URI;
45
        $this->version = self::DEFAULT_VERSION;
46
        $this->timeout = self::DEFAULT_TIMEOUT;
47
        $this->httpClient = $this->getHttpClient();
48
        $this->apiKey = $apiKey;
49
    }
50
51
    /**
52
     * @return string
53
     */
54
    public function baseUri()
55
    {
56
        return $this->baseUri;
57
    }
58
59
    /**
60
     * @param string $baseUri
61
     */
62
    public function setBaseUri($baseUri)
63
    {
64
        $this->baseUri = $baseUri;
65
    }
66
67
    /**
68
     * @return string
69
     */
70
    public function version()
71
    {
72
        return $this->version;
73
    }
74
75
    /**
76
     * @param string $version
77
     */
78
    public function setVersion($version)
79
    {
80
        $this->version = $version;
81
    }
82
83
    /**
84
     * @return string
85
     */
86
    public function timeout()
87
    {
88
        return $this->timeout;
89
    }
90
91
    /**
92
     * @param string $timeout
93
     */
94
    public function setTimeout($timeout)
95
    {
96
        $this->timeout = $timeout;
97
    }
98
99
    /**
100
     * @param ClientInterface $httpClient
101
     */
102
    public function setHttpClient(ClientInterface $httpClient)
103
    {
104
        $this->httpClient = $httpClient;
105
    }
106
107
    /**
108
     * @return Client
109
     */
110
    public function getHttpClient()
111
    {
112
        if ($this->httpClient) {
113
            return $this->httpClient;
114
        }
115
        return $this->httpClient = $this->setDefaultHttpClient();
116
    }
117
118
    /**
119
     * @return Client
120
     */
121
    private function setDefaultHttpClient()
122
    {
123
        return new Client([
124
            'base_uri' => self::DEFAULT_BASE_URI,
125
            'timeout' => self::DEFAULT_TIMEOUT
126
        ]);
127
    }
128
129
    /**
130
     * @return string
131
     */
132
    public function apiKey()
133
    {
134
        return $this->apiKey;
135
    }
136
}
137