diff --git a/system/Email/Email.php b/system/Email/Email.php index 2a0facc0ca08..727419832c62 100644 --- a/system/Email/Email.php +++ b/system/Email/Email.php @@ -68,7 +68,7 @@ class Email /** * Which method to use for sending e-mails. * - * @var string 'mail', 'sendmail' or 'smtp' + * @var 'mail'|'sendmail'|'smtp' */ public $protocol = 'mail'; @@ -117,9 +117,11 @@ class Email /** * SMTP Encryption * - * @var string '', 'tls' or 'ssl'. 'tls' will issue a STARTTLS command - * to the server. 'ssl' means implicit SSL. Connection on port - * 465 should set this to ''. + * * `tls` - will issue a STARTTLS command to the server + * * `ssl` - means implicit SSL + * * `''` - for connection on port 465 + * + * @var ''|'ssl'|'tls' */ public $SMTPCrypto = ''; @@ -142,7 +144,7 @@ class Email /** * Message format. * - * @var string 'text' or 'html' + * @var 'html'|'text' */ public $mailType = 'text'; @@ -170,7 +172,7 @@ class Email /** * X-Priority header value. * - * @var int 1-5 + * @var int<1, 5> */ public $priority = 3; @@ -180,7 +182,7 @@ class Email * * @see http://www.ietf.org/rfc/rfc822.txt * - * @var string "\r\n" or "\n" + * @var "\r\n"|"n" */ public $newline = "\r\n"; @@ -195,7 +197,7 @@ class Email * * @see http://www.ietf.org/rfc/rfc822.txt * - * @var string + * @var "\r\n"|"n" */ public $CRLF = "\r\n"; @@ -268,7 +270,7 @@ class Email /** * Mail encoding * - * @var string '8bit' or '7bit' + * @var '7bit'|'8bit' */ protected $encoding = '8bit'; @@ -342,7 +344,7 @@ class Email * * @see Email::$protocol * - * @var array + * @var list */ protected $protocols = [ 'mail', @@ -368,7 +370,7 @@ class Email * * @see Email::$encoding * - * @var array + * @var list */ protected $bitDepths = [ '7bit', @@ -380,7 +382,7 @@ class Email * * Actual values to send with the X-Priority header * - * @var array + * @var array */ protected $priorities = [ 1 => '1 (Highest)', @@ -414,7 +416,7 @@ public function __construct($config = null) * * @param array|\Config\Email|null $config * - * @return Email + * @return $this */ public function initialize($config) { @@ -445,7 +447,7 @@ public function initialize($config) /** * @param bool $clearAttachments * - * @return Email + * @return $this */ public function clear($clearAttachments = false) { @@ -463,7 +465,7 @@ public function clear($clearAttachments = false) $this->setHeader('Date', $this->setDate()); - if ($clearAttachments !== false) { + if ($clearAttachments) { $this->attachments = []; } @@ -473,13 +475,13 @@ public function clear($clearAttachments = false) /** * @param string $from * @param string $name - * @param string|null $returnPath Return-Path + * @param string|null $returnPath * - * @return Email + * @return $this */ public function setFrom($from, $name = '', $returnPath = null) { - if (preg_match('/\<(.*)\>/', $from, $match)) { + if (preg_match('/\<(.*)\>/', $from, $match) === 1) { $from = $match[1]; } @@ -504,9 +506,8 @@ public function setFrom($from, $name = '', $returnPath = null) } $this->setHeader('From', $name . ' <' . $from . '>'); - if (! isset($returnPath)) { - $returnPath = $from; - } + $returnPath ??= $from; + $this->setHeader('Return-Path', '<' . $returnPath . '>'); $this->tmpArchive['returnPath'] = $returnPath; @@ -517,11 +518,11 @@ public function setFrom($from, $name = '', $returnPath = null) * @param string $replyto * @param string $name * - * @return Email + * @return $this */ public function setReplyTo($replyto, $name = '') { - if (preg_match('/\<(.*)\>/', $replyto, $match)) { + if (preg_match('/\<(.*)\>/', $replyto, $match) === 1) { $replyto = $match[1]; } @@ -550,7 +551,7 @@ public function setReplyTo($replyto, $name = '') /** * @param array|string $to * - * @return Email + * @return $this */ public function setTo($to) { @@ -573,7 +574,7 @@ public function setTo($to) /** * @param string $cc * - * @return Email + * @return $this */ public function setCC($cc) { @@ -598,7 +599,7 @@ public function setCC($cc) * @param string $bcc * @param string $limit * - * @return Email + * @return $this */ public function setBCC($bcc, $limit = '') { @@ -626,7 +627,7 @@ public function setBCC($bcc, $limit = '') /** * @param string $subject * - * @return Email + * @return $this */ public function setSubject($subject) { @@ -641,7 +642,7 @@ public function setSubject($subject) /** * @param string $body * - * @return Email + * @return $this */ public function setMessage($body) { @@ -734,7 +735,7 @@ public function setAttachmentCID($filename) * @param string $header * @param string $value * - * @return Email + * @return $this */ public function setHeader($header, $value) { @@ -744,14 +745,16 @@ public function setHeader($header, $value) } /** - * @param array|string $email + * @param list|string $email * - * @return array + * @return list */ protected function stringToArray($email) { if (! is_array($email)) { - return (str_contains($email, ',')) ? preg_split('/[\s,]/', $email, -1, PREG_SPLIT_NO_EMPTY) : (array) trim($email); + return str_contains($email, ',') + ? preg_split('/[\s,]/', $email, -1, PREG_SPLIT_NO_EMPTY) + : (array) trim($email); } return $email; @@ -760,7 +763,7 @@ protected function stringToArray($email) /** * @param string $str * - * @return Email + * @return $this */ public function setAltMessage($str) { @@ -772,11 +775,11 @@ public function setAltMessage($str) /** * @param string $type * - * @return Email + * @return $this */ public function setMailType($type = 'text') { - $this->mailType = ($type === 'html') ? 'html' : 'text'; + $this->mailType = $type === 'html' ? 'html' : 'text'; return $this; } @@ -784,7 +787,7 @@ public function setMailType($type = 'text') /** * @param bool $wordWrap * - * @return Email + * @return $this */ public function setWordWrap($wordWrap = true) { @@ -796,7 +799,7 @@ public function setWordWrap($wordWrap = true) /** * @param string $protocol * - * @return Email + * @return $this */ public function setProtocol($protocol = 'mail') { @@ -808,7 +811,7 @@ public function setProtocol($protocol = 'mail') /** * @param int $n * - * @return Email + * @return $this */ public function setPriority($n = 3) { @@ -820,7 +823,7 @@ public function setPriority($n = 3) /** * @param string $newline * - * @return Email + * @return $this */ public function setNewline($newline = "\n") { @@ -832,11 +835,11 @@ public function setNewline($newline = "\n") /** * @param string $CRLF * - * @return Email + * @return $this */ public function setCRLF($CRLF = "\n") { - $this->CRLF = ($CRLF !== "\n" && $CRLF !== "\r\n" && $CRLF !== "\r") ? "\n" : $CRLF; + $this->CRLF = ! in_array($CRLF, ["\n", "\r\n", "\r"], true) ? "\n" : $CRLF; return $this; } @@ -891,10 +894,10 @@ protected function getEncoding() protected function getContentType() { if ($this->mailType === 'html') { - return empty($this->attachments) ? 'html' : 'html-attach'; + return $this->attachments === [] ? 'html' : 'html-attach'; } - if ($this->mailType === 'text' && ! empty($this->attachments)) { + if ($this->mailType === 'text' && $this->attachments !== []) { return 'plain-attach'; } @@ -996,8 +999,8 @@ public function cleanEmail($email) */ protected function getAltMessage() { - if (! empty($this->altMessage)) { - return ($this->wordWrap) ? $this->wordWrap($this->altMessage, 76) : $this->altMessage; + if ($this->altMessage !== '') { + return $this->wordWrap ? $this->wordWrap($this->altMessage, 76) : $this->altMessage; } $body = preg_match('/\(.*)\<\/body\>/si', $this->body, $match) ? $match[1] : $this->body; @@ -1009,7 +1012,7 @@ protected function getAltMessage() $body = preg_replace('| +|', ' ', $body); - return ($this->wordWrap) ? $this->wordWrap($body, 76) : $body; + return $this->wordWrap ? $this->wordWrap($body, 76) : $body; } /** @@ -1020,8 +1023,10 @@ protected function getAltMessage() */ public function wordWrap($str, $charlim = null) { - if (empty($charlim)) { - $charlim = empty($this->wrapChars) ? 76 : $this->wrapChars; + $charlim ??= 0; + + if ($charlim === 0) { + $charlim = $this->wrapChars === 0 ? 76 : $this->wrapChars; } if (str_contains($str, "\r")) { @@ -1269,13 +1274,13 @@ protected function buildMessage() } /** - * @param mixed $type + * @param string $type * * @return bool */ protected function attachmentsHaveMultipart($type) { - foreach ($this->attachments as &$attachment) { + foreach ($this->attachments as $attachment) { if ($attachment['multipart'] === $type) { return true; } @@ -1303,14 +1308,14 @@ protected function appendAttachments(&$body, $boundary, $multipart = null) . 'Content-Type: ' . $attachment['type'] . '; name="' . $name . '"' . $this->newline . 'Content-Disposition: ' . $attachment['disposition'] . ';' . $this->newline . 'Content-Transfer-Encoding: base64' . $this->newline - . (empty($attachment['cid']) ? '' : 'Content-ID: <' . $attachment['cid'] . '>' . $this->newline) + . ($attachment['cid'] === '' ? '' : 'Content-ID: <' . $attachment['cid'] . '>' . $this->newline) . $this->newline . $attachment['content'] . $this->newline; } // $name won't be set if no attachments were appended, // and therefore a boundary wouldn't be necessary - if (! empty($name)) { + if (isset($name)) { $body .= '--' . $boundary . '--'; } } @@ -2218,7 +2223,7 @@ protected function mimeTypes($ext = '') public function __destruct() { - if (is_resource($this->SMTPConnect)) { + if ($this->SMTPConnect !== null) { try { $this->sendCommand('quit'); } catch (ErrorException $e) { diff --git a/utils/phpstan-baseline/empty.notAllowed.neon b/utils/phpstan-baseline/empty.notAllowed.neon index ebcb9dafe4e1..91a3123c5d6c 100644 --- a/utils/phpstan-baseline/empty.notAllowed.neon +++ b/utils/phpstan-baseline/empty.notAllowed.neon @@ -1,4 +1,4 @@ -# total 247 errors +# total 240 errors parameters: ignoreErrors: @@ -184,7 +184,7 @@ parameters: - message: '#^Construct empty\(\) is not allowed\. Use more strict comparison\.$#' - count: 12 + count: 5 path: ../../system/Email/Email.php - diff --git a/utils/phpstan-baseline/loader.neon b/utils/phpstan-baseline/loader.neon index 9edbf37e3bc2..5c7183708c35 100644 --- a/utils/phpstan-baseline/loader.neon +++ b/utils/phpstan-baseline/loader.neon @@ -1,4 +1,4 @@ -# total 3161 errors +# total 3149 errors includes: - argument.type.neon - assign.propertyType.neon diff --git a/utils/phpstan-baseline/missingType.iterableValue.neon b/utils/phpstan-baseline/missingType.iterableValue.neon index c0eff3f00d6d..9e13a5c4ff23 100644 --- a/utils/phpstan-baseline/missingType.iterableValue.neon +++ b/utils/phpstan-baseline/missingType.iterableValue.neon @@ -1,4 +1,4 @@ -# total 1547 errors +# total 1542 errors parameters: ignoreErrors: @@ -2552,16 +2552,6 @@ parameters: count: 1 path: ../../system/Email/Email.php - - - message: '#^Method CodeIgniter\\Email\\Email\:\:stringToArray\(\) has parameter \$email with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Email/Email.php - - - - message: '#^Method CodeIgniter\\Email\\Email\:\:stringToArray\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Email/Email.php - - message: '#^Method CodeIgniter\\Email\\Email\:\:validateEmail\(\) has parameter \$email with no value type specified in iterable type array\.$#' count: 1 @@ -2587,11 +2577,6 @@ parameters: count: 1 path: ../../system/Email/Email.php - - - message: '#^Property CodeIgniter\\Email\\Email\:\:\$bitDepths type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Email/Email.php - - message: '#^Property CodeIgniter\\Email\\Email\:\:\$debugMessage type has no value type specified in iterable type array\.$#' count: 1 @@ -2602,16 +2587,6 @@ parameters: count: 1 path: ../../system/Email/Email.php - - - message: '#^Property CodeIgniter\\Email\\Email\:\:\$priorities type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Email/Email.php - - - - message: '#^Property CodeIgniter\\Email\\Email\:\:\$protocols type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Email/Email.php - - message: '#^Property CodeIgniter\\Email\\Email\:\:\$recipients type has no value type specified in iterable type array\.$#' count: 1