Issues (21)

src/Weather/WeatherJSONController.php (3 issues)

1
<?php
2
3
namespace Anax\Weather;
4
5
use Anax\Commons\ContainerInjectableInterface;
6
use Anax\Commons\ContainerInjectableTrait;
7
use Anax\Models\WeatherForecast;
8
use Anax\Models\GetGeo;
9
10
class WeatherJSONController implements ContainerInjectableInterface
11
{
12
    use ContainerInjectableTrait;
13
14
    public function checkWeatherRestAction()
15
    {
16
        $location = $_GET["location"];
17
18
        $weather = $this->di->get("weather");
19
        $type = $this->di->get("request")->getGet("type");
20
        $geo = new GetGeo();
21
22
23
        if ($type == 'prognosAPI') {
24
            if (strpos($location, ",") == true) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing strpos($location, ',') of type integer to the boolean true. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
25
                $exploded = explode(",", $location);
26
                $data = $weather->checkWeather($exploded[0], $exploded[1]);
27
            } else {
28
                $res = $geo->getGeo($location);
29
                if ($res["longitude"] !== null) {
30
                    $data = $weather->checkWeather($res["latitude"], $res["longitude"]);
31
                } else {
32
                    $error = "Felaktig input, prova igen!";
33
                }
34
            }
35
        } elseif ($type == 'historyAPI') {
36
            if (strpos($location, ",") == true) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing strpos($location, ',') of type integer to the boolean true. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
37
                $exploded = explode(",", $location);
38
                $data = $weather->checkHistory($exploded[0], $exploded[1]);
39
            } else {
40
                $res = $geo->getGeo($location);
41
                if ($res["longitude"] !== null) {
42
                    $data = $weather->checkHistory($res["latitude"], $res["longitude"]);
43
                } else {
44
                    $error = "Felaktig input, prova igen!";
45
                }
46
            }
47
        }
48
49
50
        $data = [
51
            "forecast" => $data ?? null,
52
            "error" => $error ?? null
53
        ];
54
55
        json_encode($data, true);
0 ignored issues
show
true of type true is incompatible with the type integer expected by parameter $options of json_encode(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

55
        json_encode($data, /** @scrutinizer ignore-type */ true);
Loading history...
56
57
        return [[ $data ]];
58
    }
59
}
60