Issues (36)

src/IPGeo/IPStack.php (4 issues)

1
<?php
2
3
/**
4
 * Ipstack
5
 */
6
7
namespace Hepa19\IPGeo;
8
9
/**
10
 * Get IP data from ipstack
11
 *
12
 */
13
class IPStack
14
{
15
    protected $curl;
16
    protected $baseUrl;
17
    private $apiKey;
18
    private $url;
19
20
21
    /**
22
     * Create complete url to curl
23
     *
24
     * @var string $ip   IP address to look up
25
     * @var string $baseUrl   API base URL
26
     * @var string $apiKey   API key for ipstack usage
27
     * @var string $url   Complete url to curl
28
     *
29
     * @return void.
0 ignored issues
show
Documentation Bug introduced by
The doc comment void. at position 0 could not be parsed: Unknown type name 'void.' at position 0 in void..
Loading history...
30
     */
31 11
    public function setUrl($ip)
32
    {
33 11
        $this->url = $this->baseUrl . $ip . "?access_key=" . $this->apiKey;
34 11
    }
35
36
37
38
    /**
39
     * Set API key
40
     *
41
     * @var string $apiKey   API key for weather service
42
     *
43
     * @return void.
0 ignored issues
show
Documentation Bug introduced by
The doc comment void. at position 0 could not be parsed: Unknown type name 'void.' at position 0 in void..
Loading history...
44
     */
45
    public function setApiKey($apiKey)
46
    {
47
        $this->apiKey = $apiKey;
48
    }
49
50
51
    /**
52
     * Set Base URL
53
     *
54
     * @var string $baseUrl   URL for weather service
55
     *
56
     * @return void.
0 ignored issues
show
Documentation Bug introduced by
The doc comment void. at position 0 could not be parsed: Unknown type name 'void.' at position 0 in void..
Loading history...
57
     */
58
    public function setBaseUrl(String $baseUrl)
59
    {
60
        $this->baseUrl = $baseUrl;
61
    }
62
63
64
65
    /**
66
     * Set curl model
67
     *
68
     * @var string $curl   Curl model
69
     *
70
     * @return void.
0 ignored issues
show
Documentation Bug introduced by
The doc comment void. at position 0 could not be parsed: Unknown type name 'void.' at position 0 in void..
Loading history...
71
     */
72
    public function setCurl(Object $curl)
73
    {
74
        $this->curl = $curl;
75
    }
76
77
78
79
80
    /**
81
     * Get data from ipstack
82
     *
83
     * @var string $url   Complete url to curl
84
     *
85
     * @return array $res Result from ipstack API.
86
     */
87
    public function getData()
88
    {
89
        $res = $this->curl->getData($this->url);
90
91
        $res = [
92
            "city" => $res["city"] ?? null,
93
            "country_name" => $res["country_name"] ?? null,
94
            "longitude" => $res["longitude"] ?? null,
95
            "latitude" => $res["latitude"] ?? null,
96
        ];
97
98
        return $res;
99
    }
100
}
101