DarkSky   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 19
dl 0
loc 35
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A weather() 0 18 3
1
<?php
2
3
namespace KW\Models;
4
5
class DarkSky
6
{
7
    /**
8
     * Return a weather forecast from DarkSky
9
     *
10
     * @return json
11
     */
12
13 7
    public function __construct($di)
14
    {
15 7
        $this->di = $di;
0 ignored issues
show
Bug Best Practice introduced by
The property di does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
16 7
        $this->darkSkyKey = $this->di->get("apikeys")["config"]["darkSky"];
0 ignored issues
show
Bug Best Practice introduced by
The property darkSkyKey does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
17 7
        $this->baseUrl = "https://api.darksky.net/forecast/";
0 ignored issues
show
Bug Best Practice introduced by
The property baseUrl does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
18 7
        $this->apiSettings = "?lang=sv&units=si";
0 ignored issues
show
Bug Best Practice introduced by
The property apiSettings does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
19 7
    }
20
21
22 3
    public function weather($longitude, $latitude, $type)
23
    {
24 3
        if ($type=="future") {
25 1
            $url = ($this->baseUrl . $this->darkSkyKey . "/" . $latitude . "," . $longitude . $this->apiSettings);
26 1
            $cURL = new CURL;
27 1
            $result = $cURL->req($url);
28 1
            $result = json_decode($result);
29 1
            if ($result == null) {
30 1
                $result["error"] = "något blev fel";
31 1
                $result["daily"]["data"][0] = "no info";
32 1
                $result = json_decode(json_encode($result));
33
            }
34 1
            return $result;
35
        } else {
36 2
            $multi = new MultiCURL($this->di);
37
38 2
            $result = $multi->multicurla($longitude, $latitude);
39 2
            return $result;
40
        }
41
    }
42
}
43