Skip to content

Commit a577705

Browse files
committed
add the isSMTPConnected() method for a type-safe check
1 parent cc7f32f commit a577705

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

system/Email/Email.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,7 +1886,7 @@ protected function SMTPEnd()
18861886
*/
18871887
protected function SMTPConnect()
18881888
{
1889-
if (is_resource($this->SMTPConnect)) {
1889+
if ($this->isSMTPConnected()) {
18901890
return true;
18911891
}
18921892

@@ -1910,7 +1910,7 @@ protected function SMTPConnect()
19101910
$this->SMTPTimeout,
19111911
);
19121912

1913-
if (! is_resource($this->SMTPConnect)) {
1913+
if (! $this->isSMTPConnected()) {
19141914
$this->setErrorMessage(lang('Email.SMTPError', [$errno . ' ' . $errstr]));
19151915

19161916
return false;
@@ -2227,7 +2227,7 @@ protected function mimeTypes($ext = '')
22272227

22282228
public function __destruct()
22292229
{
2230-
if (is_resource($this->SMTPConnect)) {
2230+
if ($this->isSMTPConnected()) {
22312231
try {
22322232
$this->sendCommand('quit');
22332233
} catch (ErrorException $e) {
@@ -2284,4 +2284,14 @@ protected function setArchiveValues(): array
22842284

22852285
return $this->archive;
22862286
}
2287+
2288+
/**
2289+
* Checks if there is an active SMTP connection.
2290+
*
2291+
* @return bool True if SMTP connection is established and open, false otherwise
2292+
*/
2293+
protected function isSMTPConnected(): bool
2294+
{
2295+
return $this->SMTPConnect !== null && get_debug_type($this->SMTPConnect) !== 'resource (closed)';
2296+
}
22872297
}

0 commit comments

Comments
 (0)