JSON.php
Function decode
has a Cognitive Complexity of 88 (exceeds 5 allowed). Consider refactoring. Open
Open
function decode($str)
{
$str = $this->reduce_string($str);
switch (strtolower($str)) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method decode
has 171 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function decode($str)
{
$str = $this->reduce_string($str);
switch (strtolower($str)) {
File JSON.php
has 394 lines of code (exceeds 250 allowed). Consider refactoring. Open
Open
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Converts to and from JSON format.
Method encode
has 121 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function encode($var)
{
switch (gettype($var)) {
case 'boolean':
return $var ? 'true' : 'false';
Function encode
has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring. Open
Open
function encode($var)
{
switch (gettype($var)) {
case 'boolean':
return $var ? 'true' : 'false';
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Consider simplifying this complex logical expression. Open
Open
if (($c == $strlen_chrs) || (($chrs{$c} == ',') && ($top['what'] == SERVICES_JSON_SLICE))) {
// found a comma that is not inside a string, array, etc.,
// OR we've reached the end of the character list
$slice = substr($chrs, $top['where'], ($c - $top['where']));
array_push($stk, array('what' => SERVICES_JSON_SLICE, 'where' => ($c + 1), 'delim' => false));
Avoid deeply nested control flow statements. Open
Open
if (reset($stk) == SERVICES_JSON_IN_ARR) {
// we are in an array, so just push an element onto the stack
array_push($arr, $this->decode($slice));
} elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
Avoid deeply nested control flow statements. Open
Open
if (($delim == '"' && $substr_chrs_c_2 != '\\\'') ||
($delim == "'" && $substr_chrs_c_2 != '\\"')) {
$utf8 .= $chrs{++$c};
}
Avoid deeply nested control flow statements. Open
Open
for ($i = $top['where']; $i <= $c; ++$i)
$chrs = substr_replace($chrs, ' ', $i, 1);
Method Services_JSON_Error
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
function Services_JSON_Error($message = 'unknown error', $code = null,
$mode = null, $options = null, $userinfo = null)
Method Services_JSON_Error
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
function Services_JSON_Error($message = 'unknown error', $code = null,
$mode = null, $options = null, $userinfo = null)
Avoid too many return
statements within this method. Open
Open
return ($this->use & SERVICES_JSON_SUPPRESS_ERRORS)
? 'null'
: new Services_JSON_Error(gettype($var)." can not be encoded as JSON string");
Avoid too many return
statements within this method. Open
Open
return '{' . join(',', $properties) . '}';
Avoid too many return
statements within this method. Open
Open
return $utf8;
Avoid too many return
statements within this method. Open
Open
return $obj;
Avoid too many return
statements within this method. Open
Open
return '{' . join(',', $properties) . '}';
Avoid too many return
statements within this method. Open
Open
return $property;
Avoid too many return
statements within this method. Open
Open
return $arr;
Avoid too many return
statements within this method. Open
Open
return '';
Avoid too many return
statements within this method. Open
Open
return $element;
Avoid too many return
statements within this method. Open
Open
return '';
Avoid too many return
statements within this method. Open
Open
return $property;
Avoid too many return
statements within this method. Open
Open
return $arr;
Avoid too many return
statements within this method. Open
Open
return '[' . join(',', $elements) . ']';
Avoid too many return
statements within this method. Open
Open
return $obj;
Avoid too many return
statements within this method. Open
Open
return '"'.$ascii.'"';