Issues (12)

src/Controller/GeoController.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace Anax\Controller;
4
5
use Anax\Commons\ContainerInjectableInterface;
6
use Anax\Commons\ContainerInjectableTrait;
7
use Anax\Model\Coordinates;
8
9
// use Anax\Route\Exception\ForbiddenException;
10
// use Anax\Route\Exception\NotFoundException;
11
// use Anax\Route\Exception\InternalErrorException;
12
13
/**
14
 *
15
 * Geo Controller for weather report
16
 *
17
 */
18
class GeoController implements ContainerInjectableInterface
19
{
20
    use ContainerInjectableTrait;
21
    /**
22
     * This is the index method action, it handles:
23
     * ANY METHOD mountpoint
24
     * ANY METHOD mountpoint/
25
     * ANY METHOD mountpoint/index
26
     *
27
     * @return string
28
     */
29 1
    public function indexAction() : object
30
    {
31
        //get page
32 1
        $page = $this->di->get("page");
33
        //name="ip"
34 1
        if ($this->di->request->getGet("submit")) {
0 ignored issues
show
Accessing request on the interface Psr\Container\ContainerInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
35 1
            $search = $this->di->request->getGet("search");
36
        } else {
37
            $search = $this->di->request->getServer("REMOTE_ADDR");
38
        }
39
40 1
        if (filter_var($search, FILTER_VALIDATE_IP)) {
41 1
            $valid = "IP";
42 1
            $ipverify = $this->di->get("ipverify");
43 1
            $validator = new \Anax\Model\IpValidator($ipverify);
44 1
            $res = $validator->getIp($search);
45
46 1
            $lat = $res["lat"];
47 1
            $long = $res["long"];
48
        } else {
49 1
            $coordinatesObj = $this->di->get("coordinates");
50 1
            $coordinates = new \Anax\Model\Coordinates($coordinatesObj);
51 1
            $cord = $coordinates->getCoordinates($search);
52 1
            $valid = $cord["valid"];
53
54 1
            $lat = $cord["lat"];
55 1
            $long = $cord["long"];
56
        }
57
58 1
        $weather = $this->di->get("weather-module");
59 1
        $geo = new \Anax\Model\GeoTag($weather);
60
61 1
        $when = "";
62 1
        $weather = array();
63 1
        $temp = array();
64 1
        $time = array();
65
66 1
        if ($this->di->request->getGet("when")) {
67 1
            $when = $this->di->request->getGet("when");
68 1
            if ($when == "past") {
69 1
                $res = $geo->getWeatherMultiCurl("past", $lat, $long);
70
                // $time = $res[0]["currently"]["time"];
71 1
                $amount = count($res);
72
73 1
                for ($i = 0; $i < $amount; $i++) {
74 1
                    $time[] = (date('Y-m-d', $res[$i]["currently"]["time"]));
75 1
                    $weather[] = $res[$i]["currently"]["summary"];
76 1
                    $temp[] = round($res[$i]["currently"]["temperature"], 1);
77
                }
78
            } else {
79 1
                $res = $geo->getWeatherMultiCurl("future", $lat, $long);
80 1
                $amount = count($res);
81
82 1
                for ($i = 0; $i < $amount; $i++) {
83 1
                    $time[] = (date('Y-m-d', $res[$i]["currently"]["time"]));
84 1
                    $weather[] = $res[$i]["currently"]["summary"];
85 1
                    $temp[] = round($res[$i]["currently"]["temperature"], 1);
86
                }
87
            }
88
        }
89
90
        $data = [
91 1
            "search" => $search,
92 1
            "valid" => $valid,
93 1
            "lat" => $lat,
94 1
            "long" => $long,
95 1
            "time" => $time,
96 1
            "weather" => $weather,
97 1
            "temp" => $temp,
98 1
            "when" => $when
99
        ];
100
101 1
        $page->add("geoTag/main", $data);
102 1
        return $page->render();
103
    }
104
}
105