Completed
Push — master ( 9d3fbd...af269e )
by Michael
09:48
created

oledrion_cart.php ➔ b_oledrion_cart_show()   B

Complexity

Conditions 4
Paths 3

Size

Total Lines 33
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 26
nc 3
nop 1
dl 0
loc 33
rs 8.5806
c 0
b 0
f 0
1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
12
/**
13
 * oledrion
14
 *
15
 * @copyright   {@link https://xoops.org/ XOOPS Project}
16
 * @license     {@link http://www.fsf.org/copyleft/gpl.html GNU public license}
17
 * @author      Hervé Thouzard (http://www.herve-thouzard.com/)
18
 */
19
20
/**
21
 * block to display items in cart
22
 *
23
 * @param  integer $options [0] Count of items to show (0 = no limit)
24
 * @return array   Block's content
0 ignored issues
show
Documentation introduced by
Should the return type not be string|array?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
25
 */
26
function b_oledrion_cart_show($options)
27
{
28
    global $mod_pref, $xoopsConfig;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
29
    include XOOPS_ROOT_PATH . '/modules/oledrion/include/common.php';
30
    $productsCount = (int)$options[0];
31
32
    $cartForTemplate      = $block = array();
33
    $emptyCart            = false;
34
    $shippingAmount       = $commandAmount = $vatAmount = $discountsCount = 0;
35
    $goOn                 = '';
36
    $commandAmountTTC     = 0;
37
    $discountsDescription = array();
38
    // Calcul du montant total du caddy
39
    $reductions = new oledrion_reductions();
40
    $reductions->computeCart($cartForTemplate, $emptyCart, $shippingAmount, $commandAmount, $vatAmount, $goOn, $commandAmountTTC, $discountsDescription, $discountsCount);
0 ignored issues
show
Bug introduced by
The call to computeCart() misses a required argument $checkoutAttributes.

This check looks for function calls that miss required arguments.

Loading history...
41
    $dec = OledrionUtility::getModuleOption('decimals_count');
42
    if ($emptyCart) {
43
        return '';
44
    }
45
    $block['block_money_full']           = OledrionUtility::getModuleOption('money_full');
46
    $block['block_money_short']          = OledrionUtility::getModuleOption('money_short');
47
    $block['block_shippingAmount']       = sprintf('%0.' . $dec . 'f', $shippingAmount); // Montant des frais de port
48
    $block['block_commandAmount']        = sprintf('%0.' . $dec . 'f', $commandAmount); // Montant HT de la commande
49
    $block['block_vatAmount']            = sprintf('%0.' . $dec . 'f', $vatAmount); // Montant de la TVA
50
    $block['block_commandAmountTTC']     = sprintf('%0.' . $dec . 'f', $commandAmountTTC); // Montant TTC de la commande
51
    $block['block_discountsDescription'] = $discountsDescription; // Liste des réductions accordées
52
    if (($productsCount > 0) && (count($cartForTemplate) > $productsCount)) {
53
        array_slice($cartForTemplate, 0, $productsCount - 1);
54
    }
55
    $block['block_caddieProducts'] = $cartForTemplate; // Produits dans le caddy
56
57
    return $block;
58
}
59
60
/**
61
 * @param $options
62
 * @return string
63
 */
64 View Code Duplication
function b_oledrion_cart_edit($options)
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
65
{
66
    global $xoopsConfig;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
67
    include XOOPS_ROOT_PATH . '/modules/oledrion/include/common.php';
68
    $form = '';
69
    $form .= "<table border='0'>";
70
    $form .= '<tr><td>' . _MB_OLEDRION_MAX_ITEMS . "</td><td><input type='text' name='options[]' id='options' value='" . $options[0] . "'></td></tr>";
71
    $form .= '</table>';
72
73
    return $form;
74
}
75