getIP()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
/**
4
 * this is a very basic class with as its sole purpose providing
5
 * the country of the customer.
6
 *
7
 *
8
 */
9
class EcommerceCountry_VisitorCountryProviderCloudFlare extends Object implements EcommerceGEOipProvider
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
10
{
11
12
    /**
13
     *
14
     * @var string
15
     */
16
    private static $forced_country_code = "";
0 ignored issues
show
Unused Code introduced by
The property $forced_country_code is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
17
18
    /**
19
     *
20
     * @var string
21
     */
22
    private static $forced_ip_address = "";
0 ignored issues
show
Unused Code introduced by
The property $forced_ip_address is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
23
24
    /**
25
     *
26
     * @return String (Country Code - e.g. NZ, AU, or AF)
0 ignored issues
show
Documentation introduced by
Should the return type not be array|integer|double|string|boolean?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
27
     */
28
    public function getCountry()
29
    {
30
        if ($code = Config::inst()->get("EcommerceCountry_VisitorCountryProviderCloudFlare", "forced_country_code")) {
31
            return $code;
32
        }
33
        return CloudFlareGeoip::visitor_country();
34
    }
35
36
    /**
37
     *
38
     *
39
     * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be array|integer|double|string|boolean?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
40
     */
41
    public function getIP()
42
    {
43
        if ($ip = Config::inst()->get("EcommerceCountry_VisitorCountryProviderCloudFlare", "forced_ip_address")) {
44
            return $ip;
45
        }
46
        return CloudFlareGeoip::get_remote_address();
47
    }
48
}
49