Issues (1919)

Security Analysis    not enabled

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.

lib/Ajde/Object/Magic.php (4 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
abstract class Ajde_Object_Magic extends Ajde_Object
4
{
5
    protected $_data = [];
6
7
    final public function __call($method, $arguments)
8
    {
9
        $prefix = strtolower(substr($method, 0, 3));
10
        $key = substr($method, 3);
11
        $key = strtolower(substr($key, 0, 1)).substr($key, 1);
12
        switch ($prefix) {
13
            case 'get':
14 View Code Duplication
                if ($this->has($key)) {
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...
15
                    return $this->get($key);
16
                } else {
17
                    if (!method_exists($this, '__fallback')) {
18
                        throw new Ajde_Exception("Property '$key' not set in class ".get_class($this)." when calling get('$key')",
19
                            90007);
20
                    }
21
                }
22
                break;
23
            case 'set':
24
                return $this->set($key, $arguments[0]);
25
                break;
0 ignored issues
show
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
26
            case 'has':
27
                return $this->has($key);
28
                break;
0 ignored issues
show
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
29
        }
30
        if (method_exists($this, '__fallback')) {
31
            return call_user_func_array([$this, '__fallback'], [$method, $arguments]);
32
        }
33
        throw new Ajde_Exception('Call to undefined method '.get_class($this)."::$method()", 90006);
34
    }
35
36
    /**
37
     * TODO.
38
     *
39
     * @param string $key
40
     * @param mixed  $value
41
     */
42
    public function set($key, $value)
43
    {
44
        $this->_set($key, $value);
45
    }
46
47
    /**
48
     * TODO.
49
     *
50
     * @param string $key
51
     * @param mixed  $value
52
     */
53
    protected function _set($key, $value)
54
    {
55
        if (substr_count($key, '.')) {
56
            Ajde_Core_Array::set($this->_data, $key, $value);
57
        } else {
58
            $this->_data[$key] = $value;
59
        }
60
    }
61
62
    public function remove($key)
63
    {
64
        unset($this->_data[$key]);
65
    }
66
67
    public function get($key)
68
    {
69 View Code Duplication
        if ($this->has($key)) {
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...
70
            return $this->_get($key);
71
        } else {
72
            throw new Ajde_Exception("Parameter '$key' not set in class ".get_class($this)." when calling get('$key')",
73
                90007);
74
        }
75
    }
76
77
    protected function _get($key)
78
    {
79
        if (substr_count($key, '.')) {
80
            return Ajde_Core_Array::get($this->_data, $key);
81
        }
82
83
        return $this->_data[$key];
84
    }
85
86
    public function has($key)
87
    {
88
        $exist = array_key_exists($key, $this->_data);
89
90
        if ($exist === false) {
91
            $exist = !is_null(Ajde_Core_Array::get($this->_data, $key));
92
        }
93
94
        return (bool) $exist;
95
    }
96
97
    public function isEmpty($key)
98
    {
99
        $value = $this->get($key);
100
101
        return $value instanceof Ajde_Model ?
102
            !$value->hasLoaded() :
103
            empty($value);
104
    }
105
106
    public function hasEmpty($key)
107
    {
108
        return $this->has($key) && $this->isEmpty($key);
109
    }
110
111
    public function hasNotEmpty($key)
112
    {
113
        if ($this->has($key)) {
114
            return !$this->isEmpty($key);
115
        }
116
117
        return false;
118
    }
119
120
    public function reset()
121
    {
122
        $this->_data = [];
123
    }
124
125
    final public function values()
126
    {
127
        return $this->_data;
128
    }
129
130
    final public function merge($key, array $value)
131
    {
132
        if (!$this->has($key)) {
133
            $this->set($key, []);
134
        }
135
136
        $this->set($key, Ajde_Core_Array::mergeRecursive($this->get($key), $value));
137
    }
138
139
    final public function valuesAsSingleDimensionArray()
140
    {
141
        $array = [];
142
        foreach ($this->_data as $k => $item) {
143
            if (is_string($item)) {
144
                $array[$k] = $item;
145
            } else {
146
                if (is_array($item)) {
147
                    $array[$k] = serialize($item);
148
                } else {
149
                    if ($item instanceof self) {
150
                        $array[$k] = serialize($item->valuesAsSingleDimensionArray());
151
                    } else {
152
                        if (is_object($item)) {
153
                            $array[$k] = serialize($item);
154
                        }
155
                    }
156
                }
157
            }
158
        }
159
160
        return $array;
161
    }
162
163
    /**
164
     * Translates a camel case string into a string with underscores (e.g. firstName -&gt; first_name).
165
     *
166
     * @see http://www.paulferrett.com/2009/php-camel-case-functions/
167
     *
168
     * @param string $str String in camel case format
169
     *
170
     * @return string $str Translated into underscore format
171
     */
172
    public static function fromCamelCase($str)
173
    {
174
        $str[0] = strtolower($str[0]);
175
        $func = create_function('$c', 'return "_" . strtolower($c[1]);');
176
177
        return preg_replace_callback('/([A-Z])/', $func, $str);
178
    }
179
180
    /**
181
     * Translates a string with underscores into camel case (e.g. first_name -&gt; firstName).
182
     *
183
     * @see http://www.paulferrett.com/2009/php-camel-case-functions/
184
     *
185
     * @param string $str                   String in underscore format
186
     * @param bool   $capitalise_first_char If true, capitalise the first char in $str
187
     *
188
     * @return string $str translated into camel caps
189
     */
190
    public static function toCamelCase($str, $capitalise_first_char = false)
191
    {
192
        if ($capitalise_first_char) {
193
            $str[0] = strtoupper($str[0]);
194
        }
195
        $func = create_function('$c', 'return strtoupper($c[1]);');
196
197
        return preg_replace_callback('/_([a-z])/', $func, $str);
198
    }
199
200
    public static function classnameToUppercase($classname)
201
    {
202
        return str_replace(' ', '_', ucwords(str_replace('_', ' ', $classname)));
203
    }
204
}
205