Issues (14)

src/Models/Weather.php (3 issues)

1
<?php
2
3
namespace Anax\Models;
4
5
use Anax\Config\apiTokens;
0 ignored issues
show
The type Anax\Config\apiTokens was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
7
class Weather
8
{
9
    private $keys;
10
11 26
    public function setKeys($keyData)
12
    {
13 26
        $this->keys = $keyData;
14 26
    }
15
16 18
    public function getWeatherGeo($lat, $long, $weather)
17
    {
18 18
        $accessKey = $this->keys['darksky'];
19
20 18
        if ($weather == "futureWeather") {
21 9
            $darkSkyUrl = 'https://api.darksky.net/forecast/' . $accessKey . "/" . $lat . "," . $long . "?units=si&lang=sv";
22 9
            $curlObj = new Curl;
23 9
            $darkSkyData = json_decode($curlObj->curl($darkSkyUrl));
24
        } else {
25
            // Past weather, change $numberOfDays to how many past days you wanna see the weather for.
26 9
            $numberOfDays = 5;
27 9
            for ($i = 0; $i < $numberOfDays; $i++) {
28 9
                $timestr = "-" . $i . " day";
29 9
                $time = strtotime($timestr, time());
30 9
                $urls[$i] = 'https://api.darksky.net/forecast/' . $accessKey . "/" . $lat . "," . $long . "," . $time . "?units=si&lang=sv";
31
            }
32
            // var_dump($urls);
33 9
            $curlObj = new Curl;
34 9
            $curlOutput = $curlObj->multiCurl($urls);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $urls does not seem to be defined for all execution paths leading up to this point.
Loading history...
35 9
            for ($i = 0; $i < $numberOfDays; $i++) {
36 9
                $darkSkyData[$i] = json_decode($curlOutput[$i]);
37
            }
38
        }
39
40
        //Get location data
41 18
        $locationUrl = "https://nominatim.openstreetmap.org/reverse?lat=$lat&lon=$long&[email protected]&format=json";
42 18
        $curlObj = new Curl;
43 18
        $locationData = json_decode($curlObj->curl($locationUrl));
44
45
        $json = [
46 18
            "weather" => $weather,
47 18
            "darkSkyData" => $darkSkyData,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $darkSkyData does not seem to be defined for all execution paths leading up to this point.
Loading history...
48 18
            "locationData" => $locationData,
49
        ];
50
51 18
        return $json;
52
    }
53
54 14
    public function getDarkSkyWeather($lat, $long, $futureOrPast)
55
    {
56 14
        if ($lat <= 90 && $lat >= -90 && $long >= -180 && $long <= 180) {
57 12
            $weatherJson = $this->getWeatherGeo($lat, $long, $futureOrPast);
58 12
            $dataExists = true;
59 12
            $status = "";
60
        } else {
61 2
            $weatherJson = "";
62 2
            $dataExists = false;
63 2
            $status = "Okänd plats";
64
        }
65
66
        return [
67 14
            "weatherJson" => $weatherJson,
68 14
            "dataExists" => $dataExists,
69 14
            "status" => $status,
70
        ];
71
    }
72
}
73