weatherApiController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
eloc 27
c 0
b 0
f 0
dl 0
loc 43
ccs 20
cts 22
cp 0.9091
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A indexAction() 0 34 4
1
<?php
2
namespace Anax\Controller;
3
use Anax\Commons\ContainerInjectableInterface;
4
use Anax\Commons\ContainerInjectableTrait;
5
// use Anax\Route\Exception\ForbiddenException;
6
// use Anax\Route\Exception\NotFoundException;
7
// use Anax\Route\Exception\InternalErrorException;
8
/**
9
 * A sample controller to show how a controller class can be implemented.
10
 */
11
class weatherApiController implements ContainerInjectableInterface
12
{
13
    use ContainerInjectableTrait;
14
    /**
15
     * This is the index method action, it handles:
16
     * ANY METHOD mountpoint
17
     *
18
     * @return array
19
     */
20 3
    public function indexAction() : array
21
    {
22 3
        $weather = $this->di->get("weather");
23 3
        $search = $this->di->request->getGet("search");
0 ignored issues
show
Bug introduced by
Accessing request on the interface Psr\Container\ContainerInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
24 3
        $when = $this->di->request->getGet("when")  ?? "future";
25
26 3
        $ip = $this->di->request->getGet("search");
27 3
        $validator = new \Anax\Model\ipValidation;
28 3
        $res = $validator->toJson($ip);
29
30 3
        if ($res["valid"] == "valid IP"){
31 1
            $locationInfo = $weather->getLocationData($res["city"]);
32
        } else {
33 2
            if (!isset($search)){
34
                $locationInfo = $weather->getLocationData("");
35
            } else{
36 2
                $locationInfo = $weather->getLocationData($search);
37
            }
38
        }
39 3
        $lon = $locationInfo["lon"] ?? null;
40 3
        $lat = $locationInfo["lat"] ?? null;
41 3
        if (!isset($locationInfo["error"])){
42
43
            $weatherInfo = $weather->getWeatherMultiCurl($when,$lon,$lat);
44
        } else {
45 3
            $weatherInfo = ["error" => "that is not a city"];
46
        }
47
        $data = [
48 3
            "location" => $search ?? null,
49 3
            "lon" => $lon ?? null,
50 3
            "lat" => $lat ?? null,
51 3
            "weatherInfo" => $weatherInfo,
52
        ];
53 3
        return [$data];
54
    }
55
}
56