EmailAFriendExtension::get_ip_user()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 0
1
<?php
2
3
class EmailAFriendExtension extends SiteTreeExtension
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...
4
{
5
6
    /**
7
     * @var String
8
     */
9
    private static $sender_email_address = "";
0 ignored issues
show
Unused Code introduced by
The property $sender_email_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...
10
11
    /**
12
     * @var String
13
     */
14
    private static $sender_name = "";
0 ignored issues
show
Unused Code introduced by
The property $sender_name 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...
15
16
    /**
17
     * @var String
18
     */
19
    private static $default_message = "";
0 ignored issues
show
Unused Code introduced by
The property $default_message 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...
20
21
    /**
22
     * @var Int
23
     */
24
    private static $max_message_phour_pip = 1;
0 ignored issues
show
Unused Code introduced by
The property $max_message_phour_pip 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...
25
26
    /**
27
     * @var String
28
     */
29
    private static $mail_subject = "";
0 ignored issues
show
Unused Code introduced by
The property $mail_subject 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...
30
31
    /**
32
     *
33
     * @return String
34
     */
35
    public static function get_ip_user()
0 ignored issues
show
Coding Style introduced by
get_ip_user uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
36
    {
37
        if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
38
            return $_SERVER['HTTP_X_FORWARDED_FOR'];
39
        } else {
40
            return isset($_SERVER['HTTP_CLIENT_IP']) ? $_SERVER['HTTP_CLIENT_IP'] : $_SERVER['REMOTE_ADDR'];
41
        }
42
    }
43
}
44