Api   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A fetchCurl() 0 8 1
A getServiceByName() 0 5 2
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