APIMockController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 12
c 2
b 0
f 0
dl 0
loc 30
ccs 11
cts 11
cp 1
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A indexAction() 0 6 2
A darkSkyMockAction() 0 8 3
1
<?php
2
3
namespace Linder\Controller;
4
5
use Anax\Commons\ContainerInjectableInterface;
6
use Anax\Commons\ContainerInjectableTrait;
7
8
/**
9
 * A controller that handles a get request
10
 * uses a model and returns a Json.
11
 */
12
class APIMockController implements ContainerInjectableInterface
13
{
14
    use ContainerInjectableTrait;
15
16
    /**
17
     * Main index page, serves as the ip mock
18
     * @return Array
19
     */
20 1
    public function indexAction() : array
21
    {
22 1
        $ip = $this->di->request->getGet("ip") ?: $this->di->request->getServer("REMOTE_ADDR");
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...
23 1
        $ipMock = new \Linder\Mock\IpVerifierMock();
24
        return [
25 1
            $ipMock->getJson($ip)
26
        ];
27
    }
28
29
    /**
30
     * Darksky mock route which mocks the return
31
     * type from the external darksky api
32
     * @return Array
33
     */
34 1
    public function darkSkyMockAction() : Array
35
    {
36 1
        $darksky = new \Linder\Mock\DarkSkyMock();
37 1
        $url = $this->di->request->getCurrentUrl();
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...
38 1
        $res = (strpos($url, "?exclude=currently,flags") || $this->di->request->getGet("type") == "past") ?
39 1
            $darksky->getWeatherPast() :
40 1
            $darksky->getWeatherComing();
41 1
        return $res;
42
    }
43
}
44