weatherApiController::indexAction()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 34
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 20
CRAP Score 4.0119

Importance

Changes 0
Metric Value
cc 4
eloc 25
c 0
b 0
f 0
nc 6
nop 0
dl 0
loc 34
ccs 20
cts 22
cp 0.9091
crap 4.0119
rs 9.52
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