Weather   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 8

1 Method

Rating   Name   Duplication   Size   Complexity  
B processRequest() 0 32 8
1
<?php
2
3
namespace H4MSK1\Weather;
4
5
use H4MSK1\Curl\Api;
6
use H4MSK1\Map\OpenLayers;
7
8
class Weather
9
{
10
    public function processRequest($iplocation, $coords, $type, Api $curl)
11
    {
12
        $payload = ['weather' => [], 'map' => null];
13
        $lat = 0;
14
        $lng = 0;
15
16
        if (empty($coords) && $iplocation['ip'] === 'Invalid') {
17
            $payload['error'] = 'Missing input data';
18
            return $payload;
19
        }
20
21
        if (empty($coords)) {
22
            if (isset($iplocation['latitude']) && isset($iplocation['longitude'])) {
23
                $lat = $iplocation['latitude'];
24
                $lng = $iplocation['longitude'];
25
            } else {
26
                $payload['error'] = 'Ip not valid';
27
            }
28
        } else {
29
            if (strpos($coords, ',') !== false) {
30
                list($lat, $lng) = explode(',', $coords);
31
            } else {
32
                $payload['error'] = 'Coordinates not valid';
33
            }
34
        }
35
36
        if (! isset($payload['error'])) {
37
            $payload['weather'] = $curl->getWeatherData($lat, $lng, $type);
38
            $payload['map'] = (new OpenLayers)->getHtml($lat, $lng);
39
        }
40
41
        return $payload;
42
    }
43
}
44