Clean up missing or inconsistent types in Mail, SMS, Push classes

This commit is contained in:
Kijin Sung 2023-10-03 15:05:06 +09:00
parent 7c844c7e24
commit 27c8d32dc5
4 changed files with 121 additions and 108 deletions

View file

@ -27,10 +27,10 @@ class Mail
/** /**
* Set the default driver. * Set the default driver.
* *
* @param object $driver * @param Drivers\MailInterface $driver
* @return void * @return void
*/ */
public static function setDefaultDriver(Drivers\MailInterface $driver) public static function setDefaultDriver(Drivers\MailInterface $driver): void
{ {
self::$default_driver = $driver; self::$default_driver = $driver;
} }
@ -38,9 +38,9 @@ class Mail
/** /**
* Get the default driver. * Get the default driver.
* *
* @return object * @return Drivers\MailInterface
*/ */
public static function getDefaultDriver() public static function getDefaultDriver(): Drivers\MailInterface
{ {
if (!self::$default_driver) if (!self::$default_driver)
{ {
@ -61,8 +61,11 @@ class Mail
/** /**
* Add a custom mail driver. * Add a custom mail driver.
*
* @param Drivers\MailInterface $driver
* @return void
*/ */
public static function addDriver(Drivers\MailInterface $driver) public static function addDriver(Drivers\MailInterface $driver): void
{ {
self::$custom_drivers[] = $driver; self::$custom_drivers[] = $driver;
} }
@ -72,7 +75,7 @@ class Mail
* *
* @return array * @return array
*/ */
public static function getSupportedDrivers() public static function getSupportedDrivers(): array
{ {
$result = array(); $result = array();
foreach (Storage::readDirectory(__DIR__ . '/drivers/mail', false) as $filename) foreach (Storage::readDirectory(__DIR__ . '/drivers/mail', false) as $filename)
@ -123,7 +126,7 @@ class Mail
* @param string $name Name (optional) * @param string $name Name (optional)
* @return bool * @return bool
*/ */
public function setFrom($email, $name = null) public function setFrom(string $email, ?string $name = null): bool
{ {
try try
{ {
@ -142,7 +145,7 @@ class Mail
* *
* @return string|null * @return string|null
*/ */
public function getFrom() public function getFrom(): ?string
{ {
$list = $this->message->getFrom(); $list = $this->message->getFrom();
return $list ? array_first($this->formatAddresses($list)) : null; return $list ? array_first($this->formatAddresses($list)) : null;
@ -155,7 +158,7 @@ class Mail
* @param string $name Name (optional) * @param string $name Name (optional)
* @return bool * @return bool
*/ */
public function addTo($email, $name = null) public function addTo(string $email, ?string $name = null): bool
{ {
try try
{ {
@ -176,7 +179,7 @@ class Mail
* @param string $name Name (optional) * @param string $name Name (optional)
* @return bool * @return bool
*/ */
public function addCc($email, $name = null) public function addCc(string $email, ?string $name = null): bool
{ {
try try
{ {
@ -197,7 +200,7 @@ class Mail
* @param string $name Name (optional) * @param string $name Name (optional)
* @return bool * @return bool
*/ */
public function addBcc($email, $name = null) public function addBcc(string $email, ?string $name = null): bool
{ {
try try
{ {
@ -214,21 +217,21 @@ class Mail
/** /**
* Get the list of recipients. * Get the list of recipients.
* *
* @return array(); * @return array
*/ */
public function getRecipients() public function getRecipients(): array
{ {
$result = array(); $result = array();
foreach ($this->formatAddresses($this->message->getTo()) as $address) foreach ($this->formatAddresses($this->message->getTo() ?: []) as $address)
{ {
$result[] = $address; $result[] = $address;
} }
foreach ($this->formatAddresses($this->message->getCc()) as $address) foreach ($this->formatAddresses($this->message->getCc() ?: []) as $address)
{ {
$result[] = $address; $result[] = $address;
} }
foreach ($this->formatAddresses($this->message->getBcc()) as $address) foreach ($this->formatAddresses($this->message->getBcc() ?: []) as $address)
{ {
$result[] = $address; $result[] = $address;
} }
@ -242,7 +245,7 @@ class Mail
* @param string $replyTo * @param string $replyTo
* @return bool * @return bool
*/ */
public function setReplyTo($replyTo) public function setReplyTo(string $replyTo): bool
{ {
try try
{ {
@ -262,7 +265,7 @@ class Mail
* @param string $returnPath * @param string $returnPath
* @return bool * @return bool
*/ */
public function setReturnPath($returnPath) public function setReturnPath(string $returnPath): bool
{ {
try try
{ {
@ -279,15 +282,15 @@ class Mail
/** /**
* Set the Message ID. * Set the Message ID.
* *
* @param string $messageId * @param string $message_id
* @return bool * @return bool
*/ */
public function setMessageID($messageId) public function setMessageID(string $message_id): bool
{ {
try try
{ {
$headers = $this->message->getHeaders(); $headers = $this->message->getHeaders();
$headers->get('Message-ID')->setId($messageId); $headers->get('Message-ID')->setId($message_id);
return true; return true;
} }
catch (\Exception $e) catch (\Exception $e)
@ -300,15 +303,15 @@ class Mail
/** /**
* Set the In-Reply-To: header. * Set the In-Reply-To: header.
* *
* @param string $inReplyTo * @param string $in_reply_to
* @return bool * @return bool
*/ */
public function setInReplyTo($inReplyTo) public function setInReplyTo(string $in_reply_to): bool
{ {
try try
{ {
$headers = $this->message->getHeaders(); $headers = $this->message->getHeaders();
$headers->addTextHeader('In-Reply-To', $inReplyTo); $headers->addTextHeader('In-Reply-To', $in_reply_to);
return true; return true;
} }
catch (\Exception $e) catch (\Exception $e)
@ -324,7 +327,7 @@ class Mail
* @param string $references * @param string $references
* @return bool * @return bool
*/ */
public function setReferences($references) public function setReferences(string $references): bool
{ {
try try
{ {
@ -345,11 +348,11 @@ class Mail
* @param string $subject * @param string $subject
* @return bool * @return bool
*/ */
public function setSubject($subject) public function setSubject(string $subject): bool
{ {
try try
{ {
$this->message->setSubject(strval($subject)); $this->message->setSubject($subject);
return true; return true;
} }
catch (\Exception $e) catch (\Exception $e)
@ -364,7 +367,7 @@ class Mail
* *
* @return string * @return string
*/ */
public function getSubject() public function getSubject(): string
{ {
return $this->message->getSubject(); return $this->message->getSubject();
} }
@ -375,7 +378,7 @@ class Mail
* @param string $subject * @param string $subject
* @return bool * @return bool
*/ */
public function setTitle($subject) public function setTitle(string $subject): bool
{ {
return $this->setSubject($subject); return $this->setSubject($subject);
} }
@ -385,7 +388,7 @@ class Mail
* *
* @return string * @return string
*/ */
public function getTitle() public function getTitle(): string
{ {
return $this->getSubject(); return $this->getSubject();
} }
@ -397,7 +400,7 @@ class Mail
* @param string $content_type (optional) * @param string $content_type (optional)
* @return void * @return void
*/ */
public function setBody($content, $content_type = null) public function setBody(string $content, ?string $content_type = null): void
{ {
if ($content_type !== null) if ($content_type !== null)
{ {
@ -417,7 +420,7 @@ class Mail
* *
* @return string * @return string
*/ */
public function getBody() public function getBody(): string
{ {
return $this->message->getBody(); return $this->message->getBody();
} }
@ -429,9 +432,9 @@ class Mail
* @param string $content_type (optional) * @param string $content_type (optional)
* @return void * @return void
*/ */
public function setContent($content, $content_type = null) public function setContent(string $content, ?string $content_type = null): void
{ {
return $this->setBody($content, $content_type); $this->setBody($content, $content_type);
} }
/** /**
@ -439,7 +442,7 @@ class Mail
* *
* @return string * @return string
*/ */
public function getContent() public function getContent(): string
{ {
return $this->getBody(); return $this->getBody();
} }
@ -450,7 +453,7 @@ class Mail
* @param string $mode The type * @param string $mode The type
* @return void * @return void
*/ */
public function setContentType($type = 'text/html') public function setContentType(string $type = 'text/html'): void
{ {
$this->content_type = (strpos($type, 'html') !== false) ? 'text/html' : ((strpos($type, '/') !== false) ? $type : 'text/plain'); $this->content_type = (strpos($type, 'html') !== false) ? 'text/html' : ((strpos($type, '/') !== false) ? $type : 'text/plain');
} }
@ -460,7 +463,7 @@ class Mail
* *
* @return string * @return string
*/ */
public function getContentType() public function getContentType(): string
{ {
return $this->content_type; return $this->content_type;
} }
@ -472,7 +475,7 @@ class Mail
* @param string $display_filename (optional) * @param string $display_filename (optional)
* @return bool * @return bool
*/ */
public function attach($local_filename, $display_filename = null) public function attach(string $local_filename, ?string $display_filename = null): bool
{ {
if ($display_filename === null) if ($display_filename === null)
{ {
@ -510,7 +513,7 @@ class Mail
* @param string $cid (optional) * @param string $cid (optional)
* @return string|false * @return string|false
*/ */
public function embed($local_filename, $cid = null) public function embed(string $local_filename, ?string $cid = null)
{ {
if (!Storage::exists($local_filename)) if (!Storage::exists($local_filename))
{ {
@ -545,7 +548,7 @@ class Mail
* *
* @return array * @return array
*/ */
public function getAttachments() public function getAttachments(): array
{ {
return $this->attachments; return $this->attachments;
} }
@ -555,7 +558,7 @@ class Mail
* *
* @return bool * @return bool
*/ */
public function send() public function send(): bool
{ {
// Get caller information. // Get caller information.
$backtrace = debug_backtrace(0); $backtrace = debug_backtrace(0);
@ -602,7 +605,7 @@ class Mail
* *
* @return bool * @return bool
*/ */
public function isSent() public function isSent(): bool
{ {
return $this->sent; return $this->sent;
} }
@ -612,7 +615,7 @@ class Mail
* *
* @return string * @return string
*/ */
public function getCaller() public function getCaller(): string
{ {
return $this->caller; return $this->caller;
} }
@ -622,7 +625,7 @@ class Mail
* *
* @return array * @return array
*/ */
public function getErrors() public function getErrors(): array
{ {
return $this->errors; return $this->errors;
} }
@ -634,7 +637,7 @@ class Mail
* @param array $matches Match info. * @param array $matches Match info.
* @return string * @return string
*/ */
protected function convertImageURLs(array $matches) protected function convertImageURLs(array $matches): string
{ {
return Filters\HTMLFilter::fixRelativeUrls($matches[0]); return Filters\HTMLFilter::fixRelativeUrls($matches[0]);
} }
@ -645,7 +648,7 @@ class Mail
* @param array $addresses * @param array $addresses
* @return array * @return array
*/ */
protected function formatAddresses($addresses) protected function formatAddresses(array $addresses): array
{ {
$result = array(); $result = array();

View file

@ -35,7 +35,7 @@ class Push
* @param object $driver * @param object $driver
* @return void * @return void
*/ */
public static function addDriver(string $name, Drivers\PushInterface $driver) public static function addDriver(string $name, Drivers\PushInterface $driver): void
{ {
self::$_drivers[$name] = $driver; self::$_drivers[$name] = $driver;
} }
@ -44,9 +44,9 @@ class Push
* Get the default driver. * Get the default driver.
* *
* @param string $name * @param string $name
* @return object|null * @return ?object
*/ */
public static function getDriver(string $name) public static function getDriver(string $name): ?object
{ {
if (isset(self::$_drivers[$name])) if (isset(self::$_drivers[$name]))
{ {
@ -464,35 +464,42 @@ class Push
* Delete the device toekn * Delete the device toekn
* *
* @param array * @param array
* @return void * @return bool
*/ */
protected function _deleteInvalidTokens(array $invalid_tokens) protected function _deleteInvalidTokens(array $invalid_tokens): bool
{ {
if(!count($invalid_tokens)) if(!count($invalid_tokens))
{ {
return; return true;
} }
$args = new \stdClass; $args = new \stdClass;
$args->device_token = $invalid_tokens; $args->device_token = $invalid_tokens;
executeQueryArray('member.deleteMemberDevice', $args); $output = executeQueryArray('member.deleteMemberDevice', $args);
return $output->toBool();
} }
/** /**
* Update the device toekn * Update the device toekn
* *
* @param array * @param array
* @return void * @return bool
*/ */
protected function _updateDeviceTokens(array $update_tokens) protected function _updateDeviceTokens(array $update_tokens): bool
{ {
$args = new \stdClass; $args = new \stdClass;
$result = true;
foreach($update_tokens as $key => $value) foreach($update_tokens as $key => $value)
{ {
$args->old_token = $key; $args->old_token = $key;
$args->new_token = $value; $args->new_token = $value;
executeQueryArray('member.updateMemberDevice', $args); $output = executeQueryArray('member.updateMemberDevice', $args);
if (!$output->toBool())
{
$result = false;
} }
} }
return $result;
}
/** /**
* Check if the message was sent. * Check if the message was sent.
@ -560,7 +567,7 @@ class Push
* @param string $message * @param string $message
* @return void * @return void
*/ */
public function addError(string $message) public function addError(string $message): void
{ {
$this->errors[] = $message; $this->errors[] = $message;
} }

View file

@ -34,10 +34,10 @@ class SMS
/** /**
* Set the default driver. * Set the default driver.
* *
* @param object $driver * @param Drivers\SMSInterface $driver
* @return void * @return void
*/ */
public static function setDefaultDriver(Drivers\SMSInterface $driver) public static function setDefaultDriver(Drivers\SMSInterface $driver): void
{ {
self::$default_driver = $driver; self::$default_driver = $driver;
} }
@ -45,9 +45,9 @@ class SMS
/** /**
* Get the default driver. * Get the default driver.
* *
* @return object * @return Drivers\SMSInterface
*/ */
public static function getDefaultDriver() public static function getDefaultDriver(): Drivers\SMSInterface
{ {
if (!self::$default_driver) if (!self::$default_driver)
{ {
@ -68,8 +68,11 @@ class SMS
/** /**
* Add a custom mail driver. * Add a custom mail driver.
*
* @param Drivers\SMSInterface $driver
* @return void
*/ */
public static function addDriver(Drivers\SMSInterface $driver) public static function addDriver(Drivers\SMSInterface $driver): void
{ {
self::$custom_drivers[] = $driver; self::$custom_drivers[] = $driver;
} }
@ -79,7 +82,7 @@ class SMS
* *
* @return array * @return array
*/ */
public static function getSupportedDrivers() public static function getSupportedDrivers(): array
{ {
$result = array(); $result = array();
foreach (Storage::readDirectory(__DIR__ . '/drivers/sms', false) as $filename) foreach (Storage::readDirectory(__DIR__ . '/drivers/sms', false) as $filename)
@ -132,7 +135,7 @@ class SMS
* @param string $number Phone number * @param string $number Phone number
* @return bool * @return bool
*/ */
public function setFrom($number) public function setFrom(string $number): bool
{ {
$this->from = preg_replace('/[^0-9]/', '', $number); $this->from = preg_replace('/[^0-9]/', '', $number);
return true; return true;
@ -143,7 +146,7 @@ class SMS
* *
* @return string|null * @return string|null
*/ */
public function getFrom() public function getFrom(): ?string
{ {
return $this->from; return $this->from;
} }
@ -155,7 +158,7 @@ class SMS
* @param string $country Country code (optional) * @param string $country Country code (optional)
* @return bool * @return bool
*/ */
public function addTo($number, $country = 0) public function addTo(string $number, string $country = '0'): bool
{ {
$this->to[] = (object)array( $this->to[] = (object)array(
'number' => preg_replace('/[^0-9]/', '', $number), 'number' => preg_replace('/[^0-9]/', '', $number),
@ -169,7 +172,7 @@ class SMS
* *
* @return array * @return array
*/ */
public function getRecipients() public function getRecipients(): array
{ {
return array_map(function($recipient) { return array_map(function($recipient) {
return $recipient->number; return $recipient->number;
@ -181,7 +184,7 @@ class SMS
* *
* @return array * @return array
*/ */
public function getRecipientsWithCountry() public function getRecipientsWithCountry(): array
{ {
return $this->to; return $this->to;
} }
@ -191,7 +194,7 @@ class SMS
* *
* @return array * @return array
*/ */
public function getRecipientsGroupedByCountry() public function getRecipientsGroupedByCountry(): array
{ {
$result = array(); $result = array();
foreach ($this->to as $recipient) foreach ($this->to as $recipient)
@ -207,7 +210,7 @@ class SMS
* @param string $subject * @param string $subject
* @return bool * @return bool
*/ */
public function setSubject($subject) public function setSubject(string $subject): bool
{ {
$this->subject = utf8_trim(utf8_clean($subject)); $this->subject = utf8_trim(utf8_clean($subject));
return true; return true;
@ -218,7 +221,7 @@ class SMS
* *
* @return string * @return string
*/ */
public function getSubject() public function getSubject(): string
{ {
return $this->subject; return $this->subject;
} }
@ -229,7 +232,7 @@ class SMS
* @param string $subject * @param string $subject
* @return bool * @return bool
*/ */
public function setTitle($subject) public function setTitle(string $subject): bool
{ {
return $this->setSubject($subject); return $this->setSubject($subject);
} }
@ -239,7 +242,7 @@ class SMS
* *
* @return string * @return string
*/ */
public function getTitle() public function getTitle(): string
{ {
return $this->getSubject(); return $this->getSubject();
} }
@ -250,7 +253,7 @@ class SMS
* @param string $content * @param string $content
* @return bool * @return bool
*/ */
public function setBody($content) public function setBody(string $content): bool
{ {
$this->content = utf8_trim(utf8_clean($content)); $this->content = utf8_trim(utf8_clean($content));
$this->content = strtr($this->content, array("\r\n" => "\n")); $this->content = strtr($this->content, array("\r\n" => "\n"));
@ -262,7 +265,7 @@ class SMS
* *
* @return string * @return string
*/ */
public function getBody() public function getBody(): string
{ {
return $this->content; return $this->content;
} }
@ -271,9 +274,9 @@ class SMS
* Set the content (alias to setBody). * Set the content (alias to setBody).
* *
* @param string $content * @param string $content
* @return void * @return bool
*/ */
public function setContent($content) public function setContent(string $content): bool
{ {
return $this->setBody($content); return $this->setBody($content);
} }
@ -283,7 +286,7 @@ class SMS
* *
* @return string * @return string
*/ */
public function getContent() public function getContent(): string
{ {
return $this->getBody(); return $this->getBody();
} }
@ -295,7 +298,7 @@ class SMS
* @param string $display_filename (optional) * @param string $display_filename (optional)
* @return bool * @return bool
*/ */
public function attach($local_filename, $display_filename = null) public function attach(string $local_filename, ?string $display_filename = null): bool
{ {
if ($display_filename === null) if ($display_filename === null)
{ {
@ -320,7 +323,7 @@ class SMS
* *
* @return array * @return array
*/ */
public function getAttachments() public function getAttachments(): array
{ {
return $this->attachments; return $this->attachments;
} }
@ -332,7 +335,7 @@ class SMS
* @param mixed $value * @param mixed $value
* @return void * @return void
*/ */
public function setExtraVar($key, $value) public function setExtraVar(string $key, $value): void
{ {
$this->extra_vars[$key] = $value; $this->extra_vars[$key] = $value;
} }
@ -343,7 +346,7 @@ class SMS
* @param string $key * @param string $key
* @return mixed * @return mixed
*/ */
public function getExtraVar($key) public function getExtraVar(string $key)
{ {
return isset($this->extra_vars[$key]) ? $this->extra_vars[$key] : null; return isset($this->extra_vars[$key]) ? $this->extra_vars[$key] : null;
} }
@ -352,9 +355,9 @@ class SMS
* Get all extra variables. * Get all extra variables.
* *
* @param string $key * @param string $key
* @return mixed * @return array
*/ */
public function getExtraVars() public function getExtraVars(): array
{ {
return $this->extra_vars; return $this->extra_vars;
} }
@ -365,7 +368,7 @@ class SMS
* @param array $vars * @param array $vars
* @return void * @return void
*/ */
public function setExtraVars(array $vars) public function setExtraVars(array $vars): void
{ {
$this->extra_vars = $vars; $this->extra_vars = $vars;
} }
@ -381,7 +384,7 @@ class SMS
* @param int $when Unix timestamp * @param int $when Unix timestamp
* @return bool * @return bool
*/ */
public function setDelay($when) public function setDelay(int $when): bool
{ {
if ($when <= (86400 * 365)) if ($when <= (86400 * 365))
{ {
@ -392,8 +395,8 @@ class SMS
$when = 0; $when = 0;
} }
$this->delay_timestamp = intval($when); $this->delay_timestamp = $when;
return true; return $when > 0;
} }
/** /**
@ -406,7 +409,7 @@ class SMS
* *
* @return int * @return int
*/ */
public function getDelay() public function getDelay(): int
{ {
return $this->delay_timestamp; return $this->delay_timestamp;
} }
@ -416,7 +419,7 @@ class SMS
* *
* @return void * @return void
*/ */
public function forceSMS() public function forceSMS(): void
{ {
$this->force_sms = true; $this->force_sms = true;
} }
@ -426,7 +429,7 @@ class SMS
* *
* @return void * @return void
*/ */
public function unforceSMS() public function unforceSMS(): void
{ {
$this->force_sms = false; $this->force_sms = false;
} }
@ -436,7 +439,7 @@ class SMS
* *
* @return bool * @return bool
*/ */
public function isForceSMS() public function isForceSMS(): bool
{ {
return $this->force_sms; return $this->force_sms;
} }
@ -446,7 +449,7 @@ class SMS
* *
* @return void * @return void
*/ */
public function allowSplitSMS() public function allowSplitSMS(): void
{ {
$this->allow_split_sms = true; $this->allow_split_sms = true;
} }
@ -456,7 +459,7 @@ class SMS
* *
* @return void * @return void
*/ */
public function allowSplitLMS() public function allowSplitLMS(): void
{ {
$this->allow_split_lms = true; $this->allow_split_lms = true;
} }
@ -466,7 +469,7 @@ class SMS
* *
* @return void * @return void
*/ */
public function disallowSplitSMS() public function disallowSplitSMS(): void
{ {
$this->allow_split_sms = false; $this->allow_split_sms = false;
} }
@ -476,7 +479,7 @@ class SMS
* *
* @return void * @return void
*/ */
public function disallowSplitLMS() public function disallowSplitLMS(): void
{ {
$this->allow_split_lms = false; $this->allow_split_lms = false;
} }
@ -486,7 +489,7 @@ class SMS
* *
* @return bool * @return bool
*/ */
public function isSplitSMSAllowed() public function isSplitSMSAllowed(): bool
{ {
return $this->allow_split_sms; return $this->allow_split_sms;
} }
@ -496,7 +499,7 @@ class SMS
* *
* @return bool * @return bool
*/ */
public function isSplitLMSAllowed() public function isSplitLMSAllowed(): bool
{ {
return $this->allow_split_lms; return $this->allow_split_lms;
} }
@ -506,7 +509,7 @@ class SMS
* *
* @return bool * @return bool
*/ */
public function send() public function send(): bool
{ {
// Get caller information. // Get caller information.
$backtrace = debug_backtrace(0); $backtrace = debug_backtrace(0);
@ -568,7 +571,7 @@ class SMS
* *
* @return bool * @return bool
*/ */
public function isSent() public function isSent(): bool
{ {
return $this->sent; return $this->sent;
} }
@ -578,7 +581,7 @@ class SMS
* *
* @return string * @return string
*/ */
public function getCaller() public function getCaller(): string
{ {
return $this->caller; return $this->caller;
} }
@ -588,7 +591,7 @@ class SMS
* *
* @return array * @return array
*/ */
public function getErrors() public function getErrors(): array
{ {
return $this->errors; return $this->errors;
} }
@ -599,7 +602,7 @@ class SMS
* @param string $message * @param string $message
* @return void * @return void
*/ */
public function addError($message) public function addError(string $message): void
{ {
$this->errors[] = $message; $this->errors[] = $message;
} }
@ -610,7 +613,7 @@ class SMS
* @param array $spec API specifications * @param array $spec API specifications
* @return array * @return array
*/ */
protected function _formatSpec(array $spec) protected function _formatSpec(array $spec): array
{ {
// Initialize the return array. // Initialize the return array.
$result = array(); $result = array();
@ -771,9 +774,9 @@ class SMS
* *
* @param string $str String to measure * @param string $str String to measure
* @param string $charset Character set to measure length * @param string $charset Character set to measure length
* @return * @return int
*/ */
protected function _getLengthInCharset($str, $charset) protected function _getLengthInCharset(string $str, string $charset): int
{ {
$str = @iconv('UTF-8', $charset . '//IGNORE', $str); $str = @iconv('UTF-8', $charset . '//IGNORE', $str);
return strlen($str); return strlen($str);
@ -787,7 +790,7 @@ class SMS
* @param string $charset Character set to measure length * @param string $charset Character set to measure length
* @return array * @return array
*/ */
protected function _splitString($str, $max_length, $charset) protected function _splitString(string $str, int $max_length, string $charset): array
{ {
$str = utf8_trim(utf8_normalize_spaces($str, true)); $str = utf8_trim(utf8_normalize_spaces($str, true));
$chars = preg_split('//u', $str, -1, \PREG_SPLIT_NO_EMPTY); $chars = preg_split('//u', $str, -1, \PREG_SPLIT_NO_EMPTY);

View file

@ -135,7 +135,7 @@ class SMSTest extends \Codeception\TestCase\Test
$this->assertLessThanOrEqual(time() + $delay_relative + 1, $sms->getDelay()); $this->assertLessThanOrEqual(time() + $delay_relative + 1, $sms->getDelay());
$delay_relative = 86400 * 3650; $delay_relative = 86400 * 3650;
$this->assertTrue($sms->setDelay($delay_relative)); $this->assertFalse($sms->setDelay($delay_relative));
$this->assertEquals(0, $sms->getDelay()); $this->assertEquals(0, $sms->getDelay());
} }