bmh_callback_database.php ➔ callbackAction()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 36

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 9
dl 0
loc 36
rs 9.344
c 0
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
/* This is a sample callback function for PHPMailer-BMH (Bounce Mail Handler).
4
 * This callback function will echo the results of the BMH processing.
5
 */
6
7
/* Callback (action) function
8
 * @param int     $msgnum        the message number returned by Bounce Mail Handler
9
 * @param string  $bounce_type   the bounce type: 'antispam','autoreply','concurrent','content_reject','command_reject','internal_error','defer','delayed'        => array('remove'=>0,'bounce_type'=>'temporary'),'dns_loop','dns_unknown','full','inactive','latin_only','other','oversize','outofoffice','unknown','unrecognized','user_reject','warning'
10
 * @param string  $email         the target email address
11
 * @param string  $subject       the subject, ignore now
12
 * @param string  $xheader       the XBounceHeader from the mail
13
 * @param boolean $remove        remove status, 1 means removed, 0 means not removed
14
 * @param string  $rule_no       Bounce Mail Handler detect rule no.
15
 * @param string  $rule_cat      Bounce Mail Handler detect rule category.
16
 * @param int     $totalFetched  total number of messages in the mailbox
17
 * @return boolean
18
 */
19
20
use XoopsModules\Xnewsletter;
21
22
require_once __DIR__ . '/admin_header.php';
23
24
/**
25
 * @param      $msgnum
26
 * @param      $bounce_type
27
 * @param      $email
28
 * @param      $subject
29
 * @param      $xheader
30
 * @param      $remove
31
 * @param bool $rule_no
32
 * @param bool $rule_cat
33
 * @param int  $totalFetched
34
 *
35
 * @return bool
36
 */
37
function callbackAction(
38
    $msgnum,
0 ignored issues
show
Unused Code introduced by
The parameter $msgnum 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...
39
    $bounce_type,
40
    $email,
41
    $subject,
42
    $xheader,
0 ignored issues
show
Unused Code introduced by
The parameter $xheader 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...
43
    $remove,
44
    $rule_no = false,
45
    $rule_cat = false,
46
    $totalFetched = 0)
0 ignored issues
show
Unused Code introduced by
The parameter $totalFetched 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...
47
{
48
    global $xoopsUser;
49
    $helper = Xnewsletter\Helper::getInstance();
50
51
    if ('0000' != $rule_no) {
52
        $bmhObj = $helper->getHandler('Bmh')->create();
53
        $bmhObj->setVar('bmh_rule_no', $rule_no);
54
        $bmhObj->setVar('bmh_rule_cat', $rule_cat);
55
        $bmhObj->setVar('bmh_bouncetype', $bounce_type);
56
        //$verif_bmh_remove = ($remove === true || $remove == '1') ? '1' : '0';
57
        $bmhObj->setVar('bmh_remove', $remove);
58
        $bmhObj->setVar('bmh_email', $email);
59
        $bmhObj->setVar('bmh_subject', $subject);
60
        $bmhObj->setVar('bmh_measure', '0');
61
        $bmhObj->setVar('bmh_submitter', $xoopsUser->uid());
62
        $bmhObj->setVar('bmh_created', time());
63
64
        if (!$helper->getHandler('Bmh')->insert($bmhObj)) {
65
            $GLOBALS['xoopsTpl']->assign('error', $bmhObj->getHtmlErrors());
66
            return false;
67
        }
68
        //echo $msgnum . ': '  . $rule_no . ' | '  . $rule_cat . ' | '  . $bounce_type . ' | '  . $remove . ' | ' . $email . ' | '  . $subject . ' | '  . $xheader . "<br>\n";
69
    }
70
71
    return true;
72
}
73