Issues (63)

src/ipweather/IpweatherController.php (7 issues)

1
<?php
2
3
namespace Anax\Ipweather;
4
5
use Anax\Commons\ContainerInjectableInterface;
6
use Anax\Commons\ContainerInjectableTrait;
7
8
// use Anax\Route\Exception\ForbiddenException;
9
// use Anax\Route\Exception\NotFoundException;
10
// use Anax\Route\Exception\InternalErrorException;
11
12
/**
13
 * A sample controller to show how a controller class can be implemented.
14
 * The controller will be injected with $di if implementing the interface
15
 * ContainerInjectableInterface, like this sample class does.
16
 * The controller is mounted on a particular route and can then handle all
17
 * requests for that mount point.
18
 *
19
 * @SuppressWarnings(PHPMD.TooManyPublicMethods)
20
 */
21
class IpweatherController implements ContainerInjectableInterface
22
{
23
    use ContainerInjectableTrait;
24
25
26
27
28
    /**
29
     * This is the index method action, it handles:
30
     * ANY METHOD mountpoint
31
     * ANY METHOD mountpoint/
32
     * ANY METHOD mountpoint/index
33
     *
34
     * @return string
35
     */
36 1
    public function indexActionGet() : object
37
    {
38 1
        $page = $this->di->get("page");
39
        // $adress = $_SERVER["REMOTE_ADDR"] ?? "";
40 1
        $adress = $_SERVER["HTTP_X_FORWARDED_FOR"] ?? "";
41
42
        $data = [
43 1
            "test" => "testing",
44 1
            "adress" => $adress,
45
        ];
46
47 1
        $page->add("ipweather/index", $data);
48
49 1
        return $page->render();
50
    }
51
52
53
54
    /**
55
     * This is the index method action, it handles:
56
     * ANY METHOD mountpoint
57
     * ANY METHOD mountpoint/
58
     * ANY METHOD mountpoint/index
59
     *
60
     * @return string
61
     */
62 1
    public function indexActionPost() : object
63
    {
64
        //gets pagestuff?
65 1
        $page = $this->di->get("page");
66
        //get ip
67 1
        $ip = $this->di->request->getPOST("ip");
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...
68
        //get dateChecked
69 1
        $dateChecked = $this->di->request->getPOST("dateChecked");
70
71
        //Creates validate-class object
72 1
        $validate = $this->di->get("validator");
73
        //Validates ip
74 1
        $resValidateIp = $validate->validateIp($ip);
75
        //Gets hostname
76 1
        $resDomain = $validate->getDomain($ip);
77
78 1
        $curl = new \Aiur\Curl\Curl();
79
        //Gets curl adress
80 1
        $resCurlAdress = $curl->getCurlAdress($ip, $resValidateIp);
81
82
83 1
        if (is_array($resCurlAdress)) {
0 ignored issues
show
The condition is_array($resCurlAdress) is always false.
Loading history...
84 1
            if (is_float($resCurlAdress[0])) {
85 1
                if ($dateChecked == "plusweek") {
86 1
                    $resCurlTempWeek = $curl->getCurlTemp($resCurlAdress[0], $resCurlAdress[1], $dateChecked);
87 1
                } elseif ($dateChecked == "minusmonth") {
88 1
                    $resCurlTempMonth = $curl->getCurlTemp($resCurlAdress[0], $resCurlAdress[1], $dateChecked);
89
                }
90 1
            } elseif (is_string($resCurlAdress[0])) {
91 1
                $notValid = "Search was not valid!";
92
            }
93
        } else {
94 1
            if ($dateChecked == "plusweek") {
95 1
                $resCurlTempWeek = $curl->getCurlTemp($resCurlAdress->latitude, $resCurlAdress->longitude, $dateChecked);
0 ignored issues
show
The property longitude does not seem to exist on Aiur\Curl\Curl.
Loading history...
The property latitude does not seem to exist on Aiur\Curl\Curl.
Loading history...
96 1
            } elseif ($dateChecked == "minusmonth") {
97 1
                $resCurlTempMonth = $curl->getCurlTemp($resCurlAdress->latitude, $resCurlAdress->longitude, $dateChecked);
98
            }
99
        }
100
        $data = [
101 1
            "ipval" => $resValidateIp,
102 1
            "host" => $resDomain,
103 1
            "latitude" => $resCurlAdress->latitude ?? "",
104 1
            "longitude" => $resCurlAdress->longitude ?? "",
105 1
            "country_name" => $resCurlAdress->country_name ?? "",
0 ignored issues
show
The property country_name does not seem to exist on Aiur\Curl\Curl.
Loading history...
106 1
            "region_name" => $resCurlAdress->region_name ?? "",
0 ignored issues
show
The property region_name does not seem to exist on Aiur\Curl\Curl.
Loading history...
107 1
            "resTempWeek" => $resCurlTempWeek->daily->data ?? "",
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $resCurlTempWeek does not seem to be defined for all execution paths leading up to this point.
Loading history...
108 1
            "resTempMonth" => $resCurlTempMonth ?? "",
109 1
            "notValid" => $notValid ?? ""
110
        ];
111
112 1
        $page->add("ipweather/weather", $data);
113
114
115 1
        return $page->render();
116
    }
117
}
118