Passed
Branch master (30ffcd)
by Michael
06:06
created

b_donations_donate_show()   B

Complexity

Conditions 9
Paths 64

Size

Total Lines 74
Code Lines 53

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 53
nc 64
nop 1
dl 0
loc 74
rs 7.4698
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
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
use XoopsModules\Xdonations;
33
34
// defined('XOOPS_ROOT_PATH') || die('Restricted access');
35
36
$moduleDirName = basename(dirname(__DIR__));
37
38
xoops_loadLanguage('main', $moduleDirName);
0 ignored issues
show
Bug introduced by
The function xoops_loadLanguage was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

38
/** @scrutinizer ignore-call */ 
39
xoops_loadLanguage('main', $moduleDirName);
Loading history...
39
40
41
42
/**
43
 * @param $options
44
 * @return array
45
 */
46
function b_donations_donate_show($options)
0 ignored issues
show
Unused Code introduced by
The parameter $options is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

46
function b_donations_donate_show(/** @scrutinizer ignore-unused */ $options)

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

Loading history...
47
{
48
    global $xoopsDB, $xoopsUser;
49
50
    $moduleDirName = basename(dirname(__DIR__));
51
    $utility = new Xdonations\Utility();
52
    $tr_config     = $utility::getConfigInfo();
53
    $paypal_url    = explode('|', $tr_config['paypal_url']);
54
    $paypal_url    = $paypal_url[0];
55
    //determine the currency
56
    $PP_CURR_CODE = explode('|', $tr_config['pp_curr_code']); // [USD,GBP,JPY,CAD,EUR]
57
    $PP_CURR_CODE = $PP_CURR_CODE[0];
58
    $currencySign = $utility::defineCurrency($PP_CURR_CODE);
59
60
    $block = [];
61
62
    $PP_RECEIVER_EMAIL = $tr_config['receiver_email'];
63
    $PP_ITEMNAME       = $tr_config['pp_itemname'];
64
    $PP_TY_URL         = $tr_config['ty_url'];
65
    $PP_CANCEL_URL     = $tr_config['pp_cancel_url'];
66
67
    // Fill out some more template tags
68
    $DON_BUTTON_SUBMIT = $tr_config['don_button_submit'];
0 ignored issues
show
Unused Code introduced by
The assignment to $DON_BUTTON_SUBMIT is dead and can be removed.
Loading history...
69
70
    $PP_NO_SHIP   = $tr_config['pp_get_addr'] ? '0' : '1';
71
    $PP_IMAGE_URL = $tr_config['pp_image_url'];
72
73
    $DON_SUB_IMG_DIMS = '';
74
    if (is_numeric($tr_config['don_sub_img_width'])) {
75
        $DON_SUB_IMG_DIMS .= 'width=' . $tr_config['don_sub_img_width'] . ' ';
76
    }
77
    if (is_numeric($tr_config['don_sub_img_height'])) {
78
        $DON_SUB_IMG_DIMS .= 'height=' . $tr_config['don_sub_img_height'] . ' ';
79
    }
80
81
    $sql        = 'SELECT * FROM ' . $xoopsDB->prefix('donations_config') . " WHERE name='don_amount' ORDER BY subtype";
82
    $Recordset1 = $xoopsDB->query($sql);
83
84
    $DONATION_AMOUNTS = '';
85
    while (false !== ($row_Recordset1 = $xoopsDB->fetchArray($Recordset1))) {
86
        if (is_numeric($row_Recordset1['value']) && $row_Recordset1['value'] > 0) {
87
            if ($row_Recordset1['subtype'] == $tr_config['don_amt_checked']) {
88
                $checked               = ' selected';
89
                $block['basedonation'] = $row_Recordset1['value'];
90
            } else {
91
                $checked = '';
92
            }
93
            $DONATION_AMOUNTS .= '<option value="' . $row_Recordset1['value'] . '" ' . $checked . ' > ' . $currencySign . $row_Recordset1['value'] . '</option>' . "\n";
94
        }
95
    }
96
    $DONATION_AMOUNTS .= '<option value="0"> ' . _MB_XDONATION_OTHER_AMOUNT . ' </option>';
97
98
    // Ok, output the page
99
100
    $uid                    = $xoopsUser ? $xoopsUser->getVar('uid') : 0;
101
    $block['custom']        = $uid;
102
    $block['email']         = $PP_RECEIVER_EMAIL;
103
    $block['item']          = $PP_ITEMNAME;
104
    $block['amounts']       = $DONATION_AMOUNTS;
105
    $block['prompt']        = $tr_config['don_name_prompt'];
106
    $block['nm_yes']        = $tr_config['don_name_yes'];
107
    $block['nm_no']         = $tr_config['don_name_no'];
108
    $block['pp_noship']     = $PP_NO_SHIP;
109
    $block['pp_curr_code']  = $PP_CURR_CODE;
110
    $block['pp_cancel']     = $PP_CANCEL_URL;
111
    $block['pp_thanks']     = $PP_TY_URL;
112
    $block['pp_image']      = $PP_IMAGE_URL;
113
    $block['sub_img']       = $DON_SUB_IMG_DIMS;
114
    $block['submit_button'] = _MB_XDONATION_SUBMIT_BUTTON;
115
    $block['paypal_url']    = $paypal_url;
116
    $block['lang_select']   = _MB_XDONATION_SELECTAMT;
117
    $block['xdon_dir']      = $moduleDirName;
118
119
    return $block;
120
}
121