NameToGeo::getGeo()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 0
loc 13
ccs 7
cts 7
cp 1
crap 1
rs 10
c 1
b 1
f 0
1
<?php
2
3
namespace Anax\OpenWeather;
4
5
6
/**
7
 * A model class retrievieng data from an external server.
8
 *
9
 * @SuppressWarnings(PHPMD.ShortVariable)
10
 */
11
class NameToGeo
12
{
13
14 2
    public function getGeo($place) : array
15
    {
16
17 2
        $url = "https://nominatim.openstreetmap.org/search.php?q=$place&polygon_geojson=1&format=jsonv2";
18 2
        $opts = array('http'=>array('header'=>"User-Agent: QingPanCleverAddressScript 3.7.6\r\n"));
19 2
        $context = stream_context_create($opts);
20
        // Open the file using the HTTP headers set above
21 2
        $file = file_get_contents($url, false, $context);
22
23
24 2
        $res = json_decode($file);
25
        //var_dump($res);
26 2
        return $res;
27
    }
28
}
29