From 0711ee6dc4c2cce27a475e30cd54ecda0d854292 Mon Sep 17 00:00:00 2001 From: Relax Dev Date: Mon, 5 Feb 2024 20:56:02 +0330 Subject: [PATCH] fix: white space issue in pattern parameters name and value (#1247) * fix: white space issue in pattern parameters name and value * fix: pint --------- Co-authored-by: rel4xdev --- config/sms.php | 2 +- src/Drivers/Farazsmspattern.php | 2 +- src/Drivers/Melipayamakpattern.php | 2 +- src/Drivers/SmsApi.php | 16 +++++++--------- tests/Drivers/SmsApiTest.php | 4 ++-- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/config/sms.php b/config/sms.php index af64b15b..38b04363 100644 --- a/config/sms.php +++ b/config/sms.php @@ -161,7 +161,7 @@ 'username' => 'Your SMSApi Username', 'password' => 'Your SMSApi Password', 'from' => 'Your Default From Number', - 'cc' => 'Your Default Country Code' + 'cc' => 'Your Default Country Code', ], ], diff --git a/src/Drivers/Farazsmspattern.php b/src/Drivers/Farazsmspattern.php index 7666c631..c7a112ba 100644 --- a/src/Drivers/Farazsmspattern.php +++ b/src/Drivers/Farazsmspattern.php @@ -36,7 +36,7 @@ protected function payload($recipient): array continue; } $key_value = explode('=', $datum); - $input_data[trim($key_value[0])] = $key_value[1]; + $input_data[trim($key_value[0])] = trim($key_value[1]); } return [ diff --git a/src/Drivers/Melipayamakpattern.php b/src/Drivers/Melipayamakpattern.php index ba9d93ef..cc3efc1e 100644 --- a/src/Drivers/Melipayamakpattern.php +++ b/src/Drivers/Melipayamakpattern.php @@ -28,7 +28,7 @@ public function send() continue; } $key_value = explode('=', $datum); - $input_data[] = $key_value[1]; + $input_data[] = trim($key_value[1]); } foreach ($this->recipients as $recipient) { $response->put($recipient, $this->client->sms('soap')->sendByBaseNumber( diff --git a/src/Drivers/SmsApi.php b/src/Drivers/SmsApi.php index 8fd69bf7..46963800 100644 --- a/src/Drivers/SmsApi.php +++ b/src/Drivers/SmsApi.php @@ -10,7 +10,7 @@ class SmsApi extends Driver protected Client $client; private array $options = []; - + protected function boot(): void { $this->client = new Client(); @@ -19,17 +19,14 @@ protected function boot(): void /** * Provides a way to pass additional valid parameters or override existing ones - * - * @param array $options - * @return self */ public function with(array $options): self { - if (!empty(array_diff(array_keys($options), ['from', 'sname', 'cc', 'sid', 'ur', 'dr', 'stime', 'unicode', 'mms', 'mmstype', 'mmsurl']))) { - throw new \Exception(__METHOD__ . " contains invalid options"); + if (! empty(array_diff(array_keys($options), ['from', 'sname', 'cc', 'sid', 'ur', 'dr', 'stime', 'unicode', 'mms', 'mmstype', 'mmsurl']))) { + throw new \Exception(__METHOD__.' contains invalid options'); } - foreach($options as $option => $value) { + foreach ($options as $option => $value) { $this->options[$option] = $value; } @@ -47,11 +44,12 @@ public function send() data_get($this->settings, 'url'), [ 'form_params' => $this->payload($recipient), - 'verify' => false + 'verify' => false, ] ) ); } + return (count($this->recipients) == 1) ? $response->first() : $response; } @@ -66,6 +64,6 @@ public function payload($recipient): array 'm' => $this->body, ]; - return array_merge($payload, $this->options); + return array_merge($payload, $this->options); } } diff --git a/tests/Drivers/SmsApiTest.php b/tests/Drivers/SmsApiTest.php index 012fa054..def332b2 100644 --- a/tests/Drivers/SmsApiTest.php +++ b/tests/Drivers/SmsApiTest.php @@ -3,8 +3,8 @@ namespace Tzsk\Sms\Tests\Drivers; use Tzsk\Sms\Facades\Sms; -use Tzsk\Sms\Tests\TestCase; use Tzsk\Sms\Tests\Mocks\Drivers\MockSmsApi; +use Tzsk\Sms\Tests\TestCase; class SmsApiTest extends TestCase { @@ -19,7 +19,7 @@ public function test_it_wont_accept_invalid_parameters() { $this->expectException(\Exception::class); $this->expectExceptionMessage('Tzsk\Sms\Drivers\SmsApi::with contains invalid options'); - Sms::via('smsapi')->send("this message", function ($sms) { + Sms::via('smsapi')->send('this message', function ($sms) { $sms->to(['Number 1', 'Number 2'])->with(['invalid_parameter' => 'value', 'sid' => 1, 'sname' => 'Sender Name']); }); }