Function stripComments
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
public static function stripComments( $json ) {
// Ensure we have a string
$str = (string)$json;
$buffer = '';
$maxLen = strlen( $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
Function parse
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
public static function parse( $value, $options = 0 ) {
if ( $options & self::STRIP_COMMENTS ) {
$value = self::stripComments( $value );
}
$assoc = ( $options & self::FORCE_ASSOC ) !== 0;
- 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 parse
has 48 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function parse( $value, $options = 0 ) {
if ( $options & self::STRIP_COMMENTS ) {
$value = self::stripComments( $value );
}
$assoc = ( $options & self::FORCE_ASSOC ) !== 0;
Method stripComments
has 45 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function stripComments( $json ) {
// Ensure we have a string
$str = (string)$json;
$buffer = '';
$maxLen = strlen( $str );
Function encode
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public static function encode( $value, $pretty = false, $escaping = 0 ) {
// PHP escapes '/' to prevent breaking out of inline script blocks using '</script>',
// which is hardly useful when '<' and '>' are escaped (and inadequate), and such
// escaping negatively impacts the human readability of URLs and similar strings.
$options = JSON_UNESCAPED_SLASHES;
- 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"