Completed
Push — master ( 749d6b...11b362 )
by jesper
02:12
created

WeatherController::indexAction()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 30
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 21
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 30
ccs 0
cts 21
cp 0
crap 12
rs 9.584
1
<?php
2
3
namespace Anax\Weather;
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
 *
14
 * @SuppressWarnings(PHPMD.TooManyPublicMethods)
15
 */
16
class WeatherController implements ContainerInjectableInterface
17
{
18
    use ContainerInjectableTrait;
19
20
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
    public function indexAction()
30
    {
31
        $title = "Weather info";
32
        $page = $this->di->get("page");
33
34
        $CurlModel = $this->di->get("curl");
35
        $WeatherModel = $this->di->get("weather");
36
        $WeatherModel->setCurl($CurlModel);
37
38
        $request = $this->di->get("request");
39
40
        $page->add("weather/form-text-weather", []);
41
        $page->add("weather/clear", []);
42
43
        if ($this->di->get("request")->hasGet("location")) {
44
            $convertedLocation = $WeatherModel->convertLocation($request->getGet("location"));
45
            if ($convertedLocation["match"]) {
46
                $weatherInfo["location"] = $convertedLocation;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$weatherInfo was never initialized. Although not strictly required by PHP, it is generally a good practice to add $weatherInfo = array(); before regardless.
Loading history...
47
                $weatherInfo["weather"] = $WeatherModel->getWeather($convertedLocation["latitude"], $convertedLocation["longitude"]);
48
                $weatherInfoPast = $WeatherModel->getWeatherMulti($convertedLocation["latitude"], $convertedLocation["longitude"], 30);
49
                $page->add("weather/location", ["location" => $weatherInfo["location"]]);
50
                $page->add("weather/result", ["weatherinfo" => $weatherInfo]);
51
                $page->add("weather/resultpast", ["weatherinfo" => $weatherInfoPast["data"]]);
52
            } else {
53
                $page->add("weather/badresult", []);
54
            }
55
        }
56
57
        return $page->render([
58
            "title" => $title,
59
        ]);
60
    }
61
}
62