Api::__construct()   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
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace H4MSK1\Curl;
4
5
use H4MSK1\Curl\Traits\WeatherApiTrait;
6
7
class Api
8
{
9
    use WeatherApiTrait;
10
11
    private $di;
12
    private $endpoints = [];
13
14
    public function __construct(array $endpoints = [], $di = null)
15
    {
16
        $this->endpoints = $endpoints;
17
        $this->di = $di;
18
    }
19
20
    public function getServiceByName($name)
21
    {
22
        return array_key_exists($name, $this->endpoints)
23
            ? $this->endpoints[$name]
24
            : false;
25
    }
26
27
    public function fetchCurl($endpoint)
28
    {
29
        $curl = curl_init($endpoint);
30
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
31
        $response = json_decode(curl_exec($curl), true);
32
        curl_close($curl);
33
34
        return $response;
35
    }
36
}
37