CurlWrapModel::getIpData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 6
nc 1
nop 2
dl 0
loc 13
c 0
b 0
f 0
cc 1
ccs 7
cts 7
cp 1
crap 1
rs 10
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