Skip to content

Commit 02ae3fc

Browse files
authored
Move isGsm7 to static for other libraries (#359)
1 parent ea84981 commit 02ae3fc

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/SMS/Message/SMS.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ public function __construct(string $to, string $from, protected string $message,
3030
$this->setType($type);
3131
}
3232

33-
public function isGsm7(): bool
33+
public static function isGsm7(string $message): bool
3434
{
35-
return (bool)preg_match(self::GSM_7_PATTERN, $this->getMessage());
35+
return (bool)preg_match(self::GSM_7_PATTERN, $message);
3636
}
3737

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

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

69-
if ($this->getType() === 'text' && ! $this->isGsm7()) {
69+
if ($this->getType() === 'text' && ! self::isGsm7($this->getMessage())) {
7070
$this->setErrorMessage("You are sending a message as `text` when contains unicode only
7171
characters. This could result in encoding problems with the target device or increased billing - See
7272
https://developer.vonage.com/messaging/sms for details, or email [email protected] if you have any

test/SMS/Message/SMSTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,9 @@ public function testDLTInfoDoesNotAppearsWhenNotSet(): void
173173
* @dataProvider unicodeStringDataProvider
174174
* @return void
175175
*/
176-
public function testGsm7Identification(string $message, bool $expectedGsm7)
176+
public function testGsm7Identification(string $message, bool $expectedGsm7): void
177177
{
178-
$sms = new SMS('16105551212', '16105551212', $message);
179-
$this->assertEquals($expectedGsm7, $sms->isGsm7());
178+
$this->assertEquals($expectedGsm7, SMS::isGsm7($message));
180179
}
181180

182181
public function unicodeStringDataProvider(): array

0 commit comments

Comments
 (0)