OpenStreetMapReverse   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 11
dl 0
loc 27
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A osmCheckCoordinates() 0 11 1
1
<?php
2
3
namespace KW\Models;
4
5
class OpenStreetMapReverse
6
{
7
    /**
8
     * Return adress from coordinates
9
     *
10
     * @return array
11
     */
12
13 7
    public function __construct($di)
14
    {
15 7
        $this->di = $di;
0 ignored issues
show
Bug Best Practice introduced by
The property di does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
16 7
        $this->accessKey = $this->di->get("apikeys")["config"]["openStreetMap"];
0 ignored issues
show
Bug Best Practice introduced by
The property accessKey does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
17 7
        $this->baseUrl = "https://nominatim.openstreetmap.org/reverse?";
0 ignored issues
show
Bug Best Practice introduced by
The property baseUrl does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
18 7
    }
19
20
21 2
    public function osmCheckCoordinates($longitude, $latitude)
22
    {
23 2
        $url = ($this->baseUrl . $this->accessKey . "&format=json&lat=" . $latitude . "&lon=" . $longitude . "&addressdetails=1");
24 2
        $cURL = new CURL;
25 2
        $result = $cURL->req($url);
26 2
        $result = json_decode($result);
27
28 2
        $country = $result->address->country ?? "";
29 2
        $town = $result->address->town ?? "";
30
31 2
        return array($country, $town);
32
    }
33
}
34