From: Reedy Date: Sat, 20 Oct 2018 22:31:00 +0000 (+0100) Subject: MailAddress->toString(): Reduce complexity by inverting ifs X-Git-Tag: 1.34.0-rc.0~3657^2 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=da9c742af04791e52f0e4552d3a77a55b558f088 MailAddress->toString(): Reduce complexity by inverting ifs Change-Id: I5185c0231a0944f36d960211e78cf36273c94d52 --- diff --git a/includes/mail/MailAddress.php b/includes/mail/MailAddress.php index 000bbe316b..63a114d2a9 100644 --- a/includes/mail/MailAddress.php +++ b/includes/mail/MailAddress.php @@ -50,7 +50,7 @@ class MailAddress { * @param string|null $name Human-readable name if a string address is given * @param string|null $realName Human-readable real name if a string address is given */ - function __construct( $address, $name = null, $realName = null ) { + public function __construct( $address, $name = null, $realName = null ) { $this->address = strval( $address ); $this->name = strval( $name ); $this->realName = strval( $realName ); @@ -72,25 +72,26 @@ class MailAddress { * @return string */ function toString() { + if ( !$this->address ) { + return ''; + } + # PHP's mail() implementation under Windows is somewhat shite, and # can't handle "Joe Bloggs " format email addresses, # so don't bother generating them - if ( $this->address ) { - if ( $this->name != '' && !wfIsWindows() ) { - global $wgEnotifUseRealName; - $name = ( $wgEnotifUseRealName && $this->realName !== '' ) ? $this->realName : $this->name; - $quoted = UserMailer::quotedPrintable( $name ); - // Must only be quoted if string does not use =? encoding (T191931) - if ( $quoted === $name ) { - $quoted = '"' . addslashes( $quoted ) . '"'; - } - return "$quoted <{$this->address}>"; - } else { - return $this->address; - } - } else { - return ""; + if ( $this->name === '' || wfIsWindows() ) { + return $this->address; } + + global $wgEnotifUseRealName; + $name = ( $wgEnotifUseRealName && $this->realName !== '' ) ? $this->realName : $this->name; + $quoted = UserMailer::quotedPrintable( $name ); + // Must only be quoted if string does not use =? encoding (T191931) + if ( $quoted === $name ) { + $quoted = '"' . addslashes( $quoted ) . '"'; + } + + return "$quoted <{$this->address}>"; } function __toString() {