Function applyTransformations
has a Cognitive Complexity of 72 (exceeds 5 allowed). Consider refactoring. Open
protected static function applyTransformations( array $dataIn, array $transforms ) {
$strip = $transforms['Strip'] ?? 'none';
if ( $strip === 'base' ) {
$transforms['Strip'] = 'none';
}
- 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
File ApiResult.php
has 630 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
Method applyTransformations
has 184 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected static function applyTransformations( array $dataIn, array $transforms ) {
$strip = $transforms['Strip'] ?? 'none';
if ( $strip === 'base' ) {
$transforms['Strip'] = 'none';
}
ApiResult
has 40 functions (exceeds 20 allowed). Consider refactoring. Open
class ApiResult implements ApiSerializable {
/**
* Override existing value in addValue(), setValue(), and similar functions
* @since 1.21
Function validateValue
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
private static function validateValue( $value ) {
if ( is_object( $value ) ) {
// Note we use is_callable() here instead of instanceof because
// ApiSerializable is an informal protocol (see docs there for details).
if ( is_callable( [ $value, 'serializeForApiResult' ] ) ) {
- 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 setValue
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
public static function setValue( array &$arr, $name, $value, $flags = 0 ) {
if ( ( $flags & self::NO_VALIDATE ) !== self::NO_VALIDATE ) {
$value = self::validateValue( $value );
}
- 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 validateValue
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function validateValue( $value ) {
if ( is_object( $value ) ) {
// Note we use is_callable() here instead of instanceof because
// ApiSerializable is an informal protocol (see docs there for details).
if ( is_callable( [ $value, 'serializeForApiResult' ] ) ) {
Function stripMetadata
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
public static function stripMetadata( $data ) {
if ( is_array( $data ) || is_object( $data ) ) {
$isObj = is_object( $data );
if ( $isObj ) {
$data = (array)$data;
- 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 stripMetadataNonRecursive
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
public static function stripMetadataNonRecursive( $data, &$metadata = null ) {
if ( !is_array( $metadata ) ) {
$metadata = [];
}
if ( is_array( $data ) || is_object( $data ) ) {
- 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 addMetadataToResultVars
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function addMetadataToResultVars( $vars, $forceHash = true ) {
// Process subarrays and determine if this is a JS [] or {}
$hash = $forceHash;
$maxKey = -1;
$bools = [];
Function addMetadataToResultVars
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public static function addMetadataToResultVars( $vars, $forceHash = true ) {
// Process subarrays and determine if this is a JS [] or {}
$hash = $forceHash;
$maxKey = -1;
$bools = [];
- 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 setValue
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function setValue( array &$arr, $name, $value, $flags = 0 ) {
if ( ( $flags & self::NO_VALIDATE ) !== self::NO_VALIDATE ) {
$value = self::validateValue( $value );
}
Method path
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function &path( $path, $create = 'append' ) {
$path = (array)$path;
$ret = &$this->data;
foreach ( $path as $i => $k ) {
if ( !isset( $ret[$k] ) ) {
Function path
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
private function &path( $path, $create = 'append' ) {
$path = (array)$path;
$ret = &$this->data;
foreach ( $path as $i => $k ) {
if ( !isset( $ret[$k] ) ) {
- 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 size
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private static function size( $value ) {
$s = 0;
if ( is_array( $value ) ) {
foreach ( $value as $k => $v ) {
if ( !self::isMetadataKey( $k ) ) {
- 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
Avoid too many return
statements within this method. Open
return $data + $keepMetadata;
Avoid too many return
statements within this method. Open
return $ret + $keepMetadata;