vindi/vindi-woocommerce

View on GitHub
src/services/VindiHelpers.php

Summary

Maintainability
B
6 hrs
Test Coverage

Showing 123 of 123 total issues

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();
Severity: Minor
Found in src/services/VindiHelpers.php - About 2 hrs to fix

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) {
Severity: Minor
Found in src/services/VindiHelpers.php - About 1 hr to fix

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();
Severity: Minor
Found in src/services/VindiHelpers.php - About 1 hr to fix

    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) {
    Severity: Minor
    Found in src/services/VindiHelpers.php - About 55 mins to fix

    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;
    }
    Severity: Minor
    Found in src/services/VindiHelpers.php by phpmd

    Avoid unused local variables such as '$match_type'.
    Open

    $line_item = wcs_find_matching_line_item($order, $subscription_item, $match_type = 'match_attributes');
    Severity: Minor
    Found in src/services/VindiHelpers.php by phpmd

    Avoid variables with short names like $i. Configured minimum length is 3.
    Open

    $i = 0;
    Severity: Minor
    Found in src/services/VindiHelpers.php by phpmd

    Avoid variables with short names like $on. Configured minimum length is 3.
    Open

    public static function array_sort($array, $on, $order=SORT_ASC)
    Severity: Minor
    Found in src/services/VindiHelpers.php by phpmd

    Blank line found at start of control structure
    Open

    foreach ($custom_attributes as $name => $value) {

    Visibility must be declared on method "__construct"
    Open

    function __construct()

    Function closing brace must go on the next line following the body; found 1 blank lines before brace
    Open

    }

    Expected 1 blank line at end of file; 3 found
    Open

    }

    Incorrect spacing between argument "$order" and equals sign; expected 1 but found 0
    Open

    public static function array_sort($array, $on, $order=SORT_ASC)

    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)

    Terminating statement must be indented to the same level as the CASE body
    Open

    break;

    Terminating statement must be indented to the same level as the CASE body
    Open

    break;

    Spaces must be used to indent lines; tabs are not allowed
    Open

    if (null === $matching_subscription && !empty($subscriptions)) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

    }

    Spaces must be used to indent lines; tabs are not allowed
    Open

    $subscriptions = wcs_get_subscriptions_for_order($order, array('order_type' => 'parent'));

    Spaces must be used to indent lines; tabs are not allowed
    Open

    $matching_subscription = array_pop($subscriptions);

    Spaces must be used to indent lines; tabs are not allowed
    Open

    $matching_item = false;

    Spaces must be used to indent lines; tabs are not allowed
    Open

    return $matching_item;

    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) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

    }

    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'.

    Spaces must be used to indent lines; tabs are not allowed
    Open

    return $matching_subscription;

    Line indented incorrectly; expected at least 4 spaces, found 2
    Open

    {

    Line indented incorrectly; expected at least 8 spaces, found 4
    Open

    return htmlspecialchars(strip_tags($value));

    Line indented incorrectly; expected 8 spaces, found 4
    Open

    if ('match_attributes' === $match_type) {

    Line indented incorrectly; expected 8 spaces, found 4
    Open

    foreach ($subscriptions as $subscription) {

    Line indented incorrectly; expected 12 spaces, found 6
    Open

    foreach ($subscription->get_items() as $subscription_item) {

    Line indented incorrectly; expected at least 4 spaces, found 2
    Open

    {

    Line indented incorrectly; expected at least 8 spaces, found 4
    Open

    return $statement_descriptor;

    Line indented incorrectly; expected 4 spaces, found 2
    Open

    public static function is_wc_lt($version)

    Line indented incorrectly; expected at least 4 spaces, found 2
    Open

    {

    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');

    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) {

    Line indented incorrectly; expected at least 12 spaces, found 6
    Open

    $matching_item = $subscription_item;

    Line indented incorrectly; expected 4 spaces, found 2
    Open

    public static function sanitize_xss($value) {

    Line indented incorrectly; expected 8 spaces, found 4
    Open

    }

    Line indented incorrectly; expected at least 20 spaces, found 10
    Open

    break 2;

    Line indented incorrectly; expected at least 12 spaces, found 6
    Open

    break;

    Line indented incorrectly; expected 4 spaces, found 2
    Open

    }

    Line indented incorrectly; expected 4 spaces, found 2
    Open

    }

    Line indented incorrectly; expected at least 8 spaces, found 4
    Open

    $matching_subscription = null;

    Line indented incorrectly; expected 4 spaces, found 2
    Open

    public static function get_matching_subscription_item($subscription, $order_item, $match_type = 'match_attributes')

    Line indented incorrectly; expected 4 spaces, found 2
    Open

    }

    Line indented incorrectly; expected 4 spaces, found 2
    Open

    function __construct()

    Line indented incorrectly; expected 4 spaces, found 2
    Open

    }

    Line indented incorrectly; expected at least 4 spaces, found 2
    Open

    {

    Line indented incorrectly; expected 8 spaces, found 4
    Open

    foreach ($custom_attributes as $name => $value) {

    Line indented incorrectly; expected at least 16 spaces, found 8
    Open

    continue;

    Line indented incorrectly; expected 8 spaces, found 4
    Open

    }

    Line indented incorrectly; expected at least 8 spaces, found 4
    Open

    $statement_descriptor = substr(trim($statement_descriptor), 0, 22);

    Line indented incorrectly; expected at least 8 spaces, found 4
    Open

    $order_item_canonical_product_id = wcs_get_canonical_product_id($order_item);

    Line indented incorrectly; expected at least 8 spaces, found 4
    Open

    add_action('woocommerce_process_product_meta', array($this, 'wc_post_meta'));

    Line indented incorrectly; expected 4 spaces, found 2
    Open

    }

    Line indented incorrectly; expected at least 8 spaces, found 4
    Open

    return version_compare(WC_VERSION, $version, '<');

    Line indented incorrectly; expected 4 spaces, found 2
    Open

    public static function get_matching_subscription($order, $order_item)

    Line indented incorrectly; expected 4 spaces, found 2
    Open

    }

    Line indented incorrectly; expected 4 spaces, found 2
    Open

    public static function get_vindi_amount($total, $currency = '')

    Line indented incorrectly; expected 4 spaces, found 2
    Open

    }

    Line indented incorrectly; expected at least 12 spaces, found 6
    Open

    $product->update_meta_data($name, $value);

    Line indented incorrectly; expected at least 8 spaces, found 4
    Open

    $product->save();

    Line indented incorrectly; expected 16 spaces, found 8
    Open

    if($order_item === $line_item) {

    Expected 1 space after IF keyword; 0 found
    Open

    if($order_item === $line_item) {

    Line indented incorrectly; expected 12 spaces, found 6
    Open

    if (wcs_get_canonical_product_id($subscription_item) !== $order_item_canonical_product_id) {

    Line indented incorrectly; expected at least 4 spaces, found 2
    Open

    {

    Line indented incorrectly; expected 16 spaces, found 8
    Open

    }

    Line indented incorrectly; expected 8 spaces, found 4
    Open

    }

    Line indented incorrectly; expected 8 spaces, found 4
    Open

    foreach ($subscription->get_items() as $subscription_item) {

    Line indented incorrectly; expected 12 spaces, found 6
    Open

    }

    Line indented incorrectly; expected 8 spaces, found 4
    Open

    if (!$currency) {

    Line indented incorrectly; expected 8 spaces, found 4
    Open

    }

    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.

    Line indented incorrectly; expected 4 spaces, found 2
    Open

    public static function wc_post_meta($post_id, $custom_attributes)

    Line indented incorrectly; expected at least 4 spaces, found 2
    Open

    {

    Line indented incorrectly; expected at least 8 spaces, found 4
    Open

    $statement_descriptor = str_replace($disallowed_characters, '', $statement_descriptor);

    Line indented incorrectly; expected at least 12 spaces, found 6
    Open

    $currency = get_woocommerce_currency();

    Line indented incorrectly; expected at least 4 spaces, found 2
    Open

    {

    Closing brace indented incorrectly; expected 2 spaces, found 4
    Open

    }

    Opening brace should be on a new line
    Open

    public static function sanitize_xss($value) {

    Line indented incorrectly; expected at least 8 spaces, found 4
    Open

    $disallowed_characters = array('<', '>', '"', "'");

    Line indented incorrectly; expected at least 8 spaces, found 4
    Open

    $product = wc_get_product($post_id);

    Line indented incorrectly; expected at least 8 spaces, found 4
    Open

    $i = 0;

    Line indented incorrectly; expected at least 12 spaces, found 6
    Open

    $i++;

    Line indented incorrectly; expected at least 16 spaces, found 8
    Open

    continue;

    Line indented incorrectly; expected 8 spaces, found 6
    Open

    if (count($array) > 0) {

    Line indented incorrectly; expected at least 20 spaces, found 10
    Open

    $matching_subscription = $subscription;

    Line indented incorrectly; expected 12 spaces, found 6
    Open

    }

    Line indented incorrectly; expected 24 spaces, found 22
    Open

    if ($k2 == $on) {

    Line indented incorrectly; expected at least 16 spaces, found 14
    Open

    $new_array[$k] = $array[$k];

    Line indented incorrectly; expected 4 spaces, found 2
    Open

    public static function clean_statement_descriptor($statement_descriptor = '')

    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');

    Line indented incorrectly; expected 8 spaces, found 4
    Open

    }

    Line indented incorrectly; expected 12 spaces, found 6
    Open

    }

    Line indented incorrectly; expected 24 spaces, found 22
    Open

    }

    Line indented incorrectly; expected 16 spaces, found 14
    Open

    } else {

    Line indented incorrectly; expected 12 spaces, found 10
    Open

    switch ($order) {

    Line indented incorrectly; expected at least 20 spaces, found 18
    Open

    arsort($sortable_array);

    Line indented incorrectly; expected 8 spaces, found 6
    Open

    }

    Line indented incorrectly; expected 12 spaces, found 10
    Open

    foreach ($array as $k => $v) {

    Line indented incorrectly; expected 12 spaces, found 10
    Open

    }

    Line indented incorrectly; expected at least 20 spaces, found 18
    Open

    asort($sortable_array);

    Line indented incorrectly; expected 12 spaces, found 10
    Open

    }

    Line indented incorrectly; expected 12 spaces, found 10
    Open

    }

    Line indented incorrectly; expected 4 spaces, found 2
    Open

    }

    Line indented incorrectly; expected at least 4 spaces, found 2
    Open

    {

    Line indented incorrectly; expected at least 20 spaces, found 18
    Open

    $sortable_array[$k] = $v;

    Line indented incorrectly; expected 16 spaces, found 14
    Open

    case SORT_DESC:

    Line indented incorrectly; expected at least 8 spaces, found 6
    Open

    $new_array = array();

    Line indented incorrectly; expected at least 8 spaces, found 6
    Open

    $sortable_array = array();

    Line indented incorrectly; expected 20 spaces, found 18
    Open

    foreach ($v as $k2 => $v2) {

    Line indented incorrectly; expected at least 28 spaces, found 26
    Open

    $sortable_array[$k] = $v2;

    Line indented incorrectly; expected 16 spaces, found 14
    Open

    case SORT_ASC:

    Line indented incorrectly; expected 4 spaces, found 2
    Open

    public static function array_sort($array, $on, $order=SORT_ASC)

    Whitespace found at end of line
    Open

    *

    Whitespace found at end of line
    Open

    *

    Line indented incorrectly; expected 20 spaces, found 18
    Open

    }

    Line indented incorrectly; expected 16 spaces, found 14
    Open

    }

    Line indented incorrectly; expected at least 8 spaces, found 6
    Open

    return $new_array;

    Line indented incorrectly; expected 16 spaces, found 14
    Open

    if (is_array($v)) {

    Line indented incorrectly; expected 12 spaces, found 10
    Open

    foreach ($sortable_array as $k => $v) {
    Category
    Status