vindi/vindi-woocommerce

View on GitHub
src/utils/InterestPriceHandler.php

Summary

Maintainability
A
25 mins
Test Coverage

Showing 41 of 41 total issues

Function calculate_cost has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

public function calculate_cost($cart) {
global $woocommerce;
if (is_admin() && !is_ajax()) {
return;
}
Severity: Minor
Found in src/utils/InterestPriceHandler.php - About 25 mins to fix

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

global $woocommerce;
Severity: Minor
Found in src/utils/InterestPriceHandler.php by phpmd

The method calculate_cost uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

} else {
$post_data = $_POST;
}
Severity: Minor
Found in src/utils/InterestPriceHandler.php by phpmd

A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 10 and the first side effect is on line 6.
Open

<?php

Visibility must be declared on method "__construct"
Open

function __construct() {

Opening brace of a class must be on the line after the definition
Open

class InterestPriceHandler {

Expected 0 spaces before closing bracket; 1 found
Open

if (isset($_POST['post_data'] ) ) {

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

exit; // Exit if accessed directly

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

global $woocommerce;

Line indented incorrectly; expected 8 spaces, found 4
Open

}

Opening brace should be on a new line
Open

function __construct() {

Opening brace should be on a new line
Open

public function add_installment_change_script() {

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

parse_str(sanitize_text_field($_POST['post_data']), $post_data);

Line indented incorrectly; expected 4 spaces, found 2
Open

}

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

$taxes = $cart->get_taxes();

Line indented incorrectly; expected 4 spaces, found 2
Open

}

Line indented incorrectly; expected 8 spaces, found 4
Open

if (isset($post_data['vindi_cc_installments']) &&

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

$cart_total = ($cart->get_cart_contents_total() + $cart->get_shipping_total() + $tax_total);

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

add_action('woocommerce_cart_calculate_fees', array($this, 'calculate_cost'));

Line indented incorrectly; expected 8 spaces, found 4
Open

}

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

add_action('wp_footer', array($this, 'add_installment_change_script'));

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

$post_data = $_POST;

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

$interest_rate = get_option('woocommerce_vindi-credit-card_settings', true)['interest_rate'];

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

$total_price = $cart_total * (1 + (($interest_rate / 100) * ($installments - 1)));

Line indented incorrectly; expected 4 spaces, found 2
Open

public function calculate_cost($cart) {

Expected 1 space after closing parenthesis; found 0
Open

if (is_checkout()): ?>

Expected 0 spaces before closing bracket; 1 found
Open

if (isset($_POST['post_data'] ) ) {

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

$tax_total = 0;

Line indented incorrectly; expected 4 spaces, found 2
Open

public function add_installment_change_script() {

Opening brace should be on a new line
Open

public function calculate_cost($cart) {

Line indented incorrectly; expected 8 spaces, found 4
Open

} else {

Line indented incorrectly; expected 4 spaces, found 2
Open

function __construct() {

Line indented incorrectly; expected 4 spaces, found 2
Open

}

Line indented incorrectly; expected 8 spaces, found 4
Open

if (is_checkout()): ?>

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

return;

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

$interest_price = (float) $total_price - $cart_total;

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

die();

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

) {

Line indented incorrectly; expected 8 spaces, found 4
Open

if (isset($_POST['post_data'] ) ) {

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

$installments = intval(filter_var($post_data['vindi_cc_installments'], FILTER_SANITIZE_NUMBER_INT));

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

WC()->cart->add_fee(__('Juros', VINDI), $interest_price);
Category
Status