Issues (59)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/helpers.php (12 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
if (!function_exists('get_user_timezone')) {
4
    function get_user_timezone()
0 ignored issues
show
function get_user_timezone() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
5
    {
6
        return 'UTC';
7
    }
8
}
9
10
if (!function_exists('get_request_ip')) {
11
    function get_request_ip()
0 ignored issues
show
function get_request_ip() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
get_request_ip 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...
12
    {
13
        if (isset($_SERVER['X_FORWARDED_FOR'])) {
14
            return $_SERVER['X_FORWARDED_FOR'];
15
        } elseif (isset($_SERVER['CLIENT_IP'])) {
16
            return $_SERVER['CLIENT_IP'];
17
        }
18
19
        return $_SERVER['REMOTE_ADDR'];
20
    }
21
}
22
23
24
if (!function_exists('to_name_value')) {
25
    function to_name_value($array, $keys = null)
0 ignored issues
show
function to_name_value() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
26
    {
27
        $data = [];
28
        foreach ($array as $name => $value) {
29
            $row = ['name' => $name, 'value' => $value];
30
            if (isset($keys)) $row = array_merge($row, $keys);
31
            array_push($data, $row);
32
        }
33
34
        return $data;
35
    }
36
}
37
38
if (!function_exists('sorting_by_key')) {
39
    /**
40
     * Sorting callable helper
41
     *
42
     * @param string $key
43
     * @param string $order
44
     *
45
     * @return Closure
46
     */
47
    function sorting_by_key($key, $order = 'ASC')
0 ignored issues
show
function sorting_by_key() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
48
    {
49
        return function ($a, $b) use ($key, $order) {
50
            if ($a[$key] === $b[$key]) {
51
                return 0;
52
            }
53
54
            $value = $a[$key] < $b[$key] ? -1 : 1;
55
            if ($order === 'DESC') {
56
                $value *= -1;
57
            }
58
59
            return $value;
60
        };
61
    }
62
}
63
64
if (!function_exists('get_columns_flat_at')) {
65
    /**
66
     * Get all the columns name in the given level
67
     *
68
     * @param array $columns
69
     * @param int $level
70
     *
71
     * @return array
72
     */
73
    function get_columns_flat_at(array $columns, $level = 0)
0 ignored issues
show
function get_columns_flat_at() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
74
    {
75
        $names = [];
76
77
        foreach ($columns as $column) {
78
            $parts = explode('.', $column);
79
80
            if (isset($parts[$level])) {
81
                $names[] = $parts[$level];
82
            }
83
        }
84
85
        return $names;
86
    }
87
}
88
89
if (!function_exists('get_csv_flat_columns')) {
90
    /**
91
     * Gets a CSV flat columns list from the given array
92
     *
93
     * @param array $columns
94
     * @param null $prefix
95
     *
96
     * @return string
97
     */
98
    function get_csv_flat_columns(array $columns, $prefix = null)
0 ignored issues
show
function get_csv_flat_columns() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
99
    {
100
        $flatColumns = [];
101
        $prefix = $prefix === null ? '' : $prefix . '.';
102
103
        foreach ($columns as $key => $value) {
104
            if (is_array($value)) {
105
                $value = get_csv_flat_columns($value, $prefix . $key);
106
            } else {
107
                $value = $prefix . $key;
108
            }
109
110
            $flatColumns[] = $value;
111
        }
112
113
        return implode(',', $flatColumns);
114
    }
115
}
116
117
if (!function_exists('get_array_flat_columns')) {
118
    /**
119
     * Gets an array flat columns list from the given array
120
     *
121
     * @param $columns
122
     *
123
     * @return array
124
     */
125
    function get_array_flat_columns($columns)
0 ignored issues
show
function get_array_flat_columns() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
126
    {
127
        // TODO: make sure array is passed???
128
        return explode(',', get_csv_flat_columns($columns ?: []));
129
    }
130
}
131
if (!function_exists('get_unflat_columns')) {
132
    /**
133
     * Gets the unflat version of flat (dot-notated) column list
134
     *
135
     * @param string|array $columns
136
     *
137
     * @return array
138
     */
139
    function get_unflat_columns($columns)
0 ignored issues
show
function get_unflat_columns() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
140
    {
141
        $names = [];
142
143
        if (!is_array($columns)) {
144
            $columns = explode(',', $columns);
145
        }
146
147
        foreach ($columns as $column) {
148
            $parts = explode('.', $column, 2);
149
150
            if (isset($parts[0])) {
151 View Code Duplication
                if (!isset($names[$parts[0]])) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
152
                    $names[$parts[0]] = null;
153
                }
154
155
                if (isset($parts[1])) {
156 View Code Duplication
                    if ($names[$parts[0]] === null) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
157
                        $names[$parts[0]] = [];
158
                    }
159
160
                    $child = get_unflat_columns($parts[1]);
161
                    $names[$parts[0]][key($child)] = current($child);
162
                };
163
            }
164
        }
165
166
        return $names;
167
    }
168
}
169