Skip to content

Commit

Permalink
Move isGsm7 to static for other libraries (#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
SecondeJK authored Feb 1, 2023
1 parent ea84981 commit 02ae3fc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/SMS/Message/SMS.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public function __construct(string $to, string $from, protected string $message,
$this->setType($type);
}

public function isGsm7(): bool
public static function isGsm7(string $message): bool
{
return (bool)preg_match(self::GSM_7_PATTERN, $this->getMessage());
return (bool)preg_match(self::GSM_7_PATTERN, $message);
}

public function getContentId(): string
Expand All @@ -59,14 +59,14 @@ public function setEntityId(string $id): self

public function getErrorMessage(): ?string
{
if ($this->getType() === 'unicode' && $this->isGsm7()) {
if ($this->getType() === 'unicode' && self::isGsm7($this->getMessage())) {
$this->setErrorMessage("You are sending a message as `unicode` when it could be `text` or a
`text` type with unicode-only characters. This could result in increased billing -
See https://developer.vonage.com/messaging/sms for details, or email [email protected] if you have any
questions.");
}

if ($this->getType() === 'text' && ! $this->isGsm7()) {
if ($this->getType() === 'text' && ! self::isGsm7($this->getMessage())) {
$this->setErrorMessage("You are sending a message as `text` when contains unicode only
characters. This could result in encoding problems with the target device or increased billing - See
https://developer.vonage.com/messaging/sms for details, or email [email protected] if you have any
Expand Down
5 changes: 2 additions & 3 deletions test/SMS/Message/SMSTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,9 @@ public function testDLTInfoDoesNotAppearsWhenNotSet(): void
* @dataProvider unicodeStringDataProvider
* @return void
*/
public function testGsm7Identification(string $message, bool $expectedGsm7)
public function testGsm7Identification(string $message, bool $expectedGsm7): void
{
$sms = new SMS('16105551212', '16105551212', $message);
$this->assertEquals($expectedGsm7, $sms->isGsm7());
$this->assertEquals($expectedGsm7, SMS::isGsm7($message));
}

public function unicodeStringDataProvider(): array
Expand Down

0 comments on commit 02ae3fc

Please sign in to comment.