GeoTag   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 23
ccs 0
cts 11
cp 0
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A getGeoInfo() 0 14 1
1
<?php
2
3
namespace Jiad\Modules;
4
5
use Anax\Session\SessionInterface;
6
7
/**
8
 * REM Server using session to store information.
9
 */
10
class GeoTag
11
{
12
    /**
13
     * Get geo information about an IP address.
14
     *
15
     * @param string $ip string with IP to fetch geoinformation about.
16
     *
17
     * @return self
18
     */
19
    public function getGeoInfo(string $ip) : object
20
    {
21
        $key = require(ANAX_INSTALL_PATH . "/config/api_key.php");
22
        $api_key = $key["ipstack"];
23
        $url = "http://api.ipstack.com/$ip?access_key=$api_key";
24
        $ch = curl_init();
25
26
        curl_setopt($ch, CURLOPT_URL, $url);
0 ignored issues
show
Bug introduced by
It seems like $ch can also be of type false; however, parameter $ch of curl_setopt() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

26
        curl_setopt(/** @scrutinizer ignore-type */ $ch, CURLOPT_URL, $url);
Loading history...
27
        curl_setopt($ch, CURLOPT_HEADER, 0);
28
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
29
30
        $info = curl_exec($ch);
0 ignored issues
show
Bug introduced by
It seems like $ch can also be of type false; however, parameter $ch of curl_exec() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

30
        $info = curl_exec(/** @scrutinizer ignore-type */ $ch);
Loading history...
31
        curl_close($ch);
0 ignored issues
show
Bug introduced by
It seems like $ch can also be of type false; however, parameter $ch of curl_close() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

31
        curl_close(/** @scrutinizer ignore-type */ $ch);
Loading history...
32
        return json_decode($info);
33
    }
34
}
35