JsonWeather   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 29
dl 0
loc 49
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A jsonify() 0 39 4
1
<?php
2
3
namespace KW\Models;
4
5
use Anax\Commons\ContainerInjectableInterface;
6
use Anax\Commons\ContainerInjectableTrait;
7
8
class JsonWeather implements ContainerInjectableInterface
9
{
10
    use ContainerInjectableTrait;
11
12
13
    /**
14
     * Returns weather info in json format
15
     *
16
     * @return json
17
     */
18 2
    public function jsonify($res)
19
    {
20 2
        $days = [];
21
        $mapUrl = "https://www.openstreetmap.org/?mlat="
22 2
        . $res["latitude"]. "&mlon="
23 2
        . $res["longitude"] ."&zoom=12#map=12/"
24 2
        . $res["latitude"] ."/"
25 2
        . $res["longitude"];
26
27 2
        $type = ($res["type"] == "past" ? "past mounth" : "future week");
28
29
        $backgroundinfo = array(
30 2
            "tempus"=>$type,
31 2
            "country"=>$res["country"],
32 2
            "town"=>($res["town"] ?? "---"),
33 2
            "longitude"=>$res["longitude"],
34 2
            "latitude"=>$res["latitude"],
35 2
            "mapUrl"=>$mapUrl
36
        );
37
38 2
        if (isset($res["weatherresult"]->daily->data)) {
39 1
            foreach ($res["weatherresult"]->daily->data as $key => $value) {
40 1
                array_push($days, array("day"=>($key ?? "---"),
41 1
                    "summary"=>($value->summary ?? "---"),
42 1
                    "highesttemp"=>($value->temperatureHigh ?? "---"),
43 1
                    "lowesttemp"=>($value->temperatureLow ?? "---"),
44 1
                    "windspeed"=>($value->windSpeed ?? "---"),));
45
            }
46
        } else {
47 1
            array_push($days, "data för aktuell tid saknas!");
48
        }
49
50
        $result = [
51 2
            "backgroundinfo"=>$backgroundinfo,
52 2
            "days"=>$days
53
        ];
54
        //$result = json_decode(json_encode($result));
55
56 2
        return [$result];
0 ignored issues
show
Bug Best Practice introduced by
The expression return array($result) returns the type array<integer,array<stri...g,mixed|string>|mixed>> which is incompatible with the documented return type KW\Models\json.
Loading history...
57
    }
58
}
59