donate.php ➔ b_donations_donate_show()   C
last analyzed

Complexity

Conditions 9
Paths 64

Size

Total Lines 74
Code Lines 53

Duplication

Lines 11
Ratio 14.86 %

Importance

Changes 0
Metric Value
cc 9
eloc 53
nc 64
nop 1
dl 11
loc 74
rs 5.9292
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 44 and the first side effect is on line 34.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/************************************************************************/
3
/* Donations - Paypal financial management module for Xoops 2           */
4
/* Copyright (c) 2016 XOOPS Project                                     */
5
/* http://dev.xoops.org/modules/xfmod/project/?group_id=1060            */
6
/* 
7
/************************************************************************/
8
/*                                                                      */
9
/* Based on NukeTreasury for PHP-Nuke - by Dave Lawrence AKA Thrash     */
10
/* NukeTreasury - Financial management for PHP-Nuke                     */
11
/* Copyright (c) 2004 by Dave Lawrence AKA Thrash                       */
12
/*                       [email protected]                         */
13
/*                       [email protected]                          */
14
/*                                                                      */
15
/************************************************************************/
16
/*                                                                      */
17
/* This program is free software; you can redistribute it and/or modify */
18
/* it under the terms of the GNU General Public License as published by */
19
/* the Free Software Foundation; either version 2 of the License.       */
20
/*                                                                      */
21
/* This program is distributed in the hope that it will be useful, but  */
22
/* WITHOUT ANY WARRANTY; without even the implied warranty of           */
23
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU     */
24
/* General Public License for more details.                             */
25
/*                                                                      */
26
/* You should have received a copy of the GNU General Public License    */
27
/* along with this program; if not, write to the Free Software          */
28
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  */
29
/* USA                                                                  */
30
/************************************************************************/
31
32
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
33
34
$moduleDirName = basename(dirname(__DIR__));
35
36
xoops_loadLanguage('main', $moduleDirName);
37
38
include_once XOOPS_ROOT_PATH . "/modules/{$moduleDirName}/include/functions.php";
39
40
/**
41
 * @param $options
42
 * @return array
43
 */
44
function b_donations_donate_show($options)
0 ignored issues
show
Unused Code introduced by
The parameter $options is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
45
{
46
    global $xoopsDB, $xoopsUser;
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...
47
48
    $moduleDirName = basename(dirname(__DIR__));
49
    $tr_config     = configInfo();
50
    $paypal_url    = explode('|', $tr_config['paypal_url']);
51
    $paypal_url    = $paypal_url[0];
52
    //determine the currency
53
    $PP_CURR_CODE = explode('|', $tr_config['pp_curr_code']); // [USD,GBP,JPY,CAD,EUR]
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
54
    $PP_CURR_CODE = $PP_CURR_CODE[0];
55
    $currencySign    = defineCurrency($PP_CURR_CODE);
56
57
    $block = array();
58
59
    $PP_RECEIVER_EMAIL = $tr_config['receiver_email'];
60
    $PP_ITEMNAME       = $tr_config['pp_itemname'];
61
    $PP_TY_URL         = $tr_config['ty_url'];
62
    $PP_CANCEL_URL     = $tr_config['pp_cancel_url'];
63
64
    // Fill out some more template tags
65
    $DON_BUTTON_SUBMIT = $tr_config['don_button_submit'];
0 ignored issues
show
Unused Code introduced by
$DON_BUTTON_SUBMIT is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
66
67
    $PP_NO_SHIP   = $tr_config['pp_get_addr'] ? '0' : '1';
68
    $PP_IMAGE_URL = $tr_config['pp_image_url'];
69
70
    $DON_SUB_IMG_DIMS = '';
71
    if (is_numeric($tr_config['don_sub_img_width'])) {
72
        $DON_SUB_IMG_DIMS .= 'width=' . $tr_config['don_sub_img_width'] . ' ';
73
    }
74
    if (is_numeric($tr_config['don_sub_img_height'])) {
75
        $DON_SUB_IMG_DIMS .= 'height=' . $tr_config['don_sub_img_height'] . ' ';
76
    }
77
78
    $sql        = 'SELECT * FROM ' . $xoopsDB->prefix('donations_config') . " WHERE name='don_amount' ORDER BY subtype";
79
    $Recordset1 = $xoopsDB->query($sql);
80
81
    $DONATION_AMOUNTS = '';
82 View Code Duplication
    while (false != ($row_Recordset1 = $xoopsDB->fetchArray($Recordset1))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
83
        if (is_numeric($row_Recordset1['value']) && $row_Recordset1['value'] > 0) {
84
            if ($row_Recordset1['subtype'] == $tr_config['don_amt_checked']) {
85
                $checked               = ' selected';
86
                $block['basedonation'] = $row_Recordset1['value'];
87
            } else {
88
                $checked = '';
89
            }
90
            $DONATION_AMOUNTS .= '<option value="' . $row_Recordset1['value'] . '" ' . $checked . ' > ' . $currencySign . $row_Recordset1['value'] . '</option>' . "\n";
91
        }
92
    }
93
    $DONATION_AMOUNTS .= '<option value="0"> ' . _MB_DON_OTHER_AMOUNT . ' </option>';
94
95
    // Ok, output the page
96
97
    $uid                    = $xoopsUser ? $xoopsUser->getVar('uid') : 0;
98
    $block['custom']        = $uid;
99
    $block['email']         = $PP_RECEIVER_EMAIL;
100
    $block['item']          = $PP_ITEMNAME;
101
    $block['amounts']       = $DONATION_AMOUNTS;
102
    $block['prompt']        = $tr_config['don_name_prompt'];
103
    $block['nm_yes']        = $tr_config['don_name_yes'];
104
    $block['nm_no']         = $tr_config['don_name_no'];
105
    $block['pp_noship']     = $PP_NO_SHIP;
106
    $block['pp_curr_code']  = $PP_CURR_CODE;
107
    $block['pp_cancel']     = $PP_CANCEL_URL;
108
    $block['pp_thanks']     = $PP_TY_URL;
109
    $block['pp_image']      = $PP_IMAGE_URL;
110
    $block['sub_img']       = $DON_SUB_IMG_DIMS;
111
    $block['submit_button'] = _MB_DON_SUBMIT_BUTTON;
112
    $block['paypal_url']    = $paypal_url;
113
    $block['lang_select']   = _MB_DON_SELECTAMT;
114
    $block['xdon_dir']      = $moduleDirName;
115
116
    return $block;
117
}
118