WeatherApiController::forecastAction()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 12
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace H4MSK1\Weather;
4
5
use Anax\Commons\ContainerInjectableInterface;
6
use Anax\Commons\ContainerInjectableTrait;
7
use H4MSK1\IpLocator\IpLocator;
8
9
class WeatherApiController implements ContainerInjectableInterface
10
{
11
    use ContainerInjectableTrait;
12
13
    public function indexAction()
14
    {
15
        $page = $this->di->get('page');
16
        $page->add('anax/weather/api');
17
18
        return $page->render([
19
            'title' => 'Weather',
20
        ]);
21
    }
22
23
    public function forecastAction()
24
    {
25
        $request = $this->di->get('request');
26
        $curl = $this->di->get('curl');
27
28
        $ipAddr = (new IpLocator($request->getGet('ip')))->locateIp();
29
        $type = $request->getGet('type');
30
        $coords = $request->getGet('coords');
31
        $result = (new Weather)->processRequest($ipAddr, $coords, $type, $curl);
32
        unset($result['map']);
33
34
        return [$result];
35
    }
36
}
37