WeatherApiController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 91.67%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 13
c 2
b 0
f 0
dl 0
loc 27
ccs 11
cts 12
cp 0.9167
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A weatherActionPost() 0 15 4
1
<?php
2
3
namespace Asti\Api;
4
5
use Anax\Commons\ContainerInjectableInterface;
6
use Anax\Commons\ContainerInjectableTrait;
7
use Asti\Weather\WeatherService;
8
9
/**
10
 * A test controller to show off using a model.
11
 */
12
class WeatherApiController implements ContainerInjectableInterface
13
{
14
    use ContainerInjectableTrait;
15
16
    /**
17
     * function checks if input is an ip address and if so, if it's PIv4 or Ipv6
18
     */
19
//    public function indexAction()
20
//    {
21
22
//    }
23
24 1
    public function weatherActionPost() : array
25
    {
26 1
        $request = $this->di->get("request");
27 1
        $geoipService = $this->di->get("location");
28 1
        $weatherService = $this->di->get("weather");
29 1
        $ipAdress = $request->getPost("ipCheck");
30 1
        $res = $geoipService->curlIpApi($ipAdress);
31
32 1
        if (isset($res["Message"])) {
33
            return [$res];
34
        }
35 1
        if (in_array("Prognos", $request->getPost())) {
36 1
            return [$weatherService->curlWeatherApi($res[0]["Longitude"], $res[0]["Latitude"])];
37 1
        } elseif ((in_array("Äldre data", $request->getPost()))) {
38 1
            return [$weatherService->curlOldWeatherApi($res[0]["Longitude"], $res[0]["Latitude"])];
39
        }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return array. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
40
    }
41
}
42