WeatherAPIController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 73.68%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
dl 0
loc 37
c 1
b 0
f 0
ccs 14
cts 19
cp 0.7368
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A indexActionPost() 0 24 2
A initialize() 0 4 1
1
<?php
2
3
namespace Teca\Weather;
4
5
use Anax\Commons\ContainerInjectableInterface;
6
use Anax\Commons\ContainerInjectableTrait;
7
8
class WeatherAPIController implements ContainerInjectableInterface
9
{
10
    use ContainerInjectableTrait;
11
12
    protected $weather = null;
13
    protected $validator = null;
14
15
    public function initialize()
16
    {
17
        $this->weather = $this->di->get("weather");
18
        $this->validator = $this->di->get("ipValidator");
19
    }
20
21 1
    public function indexActionPost() : array
22
    {
23 1
        $request = $this->di->get("request");
24 1
        $query = $request->getPost("query");
25
26 1
        $geo = $this->validator->getGeo($query);
27
28 1
        if ($geo["city"] !== null) {
29
            $query = $geo["city"];
30
        }
31
32 1
        $forecast = $this->weather->getForecast($query);
33
34
        $json = [
35 1
            "error" => $forecast["error"],
36 1
            "country_name" => $geo["country_name"],
37 1
            "region_name" => $geo["region_name"],
38 1
            "query" => $query,
39 1
            "history" => $forecast["history"],
40 1
            "today" => $forecast["today"],
41 1
            "forecast" => $forecast["forecast"]
42
        ];
43
44 1
        return [$json];
45
    }
46
}
47