| Conditions | 40 |
| Paths | 392 |
| Total Lines | 156 |
| Code Lines | 86 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 115 | function _safe_unserialize($str) |
||
| 116 | { |
||
| 117 | if(strlen($str) > MAX_SERIALIZED_INPUT_LENGTH) |
||
| 118 | { |
||
| 119 | throw new \Exception('safe_unserialize: input exceeds ' . MAX_SERIALIZED_INPUT_LENGTH); |
||
| 120 | } |
||
| 121 | |||
| 122 | if(empty($str) || !is_string($str)) |
||
| 123 | { |
||
| 124 | return false; |
||
| 125 | } |
||
| 126 | |||
| 127 | $stack = array(); |
||
| 128 | $expected = array(); |
||
| 129 | $state = 0; |
||
| 130 | |||
| 131 | while($state != 1) |
||
| 132 | { |
||
| 133 | $type = isset($str[0]) ? $str[0] : ''; |
||
| 134 | |||
| 135 | if($type == '}') |
||
| 136 | { |
||
| 137 | $str = substr($str, 1); |
||
| 138 | } |
||
| 139 | else if($type == 'N' && $str[1] == ';') |
||
| 140 | { |
||
| 141 | $value = null; |
||
| 142 | $str = substr($str, 2); |
||
| 143 | } |
||
| 144 | else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) |
||
| 145 | { |
||
| 146 | $value = $matches[1] == '1' ? true : false; |
||
| 147 | $str = substr($str, 4); |
||
| 148 | } |
||
| 149 | else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) |
||
| 150 | { |
||
| 151 | $value = (int)$matches[1]; |
||
| 152 | $str = $matches[2]; |
||
| 153 | } |
||
| 154 | else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) |
||
| 155 | { |
||
| 156 | $value = (float)$matches[1]; |
||
| 157 | $str = $matches[3]; |
||
| 158 | } |
||
| 159 | else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";') |
||
| 160 | { |
||
| 161 | $value = substr($matches[2], 0, (int)$matches[1]); |
||
| 162 | $str = substr($matches[2], (int)$matches[1] + 2); |
||
| 163 | } |
||
| 164 | else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches) && $matches[1] < MAX_SERIALIZED_ARRAY_LENGTH) |
||
| 165 | { |
||
| 166 | $expectedLength = (int)$matches[1]; |
||
| 167 | $str = $matches[2]; |
||
| 168 | } |
||
| 169 | else if($type == 'O') |
||
| 170 | { |
||
| 171 | throw new \Exception('safe_unserialize: objects not supported'); |
||
| 172 | } |
||
| 173 | else |
||
| 174 | { |
||
| 175 | throw new \Exception('safe_unserialize: unknown/malformed type: '.$type); |
||
| 176 | } |
||
| 177 | |||
| 178 | switch($state) |
||
| 179 | { |
||
| 180 | case 3: // in array, expecting value or another array |
||
| 181 | if($type == 'a') |
||
| 182 | { |
||
| 183 | if(count($stack) >= MAX_SERIALIZED_ARRAY_DEPTH) |
||
| 184 | { |
||
| 185 | throw new \Exception('safe_unserialize: array nesting exceeds ' . MAX_SERIALIZED_ARRAY_DEPTH); |
||
| 186 | } |
||
| 187 | |||
| 188 | $stack[] = &$list; |
||
| 189 | $list[$key] = array(); |
||
| 190 | $list = &$list[$key]; |
||
| 191 | $expected[] = $expectedLength; |
||
| 192 | $state = 2; |
||
| 193 | break; |
||
| 194 | } |
||
| 195 | if($type != '}') |
||
| 196 | { |
||
| 197 | $list[$key] = $value; |
||
| 198 | $state = 2; |
||
| 199 | break; |
||
| 200 | } |
||
| 201 | |||
| 202 | throw new \Exception('safe_unserialize: missing array value'); |
||
| 203 | |||
| 204 | case 2: // in array, expecting end of array or a key |
||
| 205 | if($type == '}') |
||
| 206 | { |
||
| 207 | if(count($list) < end($expected)) |
||
| 208 | { |
||
| 209 | throw new \Exception('safe_unserialize: array size less than expected ' . $expected[0]); |
||
| 210 | } |
||
| 211 | |||
| 212 | unset($list); |
||
| 213 | $list = &$stack[count($stack)-1]; |
||
| 214 | array_pop($stack); |
||
| 215 | |||
| 216 | // go to terminal state if we're at the end of the root array |
||
| 217 | array_pop($expected); |
||
| 218 | if(count($expected) == 0) { |
||
| 219 | $state = 1; |
||
| 220 | } |
||
| 221 | break; |
||
| 222 | } |
||
| 223 | if($type == 'i' || $type == 's') |
||
| 224 | { |
||
| 225 | if(count($list) >= MAX_SERIALIZED_ARRAY_LENGTH) |
||
| 226 | { |
||
| 227 | throw new \Exception('safe_unserialize: array size exceeds ' . MAX_SERIALIZED_ARRAY_LENGTH); |
||
| 228 | } |
||
| 229 | if(count($list) >= end($expected)) |
||
| 230 | { |
||
| 231 | throw new \Exception('safe_unserialize: array size exceeds expected length'); |
||
| 232 | } |
||
| 233 | |||
| 234 | $key = $value; |
||
| 235 | $state = 3; |
||
| 236 | break; |
||
| 237 | } |
||
| 238 | |||
| 239 | throw new \Exception('safe_unserialize: illegal array index type'); |
||
| 240 | |||
| 241 | case 0: // expecting array or value |
||
| 242 | if($type == 'a') |
||
| 243 | { |
||
| 244 | if(count($stack) >= MAX_SERIALIZED_ARRAY_DEPTH) |
||
| 245 | { |
||
| 246 | throw new \Exception('safe_unserialize: array nesting exceeds ' . MAX_SERIALIZED_ARRAY_DEPTH); |
||
| 247 | } |
||
| 248 | |||
| 249 | $data = array(); |
||
| 250 | $list = &$data; |
||
| 251 | $expected[] = $expectedLength; |
||
| 252 | $state = 2; |
||
| 253 | break; |
||
| 254 | } |
||
| 255 | if($type != '}') |
||
| 256 | { |
||
| 257 | $data = $value; |
||
| 258 | $state = 1; |
||
| 259 | break; |
||
| 260 | } |
||
| 261 | |||
| 262 | throw new \Exception('safe_unserialize: not in array'); |
||
| 263 | } |
||
| 264 | } |
||
| 265 | |||
| 266 | if(!empty($str)) |
||
| 267 | { |
||
| 268 | throw new \Exception('safe_unserialize: trailing data in input'); |
||
| 269 | } |
||
| 270 | return $data; |
||
| 271 | } |
||
| 303 | ?> |
||
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths