| Total Complexity | 4 |
| Total Lines | 61 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 15 | class FixerHttpClient extends Client |
||
| 16 | { |
||
| 17 | const BASE_URI = "http://data.fixer.io/api"; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Time to wait in seconds before interrupting the request. |
||
| 21 | */ |
||
| 22 | const TIMEOUT = 5; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var string |
||
| 26 | */ |
||
| 27 | private $apiKey; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var SymbolsEndpoint |
||
| 31 | */ |
||
| 32 | public $symbols; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var LatestExchangeRatesEndpoint |
||
| 36 | */ |
||
| 37 | public $rates; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * FixerHttpClient constructor. |
||
| 41 | * |
||
| 42 | * @param string $key |
||
| 43 | * @param array $config |
||
| 44 | * @throws MissingAPIKeyException |
||
| 45 | */ |
||
| 46 | 27 | public function __construct(string $key, array $config = []) |
|
| 47 | { |
||
| 48 | 27 | if (empty($key)) { |
|
| 49 | 3 | throw new MissingAPIKeyException(); |
|
| 50 | } |
||
| 51 | |||
| 52 | 24 | $this->apiKey = $key; |
|
| 53 | $baseConfig = [ |
||
| 54 | 24 | 'base_uri' => self::BASE_URI, |
|
| 55 | 24 | RequestOptions::TIMEOUT => self::TIMEOUT |
|
| 56 | ]; |
||
| 57 | 24 | parent::__construct(array_merge($baseConfig, $config)); |
|
| 58 | 24 | $this->initEndpoints(); |
|
| 59 | 24 | } |
|
| 60 | |||
| 61 | /** |
||
| 62 | * @return string |
||
| 63 | */ |
||
| 64 | 15 | public function getApiKey(): string |
|
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Initializes all the supported endpoints. |
||
| 71 | */ |
||
| 72 | 24 | private function initEndpoints() |
|
| 78 |