These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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 | /** |
||
8 | * Callback (action) function |
||
9 | * |
||
10 | * @param int $msgnum the message number returned by Bounce Mail Handler |
||
11 | * @param string $bounceType the bounce type: |
||
12 | * 'antispam','autoreply','concurrent','content_reject','command_reject','internal_error','defer','delayed' |
||
13 | * => |
||
14 | * array('remove'=>0,'bounce_type'=>'temporary'),'dns_loop','dns_unknown','full','inactive','latin_only','other','oversize','outofoffice','unknown','unrecognized','user_reject','warning' |
||
15 | * @param string $email the target email address |
||
16 | * @param string $subject the subject, ignore now |
||
17 | * @param string $xheader the XBounceHeader from the mail |
||
18 | * @param bool $remove remove status, 1 means removed, 0 means not removed |
||
19 | * @param bool|string $ruleNo bounce Mail Handler detect rule no |
||
20 | * @param bool|string $ruleCat bounce Mail Handler detect rule category |
||
21 | * @param int $totalFetched total number of messages in the mailbox |
||
22 | * @param string $body Bounce Mail Body |
||
23 | * @param string $headerFull Bounce Mail Header |
||
24 | * @param string $bodyFull Bounce Mail Body (full) |
||
25 | * |
||
26 | * @return bool |
||
27 | */ |
||
28 | function callbackAction($msgnum, $bounceType, $email, $subject, $xheader, $remove, $ruleNo = false, $ruleCat = false, $totalFetched = 0, $body = '', $headerFull = '', $bodyFull = ''): bool |
||
0 ignored issues
–
show
|
|||
29 | { |
||
30 | $displayData = prepData($email, $bounceType, $remove); |
||
31 | $bounceType = $displayData['bounce_type']; |
||
32 | $emailName = $displayData['emailName']; |
||
0 ignored issues
–
show
$emailName 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
Loading history...
|
|||
33 | $emailAddy = $displayData['emailAddy']; |
||
0 ignored issues
–
show
$emailAddy 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
Loading history...
|
|||
34 | $remove = $displayData['remove']; |
||
35 | echo $msgnum . ': ' . $ruleNo . ' | ' . $ruleCat . ' | ' . $bounceType . ' | ' . $remove . ' | ' . $email . ' | ' . $subject . "<br />\n"; |
||
36 | |||
37 | return true; |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * Function to clean the data from the Callback Function for optimized display |
||
42 | * |
||
43 | * @param $email |
||
44 | * @param $bounceType |
||
45 | * @param $remove |
||
46 | * |
||
47 | * @return mixed |
||
48 | */ |
||
49 | View Code Duplication | function prepData($email, $bounceType, $remove) |
|
0 ignored issues
–
show
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...
The function
prepData() has been defined more than once; this definition is ignored, only the first definition in examples/callback_csv.php (L78-125) is considered.
This check looks for functions that have already been defined in other files. Some Codebases, like WordPress, make a practice of defining functions multiple times. This
may lead to problems with the detection of function parameters and types. If you really
need to do this, you can mark the duplicate definition with the /**
* @ignore
*/
function getUser() {
}
function getUser($id, $realm) {
}
See also the PhpDoc documentation for @ignore.
Loading history...
|
|||
50 | { |
||
51 | $data['bounce_type'] = \trim($bounceType); |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.
Loading history...
|
|||
52 | $data['email'] = ''; |
||
53 | $data['emailName'] = ''; |
||
54 | $data['emailAddy'] = ''; |
||
55 | $data['remove'] = ''; |
||
56 | if (\strpos($email, '<') !== false) { |
||
57 | $pos_start = \strpos($email, '<'); |
||
58 | $data['emailName'] = \trim(\substr($email, 0, $pos_start)); |
||
59 | $data['emailAddy'] = \substr($email, $pos_start + 1); |
||
60 | $pos_end = \strpos($data['emailAddy'], '>'); |
||
61 | |||
62 | if ($pos_end) { |
||
63 | $data['emailAddy'] = \substr($data['emailAddy'], 0, $pos_end); |
||
64 | } |
||
65 | } |
||
66 | |||
67 | // replace the < and > able so they display on screen |
||
68 | $email = \str_replace(['<', '>'], ['<', '>'], $email); |
||
69 | |||
70 | // replace the "TO:<" with nothing |
||
71 | $email = \str_ireplace('TO:<', '', $email); |
||
72 | |||
73 | $data['email'] = $email; |
||
74 | |||
75 | // account for legitimate emails that have no bounce type |
||
76 | if (\trim($bounceType) == '') { |
||
77 | $data['bounce_type'] = 'none'; |
||
78 | } |
||
79 | |||
80 | // change the remove flag from true or 1 to textual representation |
||
81 | if (\stripos($remove, 'moved') !== false && \stripos($remove, 'hard') !== false) { |
||
82 | $data['removestat'] = 'moved (hard)'; |
||
83 | $data['remove'] = '<span style="color:red;">' . 'moved (hard)' . '</span>'; |
||
84 | } elseif (\stripos($remove, 'moved') !== false && \stripos($remove, 'soft') !== false) { |
||
85 | $data['removestat'] = 'moved (soft)'; |
||
86 | $data['remove'] = '<span style="color:gray;">' . 'moved (soft)' . '</span>'; |
||
87 | } elseif ($remove == true || $remove == '1') { |
||
88 | $data['removestat'] = 'deleted'; |
||
89 | $data['remove'] = '<span style="color:red;">' . 'deleted' . '</span>'; |
||
90 | } else { |
||
91 | $data['removestat'] = 'not deleted'; |
||
92 | $data['remove'] = '<span style="color:gray;">' . 'not deleted' . '</span>'; |
||
93 | } |
||
94 | |||
95 | return $data; |
||
96 | } |
||
97 |
This check looks for functions that have already been defined in other files.
Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the
@ignore
annotation.See also the PhpDoc documentation for @ignore.