GeoTag   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 52
ccs 15
cts 15
cp 1
rs 10
wmc 9

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 8 4
A getAllData() 0 11 5
1
<?php
2
3
namespace Pamo\GeoTag;
4
5
use Pamo\MultiCurl\MultiCurl;
6
7
/**
8
 * GeoTag
9
 */
10
class GeoTag
11
{
12
    /**
13
     * @var object $multiCurl tool.
14
     * @var string $baseAddress for the API.
15
     * @var string $apiKey for authentication.
16
     * @var array $allData to store Geotag data.
17
     */
18
    private $multiCurl;
19
    private $baseAddress;
20
    private $apiKey;
21
    private $allData;
22
23
24
25
    /**
26
     * Geotag current place
27
     *
28
     * @param string $baseAddress for the API.
29
     * @param string $apiKey for authentication.
30
     *
31
     */
32 1
    public function init()
33
    {
34 1
        $this->multiCurl = new MultiCurl();
35 1
        $filename = ANAX_INSTALL_PATH . "/config/api.php";
36 1
        $api =  file_exists($filename) ? require $filename : null;
37 1
        $this->baseAddress = $api ? $api["url"]["opencagedata"] : getenv("API_URL_OPENCAGEDATA");
38 1
        $this->apiKey = $api ? $api["key"]["opencagedata"] : getenv("API_KEY_OPENCAGEDATA");
39 1
        $this->allData = [];
40 1
    }
41
42
43
44
    /**
45
     * Valide an IP Address.
46
     *
47
     * @param string $ipAddress is the IP Address to validate.
48
     *
49
     * @return object
50
     */
51 1
    public function getAllData(string $search = null) : array
52
    {
53 1
        $url = ["$this->baseAddress/geocode/v1/json?q=" . urlencode($search) . "&key=$this->apiKey"];
54 1
        $data = $this->multiCurl->get($url);
55 1
        $data = count($data) > 0 ? $data[0] : null;
56
57 1
        if ($data && array_key_exists("results", $data) && !empty($data["results"][0])) {
58 1
            $this->allData = $data["results"][0];
59
        }
60
61 1
        return $this->allData;
62
    }
63
}
64