Issues (1256)

helpers/BaseHelper.php (1 issue)

1
<?php
2
3
namespace app\helpers;
4
5
/**
6
 * Class BaseHelper
7
 *
8
 * @package app\helpers
9
 */
10
class BaseHelper
11
{
12
    /**
13
     * @param string $date
14
     * @param string $format
15
     *
16
     * @return string
17
     */
18
    public static function getDateAt(string $date, string $format = 'd.m.Y H:i:s'): string
19
    {
20
        $inDateTime = new \DateTime($date);
21
22
        return date($format, $inDateTime->getTimestamp());
23
    }
24
25
    /**
26
     * @return string
27
     */
28
    public static function ip_address()
29
    {
30
        $fields = array('HTTP_CLIENT_IP', 'HTTP_X_REAL_IP', 'HTTP_X_FORWARDED_FOR', 'REMOTE_ADDR');
31
32
        $ip = "0.0.0.0";
33
        foreach($fields as $k)
34
        {
35
            if(!empty($_SERVER[$k]) && ip2long($_SERVER[$k]) != false)
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing ip2long($_SERVER[$k]) of type integer to the boolean false. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
36
            {
37
                $ip = $_SERVER[$k];
38
            }
39
        }
40
41
        return $ip;
42
    }
43
}
44