Function array_sort
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
public static function array_sort($array, $on, $order=SORT_ASC)
{
$new_array = array();
$sortable_array = array();
- 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 get_matching_subscription_item
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public static function get_matching_subscription_item($subscription, $order_item, $match_type = 'match_attributes')
{
$matching_item = false;
if ('match_attributes' === $match_type) {
- 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 array_sort
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function array_sort($array, $on, $order=SORT_ASC)
{
$new_array = array();
$sortable_array = array();
Function get_matching_subscription
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public static function get_matching_subscription($order, $order_item)
{
$subscriptions = wcs_get_subscriptions_for_order($order, array('order_type' => 'parent'));
$matching_subscription = null;
foreach ($subscriptions as $subscription) {
- 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
The method array_sort uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$sortable_array[$k] = $v;
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid unused local variables such as '$match_type'. Open
$line_item = wcs_find_matching_line_item($order, $subscription_item, $match_type = 'match_attributes');
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
Avoid variables with short names like $on. Configured minimum length is 3. Open
public static function array_sort($array, $on, $order=SORT_ASC)
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $i. Configured minimum length is 3. Open
$i = 0;
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Visibility must be declared on method "__construct" Open
function __construct()
- Exclude checks
Blank line found at start of control structure Open
foreach ($custom_attributes as $name => $value) {
- Exclude checks
Function closing brace must go on the next line following the body; found 1 blank lines before brace Open
}
- Exclude checks
Incorrect spacing between default value and equals sign for argument "$order"; expected 1 but found 0 Open
public static function array_sort($array, $on, $order=SORT_ASC)
- Exclude checks
Incorrect spacing between argument "$order" and equals sign; expected 1 but found 0 Open
public static function array_sort($array, $on, $order=SORT_ASC)
- Exclude checks
Terminating statement must be indented to the same level as the CASE body Open
break;
- Exclude checks
Terminating statement must be indented to the same level as the CASE body Open
break;
- Exclude checks
Expected 1 blank line at end of file; 3 found Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$subscriptions = wcs_get_subscriptions_for_order($order, array('order_type' => 'parent'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (null === $matching_subscription && !empty($subscriptions)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$matching_subscription = array_pop($subscriptions);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $matching_subscription;
- Exclude checks
Line exceeds 120 characters; contains 162 characters Open
if ('match_attributes' === $match_type && wp_list_pluck($subscription_item->get_formatted_meta_data('_', true), 'value', 'key') != $order_item_attributes) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$matching_item = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $matching_item;
- Exclude checks
Line exceeds 120 characters; contains 249 characters Open
* @param string $match_type Optional. The type of comparison to make. Can be 'match_product_ids' to compare product|variation IDs or 'match_attributes' to also compare by item attributes on top of matching product IDs. Default 'match_attributes'.
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
public static function clean_statement_descriptor($statement_descriptor = '')
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$i = 0;
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
if (!$currency) {
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
$currency = get_woocommerce_currency();
- Exclude checks
Line indented incorrectly; expected at least 4 spaces, found 2 Open
{
- Exclude checks
Line indented incorrectly; expected at least 16 spaces, found 8 Open
$line_item = wcs_find_matching_line_item($order, $subscription_item, $match_type = 'match_attributes');
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
foreach ($custom_attributes as $name => $value) {
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$disallowed_characters = array('<', '>', '"', "'");
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
public static function get_vindi_amount($total, $currency = '')
- Exclude checks
Line indented incorrectly; expected at least 4 spaces, found 2 Open
{
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
return version_compare(WC_VERSION, $version, '<');
- Exclude checks
Line indented incorrectly; expected 12 spaces, found 6 Open
foreach ($subscription->get_items() as $subscription_item) {
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
add_action('woocommerce_process_product_meta', array($this, 'wc_post_meta'));
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
}
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
return absint(wc_format_decimal(((float) $total * 100), wc_get_price_decimals())); // In cents.
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$product->save();
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
foreach ($subscriptions as $subscription) {
- Exclude checks
Line indented incorrectly; expected 16 spaces, found 8 Open
if($order_item === $line_item) {
- Exclude checks
Line indented incorrectly; expected at least 4 spaces, found 2 Open
{
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
public static function wc_post_meta($post_id, $custom_attributes)
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
}
- Exclude checks
Closing brace indented incorrectly; expected 2 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
return htmlspecialchars(strip_tags($value));
- Exclude checks
Line indented incorrectly; expected 12 spaces, found 10 Open
}
- Exclude checks
Line indented incorrectly; expected 12 spaces, found 10 Open
switch ($order) {
- Exclude checks
Line indented incorrectly; expected at least 20 spaces, found 18 Open
arsort($sortable_array);
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$statement_descriptor = str_replace($disallowed_characters, '', $statement_descriptor);
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
$matching_item = $subscription_item;
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
public static function sanitize_xss($value) {
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
$new_array = array();
- Exclude checks
Line indented incorrectly; expected 12 spaces, found 10 Open
foreach ($array as $k => $v) {
- Exclude checks
Line indented incorrectly; expected 16 spaces, found 14 Open
case SORT_DESC:
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
return $new_array;
- Exclude checks
Line indented incorrectly; expected at least 4 spaces, found 2 Open
{
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
$product->update_meta_data($name, $value);
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$matching_subscription = null;
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected 12 spaces, found 6 Open
}
- Exclude checks
Line indented incorrectly; expected at least 4 spaces, found 2 Open
{
- Exclude checks
Line indented incorrectly; expected 24 spaces, found 22 Open
}
- Exclude checks
Line indented incorrectly; expected 12 spaces, found 10 Open
}
- Exclude checks
Line indented incorrectly; expected 12 spaces, found 10 Open
foreach ($sortable_array as $k => $v) {
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
public static function array_sort($array, $on, $order=SORT_ASC)
- Exclude checks
Line indented incorrectly; expected 16 spaces, found 14 Open
if (is_array($v)) {
- Exclude checks
Line indented incorrectly; expected at least 28 spaces, found 26 Open
$sortable_array[$k] = $v2;
- Exclude checks
Line indented incorrectly; expected 16 spaces, found 14 Open
} else {
- Exclude checks
Line indented incorrectly; expected at least 16 spaces, found 14 Open
$new_array[$k] = $array[$k];
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
}
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
public static function is_wc_lt($version)
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
}
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$product = wc_get_product($post_id);
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
$i++;
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
}
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
public static function get_matching_subscription($order, $order_item)
- Exclude checks
Line indented incorrectly; expected at least 16 spaces, found 8 Open
continue;
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$statement_descriptor = substr(trim($statement_descriptor), 0, 22);
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
return $statement_descriptor;
- Exclude checks
Whitespace found at end of line Open
*
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 6 Open
if (count($array) > 0) {
- Exclude checks
Line indented incorrectly; expected at least 20 spaces, found 10 Open
break 2;
- Exclude checks
Whitespace found at end of line Open
*
- Exclude checks
Line indented incorrectly; expected at least 4 spaces, found 2 Open
{
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
}
- Exclude checks
Line indented incorrectly; expected at least 4 spaces, found 2 Open
{
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$order_item_canonical_product_id = wcs_get_canonical_product_id($order_item);
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
break;
- Exclude checks
Line indented incorrectly; expected 12 spaces, found 10 Open
}
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 6 Open
}
- Exclude checks
Line indented incorrectly; expected 12 spaces, found 6 Open
}
- Exclude checks
Line indented incorrectly; expected at least 4 spaces, found 2 Open
{
- Exclude checks
Line indented incorrectly; expected at least 16 spaces, found 8 Open
continue;
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
}
- Exclude checks
Line indented incorrectly; expected at least 20 spaces, found 18 Open
asort($sortable_array);
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
function __construct()
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
if ('match_attributes' === $match_type) {
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
}
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
$sortable_array = array();
- Exclude checks
Line indented incorrectly; expected 16 spaces, found 14 Open
}
- Exclude checks
Line indented incorrectly; expected 16 spaces, found 14 Open
case SORT_ASC:
- Exclude checks
Line indented incorrectly; expected 12 spaces, found 6 Open
if (wcs_get_canonical_product_id($subscription_item) !== $order_item_canonical_product_id) {
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
}
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
$order_item_attributes = wp_list_pluck($order_item->get_formatted_meta_data('_', true), 'value', 'key');
- Exclude checks
Line indented incorrectly; expected 12 spaces, found 6 Open
}
- Exclude checks
Opening brace should be on a new line Open
public static function sanitize_xss($value) {
- Exclude checks
Line indented incorrectly; expected 20 spaces, found 18 Open
}
- Exclude checks
Line indented incorrectly; expected 16 spaces, found 8 Open
}
- Exclude checks
Line indented incorrectly; expected at least 20 spaces, found 18 Open
$sortable_array[$k] = $v;
- Exclude checks
Expected 1 space after IF keyword; 0 found Open
if($order_item === $line_item) {
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
foreach ($subscription->get_items() as $subscription_item) {
- Exclude checks
Line indented incorrectly; expected 12 spaces, found 6 Open
if ('match_attributes' === $match_type && wp_list_pluck($subscription_item->get_formatted_meta_data('_', true), 'value', 'key') != $order_item_attributes) {
- Exclude checks
Line indented incorrectly; expected 20 spaces, found 18 Open
foreach ($v as $k2 => $v2) {
- Exclude checks
Line indented incorrectly; expected 24 spaces, found 22 Open
if ($k2 == $on) {
- Exclude checks
Line indented incorrectly; expected at least 20 spaces, found 10 Open
$matching_subscription = $subscription;
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
public static function get_matching_subscription_item($subscription, $order_item, $match_type = 'match_attributes')
- Exclude checks