WeatherController::fetchActionGet()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 12
ccs 8
cts 8
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Anax\WeatherAPI;
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 $app if implementing the interface
15
 * AppInjectableInterface, 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 WeatherController implements ContainerInjectableInterface
22
{
23
    use ContainerInjectableTrait;
24
25
    public $model;
26
27 4
    public function initialize()
28
    {
29 4
        $this->model = new WeatherModel();
30 4
    }
31
    /**
32
     * Route for index view and form
33
     *
34
     */
35 1
    public function indexAction() : object
36
    {
37 1
        $page = $this->di->get("page");
38 1
        $weather = $this->di->get("weather");
39 1
        $message = $weather->welcomeMsg();
40 1
        $title = "Väder API";
41
        $data = [
42 1
        "message" => $message["message"],
43
        ];
44
45 1
        $page->add("weatherapi/weather", $data);
46
47 1
        return $page->render([
48 1
         "title" => $title,
49
        ]);
50
    }
51 1
    public function weatherDataAction() : object
52
    {
53 1
        $page = $this->di->get("page");
54 1
        $session = $this->di->get("session");
55 1
        $weather = $this->di->get("weather");
56 1
        $message = $weather->welcomeMsg();
57 1
        $title = "Väder API";
58
        $data = [
59 1
        "message" => $message["message"],
60 1
        "jsonData" => $session->get("jsonData"),
61 1
        "address" => $session->get("address")
62
        ];
63
64 1
        $session->set("jsonData", null);
65 1
        $session->set("address", null);
66
67 1
        $page->add("weatherapi/weather-data", $data);
68
69 1
        return $page->render([
70 1
         "title" => $title,
71
        ]);
72
    }
73
    /**
74
     * Route for form POST
75
     *
76
     */
77 2
    public function fetchActionGet() : object
78
    {
79 2
        $session = $this->di->get("session");
80 2
        $request = $this->di->get("request");
81 2
        $response = $this->di->get("response");
82
83 2
        $searchReq = $request->getGet("searchReq") ?? "";
84 2
        $date = $request->getGet("date");
85
86 2
        $this->model->getWeatherData($session, $searchReq, $date);
87
88 2
        return $response->redirect("weather-api/weather-data");
89
    }
90
}
91