CurlWrapModel   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 35
c 0
b 0
f 0
ccs 14
cts 14
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getIpData() 0 13 1
A getWeatherData() 0 13 1
1
<?php
2
3
namespace Anax\Models;
4
5
use Anax\Commons\ContainerInjectableInterface;
6
use Anax\Commons\ContainerInjectableTrait;
7
8
class CurlWrapModel implements ContainerInjectableInterface
9
{
10
    use ContainerInjectableTrait;
11
    public $ipData = [];
12
    public $weatherData = [];
13
    public $map = [];
14
15 3
    public function getIpData($address, $key)
16
    {
17 3
        $curl = curl_init("http://api.ipstack.com/" . $address . '?access_key=' . $key . '');
18 3
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
19
20
        // Store the data:
21 3
        $json = curl_exec($curl);
22 3
        curl_close($curl);
23
24
        // Decode JSON response:
25 3
        $this->ipData = json_decode($json, true);
26
27 3
        return $this->ipData;
28
    }
29
30 3
    public function getWeatherData($weatherKey)
31
    {
32 3
        $curl = curl_init('https://api.darksky.net/forecast/' . $weatherKey . '/' . $this->ipData["latitude"] . "," . $this->ipData["longitude"]);
33 3
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
34
35
        // Store the data:
36 3
        $json = curl_exec($curl);
37 3
        curl_close($curl);
38
39
        // Decode JSON response:
40 3
        $this->weatherData = json_decode($json, true);
41
42 3
        return $this->weatherData;
43
    }
44
}
45