-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
clean code #36179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
clean code #36179
Conversation
| * @var ?int $hidedesc | ||
| * @var ?int $hideref | ||
| * @var ?array<string,mixed> $moreparams | ||
| * @var ?string $from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Defining $from as a predefined value does not seem correct.
$from may not be defined because we have
dolibarr/htdocs/core/actions_massactions.inc.php
Lines 501 to 503 in cec3c62
| if ($obj) { | |
| $from = dol_string_nospecial($obj->label, ' ', array(",")).' <'.$obj->email.'>'; | |
| } |
if ($obj) { $from = ... }) in one of the conditions and then $from is not defined when using it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😕
Bigger picture:
dolibarr/htdocs/core/actions_massactions.inc.php
Lines 487 to 508 in cec3c62
if ($fromtype === 'user') { $from = dol_string_nospecial($user->getFullName($langs), ' ', array(",")).' <'.$user->email.'>'; } elseif ($fromtype === 'company') { $from = getDolGlobalString('MAIN_INFO_SOCIETE_NOM') . ' <' . getDolGlobalString('MAIN_INFO_SOCIETE_MAIL').'>'; } elseif (preg_match('/user_aliases_(\d+)/', $fromtype, $reg)) { $tmp = explode(',', $user->email_aliases); $from = trim($tmp[((int) $reg[1] - 1)]); } elseif (preg_match('/global_aliases_(\d+)/', $fromtype, $reg)) { $tmp = explode(',', getDolGlobalString('MAIN_INFO_SOCIETE_MAIL_ALIASES')); $from = trim($tmp[((int) $reg[1] - 1)]); } elseif (preg_match('/senderprofile_(\d+)_(\d+)/', $fromtype, $reg)) { $sql = "SELECT rowid, label, email FROM ".MAIN_DB_PREFIX."c_email_senderprofile WHERE rowid = ".(int) $reg[1]; $resql = $db->query($sql); $obj = $db->fetch_object($resql); if ($obj) { $from = dol_string_nospecial($obj->label, ' ', array(",")).' <'.$obj->email.'>'; } } else { $from = GETPOST('fromname').' <'.GETPOST('frommail').'>'; } $replyto = $from;
After the if/elseif sequence, $from may not be defined.
One method would be:
$from = null;
if (...) ... else if() .. .
if ($from === null) {
$from = GETPOST('fromname').' <'.GETPOST('frommail').'>';
}or
$from = GETPOST('fromname').' <'.GETPOST('frommail').'>';
if (...) ... else if() .. .And remove
| * @var ?string $from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line 75 was removed
* clean code * clean code * fix * fix * fix * fix * fix --------- Co-authored-by: Laurent Destailleur <[email protected]>
No description provided.