diff --git a/src/Email/Body.php b/src/Email/Body.php index 716dfd5201..8fc0a0ba6a 100644 --- a/src/Email/Body.php +++ b/src/Email/Body.php @@ -19,20 +19,11 @@ class Body { use Properties; - /** - * @var string - */ - protected $html; - - /** - * @var string - */ - protected $text; + protected string|null $html = null; + protected string|null $text = null; /** * Email body constructor - * - * @param array $props */ public function __construct(array $props = []) { @@ -41,20 +32,16 @@ public function __construct(array $props = []) /** * Returns the HTML content of the email body - * - * @return string */ - public function html() + public function html(): string { return $this->html ?? ''; } /** * Returns the plain text content of the email body - * - * @return string */ - public function text() + public function text(): string { return $this->text ?? ''; } @@ -62,10 +49,9 @@ public function text() /** * Sets the HTML content for the email body * - * @param string|null $html * @return $this */ - protected function setHtml(string $html = null) + protected function setHtml(string|null $html = null): static { $this->html = $html; return $this; @@ -74,10 +60,9 @@ protected function setHtml(string $html = null) /** * Sets the plain text content for the email body * - * @param string|null $text * @return $this */ - protected function setText(string $text = null) + protected function setText(string|null $text = null): static { $this->text = $text; return $this; diff --git a/src/Email/Email.php b/src/Email/Email.php index 9fbbb89029..bd34870244 100644 --- a/src/Email/Email.php +++ b/src/Email/Email.php @@ -24,89 +24,31 @@ class Email /** * If set to `true`, the debug mode is enabled * for all emails - * - * @var bool */ - public static $debug = false; + public static bool $debug = false; /** * Store for sent emails when `Email::$debug` * is set to `true` - * - * @var array - */ - public static $emails = []; - - /** - * @var array|null - */ - protected $attachments; - - /** - * @var \Kirby\Email\Body|null - */ - protected $body; - - /** - * @var array|null - */ - protected $bcc; - - /** - * @var \Closure|null - */ - protected $beforeSend; - - /** - * @var array|null - */ - protected $cc; - - /** - * @var string|null - */ - protected $from; - - /** - * @var string|null - */ - protected $fromName; - - /** - * @var string|null - */ - protected $replyTo; - - /** - * @var string|null */ - protected $replyToName; + public static array $emails = []; - /** - * @var bool - */ - protected $isSent = false; - - /** - * @var string|null - */ - protected $subject; - - /** - * @var array|null - */ - protected $to; - - /** - * @var array|null - */ - protected $transport; + protected array|null $attachments = null; + protected Body|null $body = null; + protected array|null $bcc = null; + protected Closure|null $beforeSend = null; + protected array|null $cc = null; + protected string|null $from = null; + protected string|null $fromName = null; + protected string|null $replyTo = null; + protected string|null $replyToName = null; + protected bool $isSent = false; + protected string|null $subject = null; + protected array|null $to = null; + protected array|null $transport = null; /** * Email constructor - * - * @param array $props - * @param bool $debug */ public function __construct(array $props = [], bool $debug = false) { @@ -123,8 +65,6 @@ public function __construct(array $props = [], bool $debug = false) /** * Returns the email attachments - * - * @return array */ public function attachments(): array { @@ -133,18 +73,14 @@ public function attachments(): array /** * Returns the email body - * - * @return \Kirby\Email\Body|null */ - public function body() + public function body(): Body|null { return $this->body; } /** * Returns "bcc" recipients - * - * @return array */ public function bcc(): array { @@ -154,8 +90,6 @@ public function bcc(): array /** * Returns the beforeSend callback closure, * which has access to the PHPMailer instance - * - * @return \Closure|null */ public function beforeSend(): Closure|null { @@ -164,8 +98,6 @@ public function beforeSend(): Closure|null /** * Returns "cc" recipients - * - * @return array */ public function cc(): array { @@ -174,8 +106,6 @@ public function cc(): array /** * Returns default transport settings - * - * @return array */ protected function defaultTransport(): array { @@ -186,8 +116,6 @@ protected function defaultTransport(): array /** * Returns the "from" email address - * - * @return string */ public function from(): string { @@ -196,8 +124,6 @@ public function from(): string /** * Returns the "from" name - * - * @return string|null */ public function fromName(): string|null { @@ -206,18 +132,14 @@ public function fromName(): string|null /** * Checks if the email has an HTML body - * - * @return bool */ - public function isHtml() + public function isHtml(): bool { return empty($this->body()->html()) === false; } /** * Checks if the email has been sent successfully - * - * @return bool */ public function isSent(): bool { @@ -226,8 +148,6 @@ public function isSent(): bool /** * Returns the "reply to" email address - * - * @return string */ public function replyTo(): string { @@ -236,8 +156,6 @@ public function replyTo(): string /** * Returns the "reply to" name - * - * @return string|null */ public function replyToName(): string|null { @@ -247,13 +165,12 @@ public function replyToName(): string|null /** * Converts single or multiple email addresses to a sanitized format * - * @param string|array|null $email - * @param bool $multiple - * @return array|mixed|string * @throws \Exception */ - protected function resolveEmail($email = null, bool $multiple = true) - { + protected function resolveEmail( + string|array|null $email = null, + bool $multiple = true + ): array|string { if ($email === null) { return $multiple === true ? [] : ''; } @@ -284,8 +201,6 @@ protected function resolveEmail($email = null, bool $multiple = true) /** * Sends the email - * - * @return bool */ public function send(): bool { @@ -295,10 +210,9 @@ public function send(): bool /** * Sets the email attachments * - * @param array|null $attachments * @return $this */ - protected function setAttachments($attachments = null) + protected function setAttachments(array|null $attachments = null): static { $this->attachments = $attachments ?? []; return $this; @@ -307,10 +221,9 @@ protected function setAttachments($attachments = null) /** * Sets the email body * - * @param string|array $body * @return $this */ - protected function setBody($body) + protected function setBody(string|array $body): static { if (is_string($body) === true) { $body = ['text' => $body]; @@ -323,10 +236,9 @@ protected function setBody($body) /** * Sets "bcc" recipients * - * @param string|array|null $bcc * @return $this */ - protected function setBcc($bcc = null) + protected function setBcc(string|array|null $bcc = null): static { $this->bcc = $this->resolveEmail($bcc); return $this; @@ -335,10 +247,9 @@ protected function setBcc($bcc = null) /** * Sets the "beforeSend" callback * - * @param \Closure|null $beforeSend * @return $this */ - protected function setBeforeSend(Closure|null $beforeSend = null) + protected function setBeforeSend(Closure|null $beforeSend = null): static { $this->beforeSend = $beforeSend; return $this; @@ -347,10 +258,9 @@ protected function setBeforeSend(Closure|null $beforeSend = null) /** * Sets "cc" recipients * - * @param string|array|null $cc * @return $this */ - protected function setCc($cc = null) + protected function setCc(string|array|null $cc = null): static { $this->cc = $this->resolveEmail($cc); return $this; @@ -359,10 +269,9 @@ protected function setCc($cc = null) /** * Sets the "from" email address * - * @param string $from * @return $this */ - protected function setFrom(string $from) + protected function setFrom(string $from): static { $this->from = $this->resolveEmail($from, false); return $this; @@ -371,10 +280,9 @@ protected function setFrom(string $from) /** * Sets the "from" name * - * @param string|null $fromName * @return $this */ - protected function setFromName(string $fromName = null) + protected function setFromName(string|null $fromName = null): static { $this->fromName = $fromName; return $this; @@ -383,10 +291,9 @@ protected function setFromName(string $fromName = null) /** * Sets the "reply to" email address * - * @param string|null $replyTo * @return $this */ - protected function setReplyTo(string $replyTo = null) + protected function setReplyTo(string|null $replyTo = null): static { $this->replyTo = $this->resolveEmail($replyTo, false); return $this; @@ -395,10 +302,9 @@ protected function setReplyTo(string $replyTo = null) /** * Sets the "reply to" name * - * @param string|null $replyToName * @return $this */ - protected function setReplyToName(string $replyToName = null) + protected function setReplyToName(string|null $replyToName = null): static { $this->replyToName = $replyToName; return $this; @@ -407,10 +313,9 @@ protected function setReplyToName(string $replyToName = null) /** * Sets the email subject * - * @param string $subject * @return $this */ - protected function setSubject(string $subject) + protected function setSubject(string $subject): static { $this->subject = $subject; return $this; @@ -419,10 +324,9 @@ protected function setSubject(string $subject) /** * Sets the recipients of the email * - * @param string|array $to * @return $this */ - protected function setTo($to) + protected function setTo(string|array $to): static { $this->to = $this->resolveEmail($to); return $this; @@ -431,10 +335,9 @@ protected function setTo($to) /** * Sets the email transport settings * - * @param array|null $transport * @return $this */ - protected function setTransport($transport = null) + protected function setTransport(array|null $transport = null): static { $this->transport = $transport; return $this; @@ -442,8 +345,6 @@ protected function setTransport($transport = null) /** * Returns the email subject - * - * @return string */ public function subject(): string { @@ -452,8 +353,6 @@ public function subject(): string /** * Returns the email recipients - * - * @return array */ public function to(): array { @@ -462,8 +361,6 @@ public function to(): array /** * Returns the email transports settings - * - * @return array */ public function transport(): array { diff --git a/src/Email/PHPMailer.php b/src/Email/PHPMailer.php index 5f43647aef..ee84a40405 100644 --- a/src/Email/PHPMailer.php +++ b/src/Email/PHPMailer.php @@ -21,8 +21,6 @@ class PHPMailer extends Email /** * Sends email via PHPMailer library * - * @param bool $debug - * @return bool * @throws \Kirby\Exception\InvalidArgumentException */ public function send(bool $debug = false): bool