Issues (11)

src/DIController/ApiDIController.php (4 issues)

1
<?php
2
3
namespace Seb\DIController;
4
5
use Anax\Commons\ContainerInjectableInterface;
6
use Anax\Commons\ContainerInjectableTrait;
7
8
9
/**
10
 *
11
 */
12
class ApiDIController implements ContainerInjectableInterface
13
{
14
    use ContainerInjectableTrait;
15
16
    /**
17
     *
18
     * @return object
19
     */
20 1
    public function indexActionGet() : object
21
    {
22 1
        $title = "DI-API";
23 1
        $page = $this->di->get("page");
24
25 1
        $page->add("DI/api");
26
27 1
        return $page->render([
28 1
            "title" => $title,
29
        ]);
30
    }
31
32
    /**
33
     *
34
     * @return object
35
     */
36 1
    public function jsonDIActionGet() : array
37
    {
38 1
        $DICheck = $this->di->get("weather");
39 1
        $request = $this->di->get("request");
40
41 1
        $ip = $request->getGet("ip", "") ?? null;
42 1
        $lat = $request->getGet("lat", "") ?? null;
43 1
        $lon = $request->getGet("lon", "") ?? null;
44
45 1
        $arr = null;
0 ignored issues
show
The assignment to $arr is dead and can be removed.
Loading history...
46 1
        $obj = null;
47
48 1
        if ($ip) {
49 1
            $arr = $DICheck->checkCords($ip);
50 1
            $lon = $arr[0];
51 1
            $lat = $arr[1];
52
        }
53
54 1
        $coVali = $DICheck->validateCords($lat, $lon);
55
56 1
        if ($coVali) {
57
            $urlsHis = $DICheck->getHistWeatherUrls($lat, $lon);
58
            $resHistory = $DICheck->curlMulti($urlsHis);
59
            $urlsFore = $DICheck->getForecastWeatherUrl($lat, $lon);
60
            $resFore = $DICheck->curlMulti($urlsFore);
61
            $obj = [
62
                'forecast' => $resHistory,
63
                'history' => $resFore
64
            ];
65
        } else {
66
            $obj = [
67 1
                'error' => "Use query [/di-api/jsonDI?ip=[ip] or /di-api/jsonDI?lat=[lat]&lon=[lon]]"
68
            ];
69
        }
70 1
        return [$obj];
0 ignored issues
show
Bug Best Practice introduced by
The expression return array($obj) returns the type array<integer,array|array<string,string>> which is incompatible with the documented return type object.
Loading history...
71
    }
72
73
    /**
74
     *
75
     * @return object
76
     */
77 1
    public function jsonDIActionPost() : array
78
    {
79 1
        $DICheck = $this->di->get("weather");
80 1
        $request = $this->di->get("request");
81
82 1
        $ip = $request->getPost("ipPost");
83 1
        $lat = $request->getPost("latPost");
84 1
        $lon = $request->getPost("lonPost");
85
86 1
        $arr = null;
0 ignored issues
show
The assignment to $arr is dead and can be removed.
Loading history...
87 1
        $obj = null;
88
89 1
        if ($ip) {
90 1
            $arr = $DICheck->checkCords($ip);
91 1
            $lon = $arr[0];
92 1
            $lat = $arr[1];
93
        }
94
95 1
        $coVali = $DICheck->validateCords($lat, $lon);
96
97 1
        if ($coVali) {
98
            $urlsHis = $DICheck->getHistWeatherUrls($lat, $lon);
99
            $resHistory = $DICheck->curlMulti($urlsHis);
100
            $urlsFore = $DICheck->getForecastWeatherUrl($lat, $lon);
101
            $resFore = $DICheck->curlMulti($urlsFore);
102
            $obj = [
103
                'forecast' => $resHistory,
104
                'history' => $resFore
105
            ];
106
        } else {
107
            $obj = [
108 1
                'error' => "Use query [/di-api/jsonDI?ip=[ip] or /di-api/jsonDI?lat=[lat]&lon=[lon]]"
109
            ];
110
        }
111 1
        return [$obj];
0 ignored issues
show
Bug Best Practice introduced by
The expression return array($obj) returns the type array<integer,array|array<string,string>> which is incompatible with the documented return type object.
Loading history...
112
    }
113
}
114