src/utils/InterestPriceHandler.php
Showing 41 of 41 total issues
Function calculate_cost
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
Open
public function calculate_cost($cart) { global $woocommerce; if (is_admin() && !is_ajax()) { return; }
- Read upRead up
Avoid unused local variables such as '$woocommerce'. Open
Open
global $woocommerce;
- Read upRead up
- Exclude checks
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
Open
} else { $post_data = $_POST; }
- Read upRead up
- Exclude checks
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
Open
<?php
- Exclude checks
Visibility must be declared on method "__construct" Open
Open
function __construct() {
- Exclude checks
Opening brace of a class must be on the line after the definition Open
Open
class InterestPriceHandler {
- Exclude checks
Expected 0 spaces before closing bracket; 1 found Open
Open
if (isset($_POST['post_data'] ) ) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
exit; // Exit if accessed directly
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
Open
global $woocommerce;
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
Open
}
- Exclude checks
Opening brace should be on a new line Open
Open
function __construct() {
- Exclude checks
Opening brace should be on a new line Open
Open
public function add_installment_change_script() {
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
Open
parse_str(sanitize_text_field($_POST['post_data']), $post_data);
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
Open
}
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
Open
$taxes = $cart->get_taxes();
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
Open
}
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
Open
if (isset($post_data['vindi_cc_installments']) &&
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
Open
$cart_total = ($cart->get_cart_contents_total() + $cart->get_shipping_total() + $tax_total);
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
Open
add_action('woocommerce_cart_calculate_fees', array($this, 'calculate_cost'));
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
Open
}
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
Open
add_action('wp_footer', array($this, 'add_installment_change_script'));
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
Open
$post_data = $_POST;
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
Open
$interest_rate = get_option('woocommerce_vindi-credit-card_settings', true)['interest_rate'];
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
Open
$total_price = $cart_total * (1 + (($interest_rate / 100) * ($installments - 1)));
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
Open
public function calculate_cost($cart) {
- Exclude checks
Expected 1 space after closing parenthesis; found 0 Open
Open
if (is_checkout()): ?>
- Exclude checks
Expected 0 spaces before closing bracket; 1 found Open
Open
if (isset($_POST['post_data'] ) ) {
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
Open
$tax_total = 0;
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
Open
public function add_installment_change_script() {
- Exclude checks
Opening brace should be on a new line Open
Open
public function calculate_cost($cart) {
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
Open
} else {
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
Open
function __construct() {
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
Open
}
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
Open
if (is_checkout()): ?>
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 10 Open
Open
return;
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
Open
$interest_price = (float) $total_price - $cart_total;
- Exclude checks
Line indented incorrectly; expected at least 4 spaces, found 2 Open
Open
die();
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
Open
) {
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
Open
if (isset($_POST['post_data'] ) ) {
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
Open
$installments = intval(filter_var($post_data['vindi_cc_installments'], FILTER_SANITIZE_NUMBER_INT));
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
Open
WC()->cart->add_fee(__('Juros', VINDI), $interest_price);
- Exclude checks