From 6e5dbb928f2259de59e4c0b6280f2386c074f97e Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 7 Dec 2022 18:29:00 +1300 Subject: [PATCH 01/11] Move send function up to base adapter --- src/Utopia/Messaging/Adapter.php | 12 +++++++++++- src/Utopia/Messaging/Adapters/Email.php | 15 --------------- src/Utopia/Messaging/Adapters/Push.php | 15 --------------- src/Utopia/Messaging/Adapters/SMS.php | 15 --------------- 4 files changed, 11 insertions(+), 46 deletions(-) diff --git a/src/Utopia/Messaging/Adapter.php b/src/Utopia/Messaging/Adapter.php index 83422709..68fd10c0 100644 --- a/src/Utopia/Messaging/Adapter.php +++ b/src/Utopia/Messaging/Adapter.php @@ -37,8 +37,18 @@ abstract public function getMaxMessagesPerRequest(): int; * * @param Message $message The message to send. * @return string The response body. + * @throws \Exception */ - abstract public function send(Message $message): string; + public function send(Message $message): string + { + if (!\is_a($message, $this->getMessageType())) { + throw new \Exception('Invalid message type.'); + } + if (\count($message->getTo()) > $this->getMaxMessagesPerRequest()) { + throw new \Exception("{$this->getName()} can only send {$this->getMaxMessagesPerRequest()} messages per request."); + } + return $this->process($message); + } /** * Send an HTTP request. diff --git a/src/Utopia/Messaging/Adapters/Email.php b/src/Utopia/Messaging/Adapters/Email.php index 4cfff3fc..427485f9 100644 --- a/src/Utopia/Messaging/Adapters/Email.php +++ b/src/Utopia/Messaging/Adapters/Email.php @@ -18,21 +18,6 @@ public function getMessageType(): string return EmailMessage::class; } - /** - * @inheritdoc - * @throws \Exception - */ - public function send(Message $message): string - { - if (!\is_a($message, $this->getMessageType())) { - throw new \Exception('Invalid message type.'); - } - if (\count($message->getTo()) > $this->getMaxMessagesPerRequest()) { - throw new \Exception("{$this->getName()} can only send {$this->getMaxMessagesPerRequest()} messages per request."); - } - return $this->process($message); - } - /** * Process an email message. * diff --git a/src/Utopia/Messaging/Adapters/Push.php b/src/Utopia/Messaging/Adapters/Push.php index 419fc987..e9d8d66b 100644 --- a/src/Utopia/Messaging/Adapters/Push.php +++ b/src/Utopia/Messaging/Adapters/Push.php @@ -18,21 +18,6 @@ public function getMessageType(): string return PushMessage::class; } - /** - * @inheritdoc - * @throws \Exception - */ - public function send(Message $message): string - { - if (!\is_a($message, $this->getMessageType())) { - throw new \Exception('Invalid message type.'); - } - if (\count($message->getTo()) > $this->getMaxMessagesPerRequest()) { - throw new \Exception("{$this->getName()} can only send {$this->getMaxMessagesPerRequest()} messages per request."); - } - return $this->process($message); - } - /** * Send a push message. * diff --git a/src/Utopia/Messaging/Adapters/SMS.php b/src/Utopia/Messaging/Adapters/SMS.php index 7b28dff8..60c84513 100644 --- a/src/Utopia/Messaging/Adapters/SMS.php +++ b/src/Utopia/Messaging/Adapters/SMS.php @@ -18,21 +18,6 @@ public function getMessageType(): string return SMSMessage::class; } - /** - * @inheritdoc - * @throws \Exception - */ - public function send(Message $message): string - { - if (!\is_a($message, $this->getMessageType())) { - throw new \Exception('Invalid message type.'); - } - if (\count($message->getTo()) > $this->getMaxMessagesPerRequest()) { - throw new \Exception("{$this->getName()} can only send {$this->getMaxMessagesPerRequest()} messages per request."); - } - return $this->process($message); - } - /** * Send an SMS message. * From 72fc8b660b5a1629d2252d83a85f7b69ff43ebcb Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 7 Dec 2022 18:40:24 +1300 Subject: [PATCH 02/11] Add discord adapter --- src/Utopia/Messaging/Adapters/Discord.php | 59 +++++++++++++++++++++++ src/Utopia/Messaging/Messages/Discord.php | 40 +++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 src/Utopia/Messaging/Adapters/Discord.php create mode 100644 src/Utopia/Messaging/Messages/Discord.php diff --git a/src/Utopia/Messaging/Adapters/Discord.php b/src/Utopia/Messaging/Adapters/Discord.php new file mode 100644 index 00000000..c1c19207 --- /dev/null +++ b/src/Utopia/Messaging/Adapters/Discord.php @@ -0,0 +1,59 @@ +request( + method: 'POST', + url: "https://discord.com/api/webhooks/{$this->webhookId}/{$this->webhookToken}", + headers: [ + 'Content-Type: application/json', + ], + body: \json_encode([ + 'content' => $message->getContent(), + 'username' => $message->getUsername(), + 'avatar_url' => $message->getAvatarUrl(), + ]), + ); + } +} diff --git a/src/Utopia/Messaging/Messages/Discord.php b/src/Utopia/Messaging/Messages/Discord.php new file mode 100644 index 00000000..c88af4da --- /dev/null +++ b/src/Utopia/Messaging/Messages/Discord.php @@ -0,0 +1,40 @@ +content; + } + + /** + * @return string|null + */ + public function getUsername(): ?string + { + return $this->username; + } + + /** + * @return string|null + */ + public function getAvatarUrl(): ?string + { + return $this->avatarUrl; + } +} \ No newline at end of file From 9be0501ffaa7f7f3ad21d2c3d70e0985fc41f0f2 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 2 Nov 2023 00:00:30 +1300 Subject: [PATCH 03/11] Update workflows --- .github/workflows/analyse.yml | 20 +++++ .github/workflows/{linter.yml => lint.yml} | 0 .github/workflows/{tests.yml => test.yml} | 0 composer.json | 10 ++- composer.lock | 92 ++++++++++++++++++---- 5 files changed, 103 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/analyse.yml rename .github/workflows/{linter.yml => lint.yml} (100%) rename .github/workflows/{tests.yml => test.yml} (100%) diff --git a/.github/workflows/analyse.yml b/.github/workflows/analyse.yml new file mode 100644 index 00000000..72ed14c1 --- /dev/null +++ b/.github/workflows/analyse.yml @@ -0,0 +1,20 @@ +name: "Static Analysis" + +on: [pull_request] +jobs: + analyse: + name: Analyse + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + fetch-depth: 2 + + - run: git checkout HEAD^2 + + - name: Run Static Analysis + run: | + docker run --rm -v $PWD:/app composer sh -c \ + "composer install --profile --ignore-platform-reqs && composer analyse" diff --git a/.github/workflows/linter.yml b/.github/workflows/lint.yml similarity index 100% rename from .github/workflows/linter.yml rename to .github/workflows/lint.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/test.yml similarity index 100% rename from .github/workflows/tests.yml rename to .github/workflows/test.yml diff --git a/composer.json b/composer.json index bac108a5..d081f24c 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,8 @@ "scripts": { "test": "vendor/bin/phpunit", "lint": "./vendor/bin/pint --test", - "format": "./vendor/bin/pint" + "format": "./vendor/bin/pint", + "analyse": "./vendor/bin/phpstan analyse --memory-limit=2G --level=6 src tests" }, "autoload": { "psr-4": { @@ -17,8 +18,7 @@ }, "autoload-dev": { "psr-4": { - "Tests\\E2E\\": "tests/e2e", - "Tests\\Unit\\": "tests/unit" + "Utopia\\Tests\\": "tests/Messaging" } }, "require": { @@ -26,9 +26,11 @@ "ext-curl": "*" }, "require-dev": { + "ext-openssl": "*", "phpunit/phpunit": "9.6.*", "phpmailer/phpmailer": "6.8.*", - "laravel/pint": "^1.2" + "laravel/pint": "1.13.*", + "phpstan/phpstan": "1.10.*" }, "config": { "platform": { diff --git a/composer.lock b/composer.lock index 9f6b978b..6994d832 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "5ecbd865cbd7f14e7819fb79643573be", + "content-hash": "af54d4a3e39567814f90395c0d3ceb8a", "packages": [], "packages-dev": [ { @@ -79,16 +79,16 @@ }, { "name": "laravel/pint", - "version": "v1.2.0", + "version": "v1.13.5", "source": { "type": "git", "url": "https://github.com/laravel/pint.git", - "reference": "1d276e4c803397a26cc337df908f55c2a4e90d86" + "reference": "df105cf8ce7a8f0b8a9425ff45cd281a5448e423" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/pint/zipball/1d276e4c803397a26cc337df908f55c2a4e90d86", - "reference": "1d276e4c803397a26cc337df908f55c2a4e90d86", + "url": "https://api.github.com/repos/laravel/pint/zipball/df105cf8ce7a8f0b8a9425ff45cd281a5448e423", + "reference": "df105cf8ce7a8f0b8a9425ff45cd281a5448e423", "shasum": "" }, "require": { @@ -96,16 +96,16 @@ "ext-mbstring": "*", "ext-tokenizer": "*", "ext-xml": "*", - "php": "^8.0" + "php": "^8.1.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.11.0", - "illuminate/view": "^9.27", - "laravel-zero/framework": "^9.1.3", - "mockery/mockery": "^1.5.0", - "nunomaduro/larastan": "^2.2", - "nunomaduro/termwind": "^1.14.0", - "pestphp/pest": "^1.22.1" + "friendsofphp/php-cs-fixer": "^3.34.1", + "illuminate/view": "^10.26.2", + "laravel-zero/framework": "^10.1.2", + "mockery/mockery": "^1.6.6", + "nunomaduro/larastan": "^2.6.4", + "nunomaduro/termwind": "^1.15.1", + "pestphp/pest": "^2.20.0" }, "bin": [ "builds/pint" @@ -141,7 +141,7 @@ "issues": "https://github.com/laravel/pint/issues", "source": "https://github.com/laravel/pint" }, - "time": "2022-09-13T15:07:15+00:00" + "time": "2023-10-26T09:26:10+00:00" }, { "name": "myclabs/deep-copy", @@ -449,6 +449,68 @@ ], "time": "2023-03-06T14:43:22+00:00" }, + { + "name": "phpstan/phpstan", + "version": "1.10.40", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "93c84b5bf7669920d823631e39904d69b9c7dc5d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/93c84b5bf7669920d823631e39904d69b9c7dc5d", + "reference": "93c84b5bf7669920d823631e39904d69b9c7dc5d", + "shasum": "" + }, + "require": { + "php": "^7.2|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "docs": "https://phpstan.org/user-guide/getting-started", + "forum": "https://github.com/phpstan/phpstan/discussions", + "issues": "https://github.com/phpstan/phpstan/issues", + "security": "https://github.com/phpstan/phpstan/security/policy", + "source": "https://github.com/phpstan/phpstan-src" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://github.com/phpstan", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan", + "type": "tidelift" + } + ], + "time": "2023-10-30T14:48:31+00:00" + }, { "name": "phpunit/php-code-coverage", "version": "9.2.17", @@ -1898,5 +1960,5 @@ "platform-overrides": { "php": "8.0" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } From b24deb9fed3194450660b0da1bf8a339dc0556b0 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 2 Nov 2023 00:00:44 +1300 Subject: [PATCH 04/11] Add discord test --- docker-compose.yml | 2 + docs/add-new-adapter.md | 4 +- src/Utopia/Messaging/Adapter.php | 21 ++-- .../{Adapters => Adapter/App}/Discord.php | 37 ++++-- .../Messaging/{Adapters => Adapter}/Email.php | 2 +- .../{Adapters => Adapter}/Email/Mailgun.php | 8 +- .../{Adapters => Adapter}/Email/Mock.php | 8 +- .../{Adapters => Adapter}/Email/Sendgrid.php | 12 +- .../Messaging/{Adapters => Adapter}/Push.php | 2 +- .../{Adapters => Adapter}/Push/APNS.php | 108 ++++++------------ .../{Adapters => Adapter}/Push/FCM.php | 8 +- .../Messaging/{Adapters => Adapter}/SMS.php | 2 +- .../{Adapters => Adapter}/SMS/Clickatell.php | 4 +- .../{Adapters => Adapter}/SMS/Infobip.php | 4 +- .../{Adapters => Adapter}/SMS/Mock.php | 4 +- .../{Adapters => Adapter}/SMS/Msg91.php | 22 +--- .../{Adapters => Adapter}/SMS/Plivo.php | 4 +- .../{Adapters => Adapter}/SMS/Seven.php | 4 +- .../{Adapters => Adapter}/SMS/Sinch.php | 4 +- .../{Adapters => Adapter}/SMS/Telesign.php | 8 +- .../{Adapters => Adapter}/SMS/Telnyx.php | 4 +- .../{Adapters => Adapter}/SMS/TextMagic.php | 4 +- .../{Adapters => Adapter}/SMS/Twilio.php | 4 +- .../{Adapters => Adapter}/SMS/Vonage.php | 4 +- src/Utopia/Messaging/Message.php | 3 - src/Utopia/Messaging/Messages/Discord.php | 92 +++++++++++++-- src/Utopia/Messaging/Messages/Email.php | 21 +--- src/Utopia/Messaging/Messages/Push.php | 32 +----- src/Utopia/Messaging/Messages/SMS.php | 16 +-- tests/Messaging/Adapter/App/DiscordTest.php | 33 ++++++ tests/{e2e => Messaging/Adapter}/Base.php | 8 +- .../Adapter}/Email/EmailTest.php | 7 +- .../Adapter}/Email/MailgunTest.php | 19 +-- .../Adapter}/Email/SendgridTest.php | 15 +-- .../Adapter}/Push/APNSTest.php | 15 +-- .../Adapter}/Push/FCMTest.php | 9 +- .../Adapter}/SMS/Msg91Test.php | 13 +-- .../Adapter}/SMS/SMSTest.php | 7 +- .../Adapter}/SMS/TelesignTest.php | 6 +- .../Adapter}/SMS/TelnyxTest.php | 9 +- .../Adapter}/SMS/TwilioTest.php | 13 ++- .../Adapter}/SMS/VonageTest.php | 15 +-- tests/unit/.gitkeep | 0 43 files changed, 328 insertions(+), 289 deletions(-) rename src/Utopia/Messaging/{Adapters => Adapter/App}/Discord.php (50%) rename src/Utopia/Messaging/{Adapters => Adapter}/Email.php (93%) rename src/Utopia/Messaging/{Adapters => Adapter}/Email/Mailgun.php (91%) rename src/Utopia/Messaging/{Adapters => Adapter}/Email/Mock.php (89%) rename src/Utopia/Messaging/{Adapters => Adapter}/Email/Sendgrid.php (87%) rename src/Utopia/Messaging/{Adapters => Adapter}/Push.php (93%) rename src/Utopia/Messaging/{Adapters => Adapter}/Push/APNS.php (55%) rename src/Utopia/Messaging/{Adapters => Adapter}/Push/FCM.php (91%) rename src/Utopia/Messaging/{Adapters => Adapter}/SMS.php (93%) rename src/Utopia/Messaging/{Adapters => Adapter}/SMS/Clickatell.php (92%) rename src/Utopia/Messaging/{Adapters => Adapter}/SMS/Infobip.php (93%) rename src/Utopia/Messaging/{Adapters => Adapter}/SMS/Mock.php (92%) rename src/Utopia/Messaging/{Adapters => Adapter}/SMS/Msg91.php (65%) rename src/Utopia/Messaging/{Adapters => Adapter}/SMS/Plivo.php (92%) rename src/Utopia/Messaging/{Adapters => Adapter}/SMS/Seven.php (92%) rename src/Utopia/Messaging/{Adapters => Adapter}/SMS/Sinch.php (93%) rename src/Utopia/Messaging/{Adapters => Adapter}/SMS/Telesign.php (90%) rename src/Utopia/Messaging/{Adapters => Adapter}/SMS/Telnyx.php (91%) rename src/Utopia/Messaging/{Adapters => Adapter}/SMS/TextMagic.php (93%) rename src/Utopia/Messaging/{Adapters => Adapter}/SMS/Twilio.php (92%) rename src/Utopia/Messaging/{Adapters => Adapter}/SMS/Vonage.php (93%) create mode 100644 tests/Messaging/Adapter/App/DiscordTest.php rename tests/{e2e => Messaging/Adapter}/Base.php (82%) rename tests/{e2e => Messaging/Adapter}/Email/EmailTest.php (84%) rename tests/{e2e => Messaging/Adapter}/Email/MailgunTest.php (59%) rename tests/{e2e => Messaging/Adapter}/Email/SendgridTest.php (63%) rename tests/{e2e => Messaging/Adapter}/Push/APNSTest.php (67%) rename tests/{e2e => Messaging/Adapter}/Push/FCMTest.php (76%) rename tests/{e2e => Messaging/Adapter}/SMS/Msg91Test.php (59%) rename tests/{e2e => Messaging/Adapter}/SMS/SMSTest.php (86%) rename tests/{e2e => Messaging/Adapter}/SMS/TelesignTest.php (64%) rename tests/{e2e => Messaging/Adapter}/SMS/TelnyxTest.php (71%) rename tests/{e2e => Messaging/Adapter}/SMS/TwilioTest.php (61%) rename tests/{e2e => Messaging/Adapter}/SMS/VonageTest.php (62%) delete mode 100644 tests/unit/.gitkeep diff --git a/docker-compose.yml b/docker-compose.yml index 80d626d9..6cb8400a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -29,6 +29,8 @@ services: - VONAGE_API_SECRET - VONAGE_TO - VONAGE_FROM + - DISCORD_WEBHOOK_ID + - DISCORD_WEBHOOK_TOKEN build: context: . volumes: diff --git a/docs/add-new-adapter.md b/docs/add-new-adapter.md index a720bbc0..70d3d38d 100644 --- a/docs/add-new-adapter.md +++ b/docs/add-new-adapter.md @@ -81,10 +81,10 @@ Putting it all together, the `SendGrid` adapter should look like this: ```php getMessageType())) { + if (! \is_a($message, $this->getMessageType())) { throw new \Exception('Invalid message type.'); } - if (\count($message->getTo()) > $this->getMaxMessagesPerRequest()) { + if (\method_exists($message, 'getTo') && \count($message->getTo()) > $this->getMaxMessagesPerRequest()) { throw new \Exception("{$this->getName()} can only send {$this->getMaxMessagesPerRequest()} messages per request."); } + if (! \method_exists($this, 'process')) { + throw new \Exception('Adapter does not implement process method.'); + } + return $this->process($message); } @@ -55,7 +52,7 @@ public function send(Message $message): string * * @param string $method The HTTP method to use. * @param string $url The URL to send the request to. - * @param array $headers An array of headers to send with the request. + * @param array $headers An array of headers to send with the request. * @param string|null $body The body of the request. * @return string The response body. * @@ -65,7 +62,7 @@ protected function request( string $method, string $url, array $headers = [], - ?string $body = null, + string $body = null, ): string { $ch = \curl_init(); diff --git a/src/Utopia/Messaging/Adapters/Discord.php b/src/Utopia/Messaging/Adapter/App/Discord.php similarity index 50% rename from src/Utopia/Messaging/Adapters/Discord.php rename to src/Utopia/Messaging/Adapter/App/Discord.php index c1c19207..af3582ab 100644 --- a/src/Utopia/Messaging/Adapters/Discord.php +++ b/src/Utopia/Messaging/Adapter/App/Discord.php @@ -1,6 +1,6 @@ getWait())) { + $query['wait'] = $message->getWait(); + } + if (! \is_null($message->getThreadId())) { + $query['thread_id'] = $message->getThreadId(); + } + + $queryString = ''; + foreach ($query as $key => $value) { + if (empty($queryString)) { + $queryString .= '?'; + } + $queryString .= $key.'='.$value; + } + return $this->request( method: 'POST', - url: "https://discord.com/api/webhooks/{$this->webhookId}/{$this->webhookToken}", + url: "https://discord.com/api/webhooks/{$this->webhookId}/{$this->webhookToken}{$queryString}", headers: [ 'Content-Type: application/json', ], @@ -53,6 +69,13 @@ protected function process(DiscordMessage $message): string 'content' => $message->getContent(), 'username' => $message->getUsername(), 'avatar_url' => $message->getAvatarUrl(), + 'tts' => $message->getTTS(), + 'embeds' => $message->getEmbeds(), + 'allowed_mentions' => $message->getAllowedMentions(), + 'components' => $message->getComponents(), + 'attachments' => $message->getAttachments(), + 'flags' => $message->getFlags(), + 'thread_name' => $message->getThreadName(), ]), ); } diff --git a/src/Utopia/Messaging/Adapters/Email.php b/src/Utopia/Messaging/Adapter/Email.php similarity index 93% rename from src/Utopia/Messaging/Adapters/Email.php rename to src/Utopia/Messaging/Adapter/Email.php index e1fcf967..9b395a0e 100644 --- a/src/Utopia/Messaging/Adapters/Email.php +++ b/src/Utopia/Messaging/Adapter/Email.php @@ -1,6 +1,6 @@ SMTPAuth = false; $mail->Username = ''; $mail->Password = ''; - $mail->SMTPSecure = false; + $mail->SMTPSecure = ''; $mail->SMTPAutoTLS = false; $mail->CharSet = 'UTF-8'; $mail->Subject = $message->getSubject(); @@ -54,6 +54,6 @@ protected function process(Email $message): string throw new \Exception($mail->ErrorInfo); } - return true; + return \json_encode($message); } } diff --git a/src/Utopia/Messaging/Adapters/Email/Sendgrid.php b/src/Utopia/Messaging/Adapter/Email/Sendgrid.php similarity index 87% rename from src/Utopia/Messaging/Adapters/Email/Sendgrid.php rename to src/Utopia/Messaging/Adapter/Email/Sendgrid.php index e91c31cc..27be13bc 100644 --- a/src/Utopia/Messaging/Adapters/Email/Sendgrid.php +++ b/src/Utopia/Messaging/Adapter/Email/Sendgrid.php @@ -1,8 +1,8 @@ notify($message->getTo(), $payload)); } + /** + * @param array $to + * @param array $payload + * @return array + * @throws Exception + */ private function notify(array $to, array $payload): array { $headers = [ @@ -78,16 +73,16 @@ private function notify(array $to, array $payload): array 'apns-push-type: alert', ]; - $sh = curl_share_init(); + $sh = \curl_share_init(); - curl_share_setopt($sh, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT); + \curl_share_setopt($sh, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT); - $ch = curl_init(); + $ch = \curl_init(); - curl_setopt($ch, CURLOPT_SHARE, $sh); - curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0); + \curl_setopt($ch, CURLOPT_SHARE, $sh); + \curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0); - curl_setopt_array($ch, [ + \curl_setopt_array($ch, [ CURLOPT_PORT => 443, CURLOPT_HTTPHEADER => $headers, CURLOPT_POST => true, @@ -97,17 +92,15 @@ private function notify(array $to, array $payload): array CURLOPT_HEADER => true, ]); - $response = ''; - - $mh = curl_multi_init(); + $mh = \curl_multi_init(); $handles = []; // Create a handle for each request foreach ($to as $token) { - curl_setopt($ch, CURLOPT_URL, $this->endpoint.'/3/device/'.$token); + \curl_setopt($ch, CURLOPT_URL, $this->endpoint.'/3/device/'.$token); - $handle = curl_copy_handle($ch); - curl_multi_add_handle($mh, $handle); + $handle = \curl_copy_handle($ch); + \curl_multi_add_handle($mh, $handle); $handles[] = $handle; } @@ -117,17 +110,17 @@ private function notify(array $to, array $payload): array // Execute the handles while ($active && $status == CURLM_OK) { - $status = curl_multi_exec($mh, $active); + $status = \curl_multi_exec($mh, $active); } - // Check each handle's result + // Check each handles result $responses = []; foreach ($handles as $ch) { - $urlInfo = curl_getinfo($ch); + $urlInfo = \curl_getinfo($ch); $device = basename($urlInfo['url']); // Extracts deviceToken from the URL - if (! curl_errno($ch)) { - $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + if (! \curl_errno($ch)) { + $statusCode = \curl_getinfo($ch, CURLINFO_HTTP_CODE); $responses[] = [ 'device' => $device, 'status' => 'success', @@ -136,50 +129,23 @@ private function notify(array $to, array $payload): array } else { $responses[$device] = [ 'status' => 'error', - 'error' => curl_error($ch), + 'error' => \curl_error($ch), ]; } - curl_multi_remove_handle($mh, $ch); - curl_close($ch); + \curl_multi_remove_handle($mh, $ch); + \curl_close($ch); } - curl_multi_close($mh); - curl_share_close($sh); + \curl_multi_close($mh); + \curl_share_close($sh); return $responses; } - private function formatResponse(string $response): array - { - $filtered = array_filter( - explode("\r\n", $response), - function ($value) { - return ! empty($value); - } - ); - - $result = []; - - foreach ($filtered as $value) { - if (str_contains($value, 'HTTP')) { - $result['status'] = trim(str_replace('HTTP/2 ', '', $value)); - - continue; - } - - $parts = explode(':', trim($value)); - - $result[$parts[0]] = $parts[1]; - } - - return $result; - } - /** * Generate JWT. * - * @return string * * @throws Exception */ @@ -193,21 +159,21 @@ private function generateJwt(): string // Replaces URL sensitive characters that could be the result of base64 encoding. // Replace to _ to avoid any special handling. - $base64UrlHeader = str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($header)); - $base64UrlClaims = str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($claims)); + $base64UrlHeader = \str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($header)); + $base64UrlClaims = \str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($claims)); if (! $this->authKey) { throw new \Exception('Invalid private key'); } $signature = ''; - $success = openssl_sign("$base64UrlHeader.$base64UrlClaims", $signature, $this->authKey, OPENSSL_ALGO_SHA256); + $success = \openssl_sign("$base64UrlHeader.$base64UrlClaims", $signature, $this->authKey, OPENSSL_ALGO_SHA256); if (! $success) { throw new \Exception('Failed to sign JWT'); } - $base64UrlSignature = str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($signature)); + $base64UrlSignature = \str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($signature)); return "$base64UrlHeader.$base64UrlClaims.$base64UrlSignature"; } diff --git a/src/Utopia/Messaging/Adapters/Push/FCM.php b/src/Utopia/Messaging/Adapter/Push/FCM.php similarity index 91% rename from src/Utopia/Messaging/Adapters/Push/FCM.php rename to src/Utopia/Messaging/Adapter/Push/FCM.php index 8a4d8ac2..4625b905 100644 --- a/src/Utopia/Messaging/Adapters/Push/FCM.php +++ b/src/Utopia/Messaging/Adapter/Push/FCM.php @@ -1,8 +1,8 @@ request( - method: 'POST', - url: 'https://control.msg91.com/api/v5/sms/addTemplate', - headers: [ - 'content-type: application/json', - "authkey: {$this->authKey}", - ], - body: \json_encode([ - 'template' => $content, - 'sender_id' => $senderId, - 'template_name' => $templateName, - 'smsType' => 'NORMAL', - ]) - ); - } } diff --git a/src/Utopia/Messaging/Adapters/SMS/Plivo.php b/src/Utopia/Messaging/Adapter/SMS/Plivo.php similarity index 92% rename from src/Utopia/Messaging/Adapters/SMS/Plivo.php rename to src/Utopia/Messaging/Adapter/SMS/Plivo.php index 4f923fdf..edfd01ff 100644 --- a/src/Utopia/Messaging/Adapters/SMS/Plivo.php +++ b/src/Utopia/Messaging/Adapter/SMS/Plivo.php @@ -1,8 +1,8 @@ $numbers + * @return string + */ private function formatNumbers(array $numbers): string { $formatted = \array_map( diff --git a/src/Utopia/Messaging/Adapters/SMS/Telnyx.php b/src/Utopia/Messaging/Adapter/SMS/Telnyx.php similarity index 91% rename from src/Utopia/Messaging/Adapters/SMS/Telnyx.php rename to src/Utopia/Messaging/Adapter/SMS/Telnyx.php index 431736b5..85719c4f 100644 --- a/src/Utopia/Messaging/Adapters/SMS/Telnyx.php +++ b/src/Utopia/Messaging/Adapter/SMS/Telnyx.php @@ -1,8 +1,8 @@ |null $embeds + * @param array|null $allowedMentions + * @param array|null $components + * @param array|null $attachments + * @param string|null $flags + * @param string|null $threadName + * @param bool|null $wait + * @param string|null $threadId + */ public function __construct( private string $content, private ?string $username = null, private ?string $avatarUrl = null, - ) + private ?bool $tts = null, + private ?array $embeds = null, + private ?array $allowedMentions = null, + private ?array $components = null, + private ?array $attachments = null, + private ?string $flags = null, + private ?string $threadName = null, + private ?bool $wait = null, + private ?string $threadId = null + ) { + } + + public function getContent(): string { + return $this->content; + } + + public function getUsername(): ?string + { + return $this->username; + } + + public function getAvatarUrl(): ?string + { + return $this->avatarUrl; + } + + public function getTts(): ?bool + { + return $this->tts; } /** - * @return string + * @return array|null */ - public function getContent(): string + public function getEmbeds(): ?array { - return $this->content; + return $this->embeds; } /** - * @return string|null + * @return array|null */ - public function getUsername(): ?string + public function getAllowedMentions(): ?array { - return $this->username; + return $this->allowedMentions; } /** - * @return string|null + * @return array|null */ - public function getAvatarUrl(): ?string + public function getComponents(): ?array { - return $this->avatarUrl; + return $this->components; + } + + /** + * @return array|null + */ + public function getAttachments(): ?array + { + return $this->attachments; + } + + public function getFlags(): ?string + { + return $this->flags; + } + + public function getThreadName(): ?string + { + return $this->threadName; + } + + public function getWait(): ?bool + { + return $this->wait; + } + + public function getThreadId(): ?string + { + return $this->threadId; } -} \ No newline at end of file +} diff --git a/src/Utopia/Messaging/Messages/Email.php b/src/Utopia/Messaging/Messages/Email.php index 21fedeea..633d72e0 100644 --- a/src/Utopia/Messaging/Messages/Email.php +++ b/src/Utopia/Messaging/Messages/Email.php @@ -6,12 +6,13 @@ class Email implements Message { + /** - * @param array $to The recipients of the email. + * @param array $to The recipients of the email. * @param string $subject The subject of the email. * @param string $content The content of the email. * @param string|null $from The sender of the email. - * @param array|null $attachments The attachments of the email. + * @param array|null $attachments The attachments of the email. * @param bool $html Whether the message is HTML or not. */ public function __construct( @@ -25,48 +26,36 @@ public function __construct( } /** - * @return array + * @return array */ public function getTo(): array { return $this->to; } - /** - * @return string - */ public function getSubject(): string { return $this->subject; } - /** - * @return string - */ public function getContent(): string { return $this->content; } - /** - * @return string|null - */ public function getFrom(): ?string { return $this->from; } /** - * @return array|null + * @return array|null */ public function getAttachments(): ?array { return $this->attachments; } - /** - * @return bool - */ public function isHtml(): bool { return $this->html; diff --git a/src/Utopia/Messaging/Messages/Push.php b/src/Utopia/Messaging/Messages/Push.php index 93b8f5d7..bf1712f6 100644 --- a/src/Utopia/Messaging/Messages/Push.php +++ b/src/Utopia/Messaging/Messages/Push.php @@ -7,10 +7,10 @@ class Push implements Message { /** - * @param array $to The recipients of the push notification. + * @param array $to The recipients of the push notification. * @param string $title The title of the push notification. * @param string $body The body of the push notification. - * @param array|null $data This parameter specifies the custom key-value pairs of the message's payload. For example, with data:{"score":"3x1"}:

On Apple platforms, if the message is sent via APNs, it represents the custom data fields. If it is sent via FCM, it would be represented as key value dictionary in AppDelegate application:didReceiveRemoteNotification:.

On Android, this would result in an intent extra named score with the string value 3x1.

The key should not be a reserved word ("from", "message_type", or any word starting with "google" or "gcm"). Do not use any of the words defined in this table (such as collapse_key).

Values in string types are recommended. You have to convert values in objects or other non-string data types (e.g., integers or booleans) to string. + * @param array|null $data This parameter specifies the custom key-value pairs of the message's payload. For example, with data:{"score":"3x1"}:

On Apple platforms, if the message is sent via APNs, it represents the custom data fields. If it is sent via FCM, it would be represented as key value dictionary in AppDelegate application:didReceiveRemoteNotification:.

On Android, this would result in an intent extra named score with the string value 3x1.

The key should not be a reserved word ("from", "message_type", or any word starting with "google" or "gcm"). Do not use any of the words defined in this table (such as collapse_key).

Values in string types are recommended. You have to convert values in objects or other non-string data types (e.g., integers or booleans) to string. * @param string|null $sound The sound to play when the device receives the notification.

On Android, sound files must reside in /res/raw/.

On iOS, sounds files must reside in the main bundle of the client app or in the Library/Sounds folder of the app's data container. * @param string|null $action The action associated with a user click on the notification.

On Android, this is the activity to launch.

On iOS, this is the category to launch. * @param string|null $icon Android only. The icon of the push notification. Sets the notification icon to myicon for drawable resource myicon. If you don't send this key in the request, FCM displays the launcher icon specified in your app manifest. @@ -33,7 +33,7 @@ public function __construct( } /** - * @return array + * @return array */ public function getTo(): array { @@ -45,73 +45,49 @@ public function getFrom(): ?string return null; } - /** - * @return string - */ public function getTitle(): string { return $this->title; } - /** - * @return string - */ public function getBody(): string { return $this->body; } /** - * @return array|null + * @return array|null */ public function getData(): ?array { return $this->data; } - /** - * @return string|null - */ public function getAction(): ?string { return $this->action; } - /** - * @return string|null - */ public function getSound(): ?string { return $this->sound; } - /** - * @return string|null - */ public function getIcon(): ?string { return $this->icon; } - /** - * @return string|null - */ public function getColor(): ?string { return $this->color; } - /** - * @return string|null - */ public function getTag(): ?string { return $this->tag; } - /** - * @return string|null - */ public function getBadge(): ?string { return $this->badge; diff --git a/src/Utopia/Messaging/Messages/SMS.php b/src/Utopia/Messaging/Messages/SMS.php index bcb913c0..d96f582b 100644 --- a/src/Utopia/Messaging/Messages/SMS.php +++ b/src/Utopia/Messaging/Messages/SMS.php @@ -6,6 +6,12 @@ class SMS implements Message { + /** + * @param array $to + * @param string $content + * @param string|null $from + * @param array|null $attachments + */ public function __construct( private array $to, private string $content, @@ -15,31 +21,25 @@ public function __construct( } /** - * @return array + * @return array */ public function getTo(): array { return $this->to; } - /** - * @return string - */ public function getContent(): string { return $this->content; } - /** - * @return string|null - */ public function getFrom(): ?string { return $this->from; } /** - * @return array|null + * @return array|null */ public function getAttachments(): ?array { diff --git a/tests/Messaging/Adapter/App/DiscordTest.php b/tests/Messaging/Adapter/App/DiscordTest.php new file mode 100644 index 00000000..967d1888 --- /dev/null +++ b/tests/Messaging/Adapter/App/DiscordTest.php @@ -0,0 +1,33 @@ +send($message), true); + + $this->assertNotEmpty($result); + $this->assertNotEmpty($result['id']); + } +} \ No newline at end of file diff --git a/tests/e2e/Base.php b/tests/Messaging/Adapter/Base.php similarity index 82% rename from tests/e2e/Base.php rename to tests/Messaging/Adapter/Base.php index 14970e51..218cadd9 100644 --- a/tests/e2e/Base.php +++ b/tests/Messaging/Adapter/Base.php @@ -1,11 +1,14 @@ + */ protected function getLastRequest(): array { \sleep(2); @@ -16,6 +19,9 @@ protected function getLastRequest(): array return $request; } + /** + * @return array + */ protected function getLastEmail(): array { sleep(3); diff --git a/tests/e2e/Email/EmailTest.php b/tests/Messaging/Adapter/Email/EmailTest.php similarity index 84% rename from tests/e2e/Email/EmailTest.php rename to tests/Messaging/Adapter/Email/EmailTest.php index 40606255..edd568a4 100644 --- a/tests/e2e/Email/EmailTest.php +++ b/tests/Messaging/Adapter/Email/EmailTest.php @@ -1,8 +1,9 @@ send($message)); + $result = \json_decode($sender->send($message), true); $this->assertArrayHasKey('id', $result); $this->assertArrayHasKey('message', $result); - $this->assertTrue(str_contains(strtolower($result['message']), 'queued')); + $this->assertTrue(\str_contains(\strtolower($result['message']), 'queued')); } } diff --git a/tests/e2e/Email/SendgridTest.php b/tests/Messaging/Adapter/Email/SendgridTest.php similarity index 63% rename from tests/e2e/Email/SendgridTest.php rename to tests/Messaging/Adapter/Email/SendgridTest.php index 9437b167..98426ea3 100644 --- a/tests/e2e/Email/SendgridTest.php +++ b/tests/Messaging/Adapter/Email/SendgridTest.php @@ -1,8 +1,9 @@ send($message); diff --git a/tests/e2e/Push/APNSTest.php b/tests/Messaging/Adapter/Push/APNSTest.php similarity index 67% rename from tests/e2e/Push/APNSTest.php rename to tests/Messaging/Adapter/Push/APNSTest.php index cbd1a354..c24470f0 100644 --- a/tests/e2e/Push/APNSTest.php +++ b/tests/Messaging/Adapter/Push/APNSTest.php @@ -1,24 +1,25 @@ send($message); diff --git a/tests/e2e/SMS/SMSTest.php b/tests/Messaging/Adapter/SMS/SMSTest.php similarity index 86% rename from tests/e2e/SMS/SMSTest.php rename to tests/Messaging/Adapter/SMS/SMSTest.php index b7cdb8be..c935d834 100644 --- a/tests/e2e/SMS/SMSTest.php +++ b/tests/Messaging/Adapter/SMS/SMSTest.php @@ -1,8 +1,9 @@ markTestSkipped('Telesign requires support/sales call in order to enable bulk SMS'); } diff --git a/tests/e2e/SMS/TelnyxTest.php b/tests/Messaging/Adapter/SMS/TelnyxTest.php similarity index 71% rename from tests/e2e/SMS/TelnyxTest.php rename to tests/Messaging/Adapter/SMS/TelnyxTest.php index dc711498..3db276a5 100644 --- a/tests/e2e/SMS/TelnyxTest.php +++ b/tests/Messaging/Adapter/SMS/TelnyxTest.php @@ -1,18 +1,17 @@ send($message); diff --git a/tests/unit/.gitkeep b/tests/unit/.gitkeep deleted file mode 100644 index e69de29b..00000000 From aa635f12eb6e26b6380430201d8865883fdd4a8d Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 2 Nov 2023 00:12:49 +1300 Subject: [PATCH 05/11] Add discord keys to workflow --- .github/workflows/test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 552b207d..47086952 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -40,6 +40,8 @@ jobs: VONAGE_API_SECRET: ${{ secrets.VONAGE_API_SECRET }} VONAGE_TO: ${{ secrets.VONAGE_TO }} VONAGE_FROM: ${{ secrets.VONAGE_FROM }} + DISCORD_WEBHOOK_ID: ${{ secrets.DISCORD_WEBHOOK_ID }} + DISCORD_WEBHOOK_TOKEN: ${{ secrets.DISCORD_WEBHOOK_TOKEN }} run: | docker compose up -d --build sleep 5 From 327acfdde3dddd565386bfc82d5f0913e743031c Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 2 Nov 2023 21:52:32 +1300 Subject: [PATCH 06/11] Lint --- composer.json | 2 +- composer.lock | 167 +++++++++--------- src/Utopia/Messaging/Adapter/Push/APNS.php | 5 +- src/Utopia/Messaging/Adapter/SMS/Telesign.php | 3 +- src/Utopia/Messaging/Messages/Discord.php | 16 +- src/Utopia/Messaging/Messages/Email.php | 1 - src/Utopia/Messaging/Messages/SMS.php | 6 +- tests/Messaging/Adapter/App/DiscordTest.php | 4 +- tests/Messaging/Adapter/Email/EmailTest.php | 2 +- tests/Messaging/Adapter/Email/MailgunTest.php | 2 +- .../Messaging/Adapter/Email/SendgridTest.php | 2 +- tests/Messaging/Adapter/Push/APNSTest.php | 2 +- tests/Messaging/Adapter/Push/FCMTest.php | 2 +- tests/Messaging/Adapter/SMS/SMSTest.php | 2 +- tests/Messaging/Adapter/SMS/TwilioTest.php | 2 +- tests/Messaging/Adapter/SMS/VonageTest.php | 2 +- 16 files changed, 106 insertions(+), 114 deletions(-) diff --git a/composer.json b/composer.json index d081f24c..a422b9f3 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "license": "MIT", "minimum-stability": "stable", "scripts": { - "test": "vendor/bin/phpunit", + "test": "./vendor/bin/phpunit", "lint": "./vendor/bin/pint --test", "format": "./vendor/bin/pint", "analyse": "./vendor/bin/phpstan analyse --memory-limit=2G --level=6 src tests" diff --git a/composer.lock b/composer.lock index 6994d832..80172ea8 100644 --- a/composer.lock +++ b/composer.lock @@ -4,35 +4,35 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "af54d4a3e39567814f90395c0d3ceb8a", + "content-hash": "0afb85e3cb0d85adca85fb5d778af118", "packages": [], "packages-dev": [ { "name": "doctrine/instantiator", - "version": "1.4.1", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "10dcfce151b967d20fde1b34ae6640712c3891bc" + "reference": "c6222283fa3f4ac679f8b9ced9a4e23f163e80d0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/10dcfce151b967d20fde1b34ae6640712c3891bc", - "reference": "10dcfce151b967d20fde1b34ae6640712c3891bc", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/c6222283fa3f4ac679f8b9ced9a4e23f163e80d0", + "reference": "c6222283fa3f4ac679f8b9ced9a4e23f163e80d0", "shasum": "" }, "require": { - "php": "^7.1 || ^8.0" + "php": "^8.1" }, "require-dev": { - "doctrine/coding-standard": "^9", + "doctrine/coding-standard": "^11", "ext-pdo": "*", "ext-phar": "*", - "phpbench/phpbench": "^0.16 || ^1", - "phpstan/phpstan": "^1.4", - "phpstan/phpstan-phpunit": "^1", - "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", - "vimeo/psalm": "^4.22" + "phpbench/phpbench": "^1.2", + "phpstan/phpstan": "^1.9.4", + "phpstan/phpstan-phpunit": "^1.3", + "phpunit/phpunit": "^9.5.27", + "vimeo/psalm": "^5.4" }, "type": "library", "autoload": { @@ -59,7 +59,7 @@ ], "support": { "issues": "https://github.com/doctrine/instantiator/issues", - "source": "https://github.com/doctrine/instantiator/tree/1.4.1" + "source": "https://github.com/doctrine/instantiator/tree/2.0.0" }, "funding": [ { @@ -75,7 +75,7 @@ "type": "tidelift" } ], - "time": "2022-03-03T08:28:38+00:00" + "time": "2022-12-30T00:23:10+00:00" }, { "name": "laravel/pint", @@ -145,16 +145,16 @@ }, { "name": "myclabs/deep-copy", - "version": "1.11.0", + "version": "1.11.1", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "14daed4296fae74d9e3201d2c4925d1acb7aa614" + "reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/14daed4296fae74d9e3201d2c4925d1acb7aa614", - "reference": "14daed4296fae74d9e3201d2c4925d1acb7aa614", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/7284c22080590fb39f2ffa3e9057f10a4ddd0e0c", + "reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c", "shasum": "" }, "require": { @@ -192,7 +192,7 @@ ], "support": { "issues": "https://github.com/myclabs/DeepCopy/issues", - "source": "https://github.com/myclabs/DeepCopy/tree/1.11.0" + "source": "https://github.com/myclabs/DeepCopy/tree/1.11.1" }, "funding": [ { @@ -200,20 +200,20 @@ "type": "tidelift" } ], - "time": "2022-03-03T13:19:32+00:00" + "time": "2023-03-08T13:26:56+00:00" }, { "name": "nikic/php-parser", - "version": "v4.15.1", + "version": "v4.17.1", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "0ef6c55a3f47f89d7a374e6f835197a0b5fcf900" + "reference": "a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/0ef6c55a3f47f89d7a374e6f835197a0b5fcf900", - "reference": "0ef6c55a3f47f89d7a374e6f835197a0b5fcf900", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d", + "reference": "a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d", "shasum": "" }, "require": { @@ -254,9 +254,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v4.15.1" + "source": "https://github.com/nikic/PHP-Parser/tree/v4.17.1" }, - "time": "2022-09-04T07:30:47+00:00" + "time": "2023-08-13T19:53:39+00:00" }, { "name": "phar-io/manifest", @@ -371,16 +371,16 @@ }, { "name": "phpmailer/phpmailer", - "version": "v6.8.0", + "version": "v6.8.1", "source": { "type": "git", "url": "https://github.com/PHPMailer/PHPMailer.git", - "reference": "df16b615e371d81fb79e506277faea67a1be18f1" + "reference": "e88da8d679acc3824ff231fdc553565b802ac016" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPMailer/PHPMailer/zipball/df16b615e371d81fb79e506277faea67a1be18f1", - "reference": "df16b615e371d81fb79e506277faea67a1be18f1", + "url": "https://api.github.com/repos/PHPMailer/PHPMailer/zipball/e88da8d679acc3824ff231fdc553565b802ac016", + "reference": "e88da8d679acc3824ff231fdc553565b802ac016", "shasum": "" }, "require": { @@ -390,13 +390,13 @@ "php": ">=5.5.0" }, "require-dev": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.7.2", + "dealerdirect/phpcodesniffer-composer-installer": "^1.0", "doctrine/annotations": "^1.2.6 || ^1.13.3", "php-parallel-lint/php-console-highlighter": "^1.0.0", "php-parallel-lint/php-parallel-lint": "^1.3.2", "phpcompatibility/php-compatibility": "^9.3.5", "roave/security-advisories": "dev-latest", - "squizlabs/php_codesniffer": "^3.7.1", + "squizlabs/php_codesniffer": "^3.7.2", "yoast/phpunit-polyfills": "^1.0.4" }, "suggest": { @@ -439,7 +439,7 @@ "description": "PHPMailer is a full-featured email creation and transfer class for PHP", "support": { "issues": "https://github.com/PHPMailer/PHPMailer/issues", - "source": "https://github.com/PHPMailer/PHPMailer/tree/v6.8.0" + "source": "https://github.com/PHPMailer/PHPMailer/tree/v6.8.1" }, "funding": [ { @@ -447,7 +447,7 @@ "type": "github" } ], - "time": "2023-03-06T14:43:22+00:00" + "time": "2023-08-29T08:26:30+00:00" }, { "name": "phpstan/phpstan", @@ -513,23 +513,23 @@ }, { "name": "phpunit/php-code-coverage", - "version": "9.2.17", + "version": "9.2.29", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "aa94dc41e8661fe90c7316849907cba3007b10d8" + "reference": "6a3a87ac2bbe33b25042753df8195ba4aa534c76" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/aa94dc41e8661fe90c7316849907cba3007b10d8", - "reference": "aa94dc41e8661fe90c7316849907cba3007b10d8", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/6a3a87ac2bbe33b25042753df8195ba4aa534c76", + "reference": "6a3a87ac2bbe33b25042753df8195ba4aa534c76", "shasum": "" }, "require": { "ext-dom": "*", "ext-libxml": "*", "ext-xmlwriter": "*", - "nikic/php-parser": "^4.14", + "nikic/php-parser": "^4.15", "php": ">=7.3", "phpunit/php-file-iterator": "^3.0.3", "phpunit/php-text-template": "^2.0.2", @@ -544,8 +544,8 @@ "phpunit/phpunit": "^9.3" }, "suggest": { - "ext-pcov": "*", - "ext-xdebug": "*" + "ext-pcov": "PHP extension that provides line coverage", + "ext-xdebug": "PHP extension that provides line coverage as well as branch and path coverage" }, "type": "library", "extra": { @@ -578,7 +578,8 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.17" + "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.29" }, "funding": [ { @@ -586,7 +587,7 @@ "type": "github" } ], - "time": "2022-08-30T12:24:04+00:00" + "time": "2023-09-19T04:57:46+00:00" }, { "name": "phpunit/php-file-iterator", @@ -831,16 +832,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.6.10", + "version": "9.6.13", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "a6d351645c3fe5a30f5e86be6577d946af65a328" + "reference": "f3d767f7f9e191eab4189abe41ab37797e30b1be" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a6d351645c3fe5a30f5e86be6577d946af65a328", - "reference": "a6d351645c3fe5a30f5e86be6577d946af65a328", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/f3d767f7f9e191eab4189abe41ab37797e30b1be", + "reference": "f3d767f7f9e191eab4189abe41ab37797e30b1be", "shasum": "" }, "require": { @@ -855,7 +856,7 @@ "phar-io/manifest": "^2.0.3", "phar-io/version": "^3.0.2", "php": ">=7.3", - "phpunit/php-code-coverage": "^9.2.13", + "phpunit/php-code-coverage": "^9.2.28", "phpunit/php-file-iterator": "^3.0.5", "phpunit/php-invoker": "^3.1.1", "phpunit/php-text-template": "^2.0.3", @@ -914,7 +915,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.10" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.13" }, "funding": [ { @@ -930,7 +931,7 @@ "type": "tidelift" } ], - "time": "2023-07-10T04:04:23+00:00" + "time": "2023-09-19T05:39:22+00:00" }, { "name": "sebastian/cli-parser", @@ -1232,16 +1233,16 @@ }, { "name": "sebastian/diff", - "version": "4.0.4", + "version": "4.0.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "3461e3fccc7cfdfc2720be910d3bd73c69be590d" + "reference": "74be17022044ebaaecfdf0c5cd504fc9cd5a7131" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/3461e3fccc7cfdfc2720be910d3bd73c69be590d", - "reference": "3461e3fccc7cfdfc2720be910d3bd73c69be590d", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/74be17022044ebaaecfdf0c5cd504fc9cd5a7131", + "reference": "74be17022044ebaaecfdf0c5cd504fc9cd5a7131", "shasum": "" }, "require": { @@ -1286,7 +1287,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/diff/issues", - "source": "https://github.com/sebastianbergmann/diff/tree/4.0.4" + "source": "https://github.com/sebastianbergmann/diff/tree/4.0.5" }, "funding": [ { @@ -1294,20 +1295,20 @@ "type": "github" } ], - "time": "2020-10-26T13:10:38+00:00" + "time": "2023-05-07T05:35:17+00:00" }, { "name": "sebastian/environment", - "version": "5.1.4", + "version": "5.1.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "1b5dff7bb151a4db11d49d90e5408e4e938270f7" + "reference": "830c43a844f1f8d5b7a1f6d6076b784454d8b7ed" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/1b5dff7bb151a4db11d49d90e5408e4e938270f7", - "reference": "1b5dff7bb151a4db11d49d90e5408e4e938270f7", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/830c43a844f1f8d5b7a1f6d6076b784454d8b7ed", + "reference": "830c43a844f1f8d5b7a1f6d6076b784454d8b7ed", "shasum": "" }, "require": { @@ -1349,7 +1350,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/environment/issues", - "source": "https://github.com/sebastianbergmann/environment/tree/5.1.4" + "source": "https://github.com/sebastianbergmann/environment/tree/5.1.5" }, "funding": [ { @@ -1357,7 +1358,7 @@ "type": "github" } ], - "time": "2022-04-03T09:37:03+00:00" + "time": "2023-02-03T06:03:51+00:00" }, { "name": "sebastian/exporter", @@ -1438,16 +1439,16 @@ }, { "name": "sebastian/global-state", - "version": "5.0.5", + "version": "5.0.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "0ca8db5a5fc9c8646244e629625ac486fa286bf2" + "reference": "bde739e7565280bda77be70044ac1047bc007e34" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/0ca8db5a5fc9c8646244e629625ac486fa286bf2", - "reference": "0ca8db5a5fc9c8646244e629625ac486fa286bf2", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bde739e7565280bda77be70044ac1047bc007e34", + "reference": "bde739e7565280bda77be70044ac1047bc007e34", "shasum": "" }, "require": { @@ -1490,7 +1491,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/global-state/issues", - "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.5" + "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.6" }, "funding": [ { @@ -1498,7 +1499,7 @@ "type": "github" } ], - "time": "2022-02-14T08:28:10+00:00" + "time": "2023-08-02T09:26:13+00:00" }, { "name": "sebastian/lines-of-code", @@ -1671,16 +1672,16 @@ }, { "name": "sebastian/recursion-context", - "version": "4.0.4", + "version": "4.0.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/recursion-context.git", - "reference": "cd9d8cf3c5804de4341c283ed787f099f5506172" + "reference": "e75bd0f07204fec2a0af9b0f3cfe97d05f92efc1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/cd9d8cf3c5804de4341c283ed787f099f5506172", - "reference": "cd9d8cf3c5804de4341c283ed787f099f5506172", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/e75bd0f07204fec2a0af9b0f3cfe97d05f92efc1", + "reference": "e75bd0f07204fec2a0af9b0f3cfe97d05f92efc1", "shasum": "" }, "require": { @@ -1719,10 +1720,10 @@ } ], "description": "Provides functionality to recursively process PHP variables", - "homepage": "http://www.github.com/sebastianbergmann/recursion-context", + "homepage": "https://github.com/sebastianbergmann/recursion-context", "support": { "issues": "https://github.com/sebastianbergmann/recursion-context/issues", - "source": "https://github.com/sebastianbergmann/recursion-context/tree/4.0.4" + "source": "https://github.com/sebastianbergmann/recursion-context/tree/4.0.5" }, "funding": [ { @@ -1730,7 +1731,7 @@ "type": "github" } ], - "time": "2020-10-26T13:17:30+00:00" + "time": "2023-02-03T06:07:39+00:00" }, { "name": "sebastian/resource-operations", @@ -1789,16 +1790,16 @@ }, { "name": "sebastian/type", - "version": "3.2.0", + "version": "3.2.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/type.git", - "reference": "fb3fe09c5f0bae6bc27ef3ce933a1e0ed9464b6e" + "reference": "75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/fb3fe09c5f0bae6bc27ef3ce933a1e0ed9464b6e", - "reference": "fb3fe09c5f0bae6bc27ef3ce933a1e0ed9464b6e", + "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7", + "reference": "75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7", "shasum": "" }, "require": { @@ -1833,7 +1834,7 @@ "homepage": "https://github.com/sebastianbergmann/type", "support": { "issues": "https://github.com/sebastianbergmann/type/issues", - "source": "https://github.com/sebastianbergmann/type/tree/3.2.0" + "source": "https://github.com/sebastianbergmann/type/tree/3.2.1" }, "funding": [ { @@ -1841,7 +1842,7 @@ "type": "github" } ], - "time": "2022-09-12T14:47:03+00:00" + "time": "2023-02-03T06:13:03+00:00" }, { "name": "sebastian/version", @@ -1956,7 +1957,9 @@ "php": ">=8.0.0", "ext-curl": "*" }, - "platform-dev": [], + "platform-dev": { + "ext-openssl": "*" + }, "platform-overrides": { "php": "8.0" }, diff --git a/src/Utopia/Messaging/Adapter/Push/APNS.php b/src/Utopia/Messaging/Adapter/Push/APNS.php index fa5d30b9..45766fd9 100644 --- a/src/Utopia/Messaging/Adapter/Push/APNS.php +++ b/src/Utopia/Messaging/Adapter/Push/APNS.php @@ -60,9 +60,10 @@ public function process(Push $message): string } /** - * @param array $to - * @param array $payload + * @param array $to + * @param array $payload * @return array + * * @throws Exception */ private function notify(array $to, array $payload): array diff --git a/src/Utopia/Messaging/Adapter/SMS/Telesign.php b/src/Utopia/Messaging/Adapter/SMS/Telesign.php index a0959908..896e90d2 100644 --- a/src/Utopia/Messaging/Adapter/SMS/Telesign.php +++ b/src/Utopia/Messaging/Adapter/SMS/Telesign.php @@ -56,8 +56,7 @@ protected function process(SMS $message): string } /** - * @param array $numbers - * @return string + * @param array $numbers */ private function formatNumbers(array $numbers): string { diff --git a/src/Utopia/Messaging/Messages/Discord.php b/src/Utopia/Messaging/Messages/Discord.php index 7b678988..dffa5fec 100644 --- a/src/Utopia/Messaging/Messages/Discord.php +++ b/src/Utopia/Messaging/Messages/Discord.php @@ -7,18 +7,10 @@ class Discord implements Message { /** - * @param string $content - * @param string|null $username - * @param string|null $avatarUrl - * @param bool|null $tts - * @param array|null $embeds - * @param array|null $allowedMentions - * @param array|null $components - * @param array|null $attachments - * @param string|null $flags - * @param string|null $threadName - * @param bool|null $wait - * @param string|null $threadId + * @param array|null $embeds + * @param array|null $allowedMentions + * @param array|null $components + * @param array|null $attachments */ public function __construct( private string $content, diff --git a/src/Utopia/Messaging/Messages/Email.php b/src/Utopia/Messaging/Messages/Email.php index 633d72e0..8e79c10c 100644 --- a/src/Utopia/Messaging/Messages/Email.php +++ b/src/Utopia/Messaging/Messages/Email.php @@ -6,7 +6,6 @@ class Email implements Message { - /** * @param array $to The recipients of the email. * @param string $subject The subject of the email. diff --git a/src/Utopia/Messaging/Messages/SMS.php b/src/Utopia/Messaging/Messages/SMS.php index d96f582b..a2eb2bad 100644 --- a/src/Utopia/Messaging/Messages/SMS.php +++ b/src/Utopia/Messaging/Messages/SMS.php @@ -7,10 +7,8 @@ class SMS implements Message { /** - * @param array $to - * @param string $content - * @param string|null $from - * @param array|null $attachments + * @param array $to + * @param array|null $attachments */ public function __construct( private array $to, diff --git a/tests/Messaging/Adapter/App/DiscordTest.php b/tests/Messaging/Adapter/App/DiscordTest.php index 967d1888..9096c1d9 100644 --- a/tests/Messaging/Adapter/App/DiscordTest.php +++ b/tests/Messaging/Adapter/App/DiscordTest.php @@ -2,9 +2,9 @@ namespace Utopia\Tests\Adapter\App; -use Utopia\Tests\Adapter\Base; use Utopia\Messaging\Adapter\App\Discord; use Utopia\Messaging\Messages\Discord as DiscordMessage; +use Utopia\Tests\Adapter\Base; class DiscordTest extends Base { @@ -30,4 +30,4 @@ public function testSendMessage(): void $this->assertNotEmpty($result); $this->assertNotEmpty($result['id']); } -} \ No newline at end of file +} diff --git a/tests/Messaging/Adapter/Email/EmailTest.php b/tests/Messaging/Adapter/Email/EmailTest.php index edd568a4..f0064acd 100644 --- a/tests/Messaging/Adapter/Email/EmailTest.php +++ b/tests/Messaging/Adapter/Email/EmailTest.php @@ -2,9 +2,9 @@ namespace Utopia\Tests\Adapter\Email; -use Utopia\Tests\Adapter\Base; use Utopia\Messaging\Adapter\Email\Mock; use Utopia\Messaging\Messages\Email; +use Utopia\Tests\Adapter\Base; class EmailTest extends Base { diff --git a/tests/Messaging/Adapter/Email/MailgunTest.php b/tests/Messaging/Adapter/Email/MailgunTest.php index a6bd0cdb..24fc886c 100644 --- a/tests/Messaging/Adapter/Email/MailgunTest.php +++ b/tests/Messaging/Adapter/Email/MailgunTest.php @@ -2,9 +2,9 @@ namespace Utopia\Tests\Adapter\Email; -use Utopia\Tests\Adapter\Base; use Utopia\Messaging\Adapter\Email\Mailgun; use Utopia\Messaging\Messages\Email; +use Utopia\Tests\Adapter\Base; class MailgunTest extends Base { diff --git a/tests/Messaging/Adapter/Email/SendgridTest.php b/tests/Messaging/Adapter/Email/SendgridTest.php index 98426ea3..244cb93d 100644 --- a/tests/Messaging/Adapter/Email/SendgridTest.php +++ b/tests/Messaging/Adapter/Email/SendgridTest.php @@ -2,9 +2,9 @@ namespace Utopia\Tests\Adapter\Email; -use Utopia\Tests\Adapter\Base; use Utopia\Messaging\Adapter\Email\Sendgrid; use Utopia\Messaging\Messages\Email; +use Utopia\Tests\Adapter\Base; class SendgridTest extends Base { diff --git a/tests/Messaging/Adapter/Push/APNSTest.php b/tests/Messaging/Adapter/Push/APNSTest.php index c24470f0..b612b614 100644 --- a/tests/Messaging/Adapter/Push/APNSTest.php +++ b/tests/Messaging/Adapter/Push/APNSTest.php @@ -2,9 +2,9 @@ namespace Utopia\Tests\Adapter\Push; -use Utopia\Tests\Adapter\Base; use Utopia\Messaging\Adapter\Push\APNS as APNSAdapter; use Utopia\Messaging\Messages\Push; +use Utopia\Tests\Adapter\Base; class APNSTest extends Base { diff --git a/tests/Messaging/Adapter/Push/FCMTest.php b/tests/Messaging/Adapter/Push/FCMTest.php index 121fd5d6..3008962b 100644 --- a/tests/Messaging/Adapter/Push/FCMTest.php +++ b/tests/Messaging/Adapter/Push/FCMTest.php @@ -2,9 +2,9 @@ namespace Utopia\Tests\Adapter\Push; -use Utopia\Tests\Adapter\Base; use Utopia\Messaging\Adapter\Push\FCM as FCMAdapter; use Utopia\Messaging\Messages\Push; +use Utopia\Tests\Adapter\Base; class FCMTest extends Base { diff --git a/tests/Messaging/Adapter/SMS/SMSTest.php b/tests/Messaging/Adapter/SMS/SMSTest.php index c935d834..848b034a 100644 --- a/tests/Messaging/Adapter/SMS/SMSTest.php +++ b/tests/Messaging/Adapter/SMS/SMSTest.php @@ -2,9 +2,9 @@ namespace Utopia\Tests\Adapter\SMS; -use Utopia\Tests\Adapter\Base; use Utopia\Messaging\Adapter\SMS\Mock; use Utopia\Messaging\Messages\SMS; +use Utopia\Tests\Adapter\Base; class SMSTest extends Base { diff --git a/tests/Messaging/Adapter/SMS/TwilioTest.php b/tests/Messaging/Adapter/SMS/TwilioTest.php index 6c1933d4..5a1b7f96 100644 --- a/tests/Messaging/Adapter/SMS/TwilioTest.php +++ b/tests/Messaging/Adapter/SMS/TwilioTest.php @@ -2,9 +2,9 @@ namespace Utopia\Tests\Adapter\SMS; -use Utopia\Tests\Adapter\Base; use Utopia\Messaging\Adapter\SMS\Twilio; use Utopia\Messaging\Messages\SMS; +use Utopia\Tests\Adapter\Base; class TwilioTest extends Base { diff --git a/tests/Messaging/Adapter/SMS/VonageTest.php b/tests/Messaging/Adapter/SMS/VonageTest.php index 3e5d97c1..19d67620 100644 --- a/tests/Messaging/Adapter/SMS/VonageTest.php +++ b/tests/Messaging/Adapter/SMS/VonageTest.php @@ -2,9 +2,9 @@ namespace Utopia\Tests\Adapter\SMS; -use Utopia\Tests\Adapter\Base; use Utopia\Messaging\Adapter\SMS\Vonage; use Utopia\Messaging\Messages\SMS; +use Utopia\Tests\Adapter\Base; class VonageTest extends Base { From 1060cc150138f483b44dfa57940a978892abcda6 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 2 Nov 2023 21:54:15 +1300 Subject: [PATCH 07/11] Fix test config --- phpunit.xml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index 8db6586a..bb763030 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -9,11 +9,8 @@ stopOnFailure="false" > - - ./tests/unit - - - ./tests/e2e/ + + ./tests/ \ No newline at end of file From 28f059927eed9c8e1b9d4317431a66ee34a34142 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 10 Nov 2023 12:21:58 +1300 Subject: [PATCH 08/11] Refactor `App` namespace to `Chat` --- src/Utopia/Messaging/Adapter/{App => Chat}/Discord.php | 2 +- tests/Messaging/Adapter/App/DiscordTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename src/Utopia/Messaging/Adapter/{App => Chat}/Discord.php (98%) diff --git a/src/Utopia/Messaging/Adapter/App/Discord.php b/src/Utopia/Messaging/Adapter/Chat/Discord.php similarity index 98% rename from src/Utopia/Messaging/Adapter/App/Discord.php rename to src/Utopia/Messaging/Adapter/Chat/Discord.php index af3582ab..7b0deea6 100644 --- a/src/Utopia/Messaging/Adapter/App/Discord.php +++ b/src/Utopia/Messaging/Adapter/Chat/Discord.php @@ -1,6 +1,6 @@ Date: Fri, 10 Nov 2023 19:38:03 +1300 Subject: [PATCH 09/11] Stan fixes --- README.md | 10 ++++---- src/Utopia/Messaging/Adapter/SMS/GEOSMS.php | 23 ++++++++++++++----- .../Adapter/SMS/GEOSMS/CallingCode.php | 4 ++-- .../Adapter/SMS/GEOSMS/CallingCodeTest.php | 7 +++--- tests/Messaging/Adapter/SMS/GEOSMSTest.php | 17 +++++++------- 5 files changed, 37 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index d745b630..363d928e 100644 --- a/README.md +++ b/README.md @@ -21,8 +21,8 @@ composer require utopia-php/messaging send($message); send($message); + */ + protected array $localAdapters = []; public function __construct(SMSAdapter $defaultAdapter) { @@ -34,6 +37,10 @@ public function setLocal(string $callingCode, SMSAdapter $adapter): self return $this; } + /** + * @param SMSAdapter $adapter + * @return array + */ protected function filterCallingCodesByAdapter(SMSAdapter $adapter): array { $result = []; @@ -77,6 +84,10 @@ protected function process(SMS $message): string return \json_encode($results); } + /** + * @param array $recipients + * @return array|SMSAdapter> + */ protected function getNextRecipientsAndAdapter(array $recipients): array { $nextRecipients = []; @@ -97,7 +108,7 @@ protected function getNextRecipientsAndAdapter(array $recipients): array protected function getAdapterByPhoneNumber(?string $phoneNumber): SMSAdapter { $callingCode = CallingCode::fromPhoneNumber($phoneNumber); - if ($callingCode === null || empty($callingCode)) { + if (empty($callingCode)) { return $this->defaultAdapter; } diff --git a/src/Utopia/Messaging/Adapter/SMS/GEOSMS/CallingCode.php b/src/Utopia/Messaging/Adapter/SMS/GEOSMS/CallingCode.php index 141c9250..35e8fe0d 100644 --- a/src/Utopia/Messaging/Adapter/SMS/GEOSMS/CallingCode.php +++ b/src/Utopia/Messaging/Adapter/SMS/GEOSMS/CallingCode.php @@ -1,6 +1,6 @@ true, ]; - public static function fromPhoneNumber($number): ?string + public static function fromPhoneNumber(string $number): ?string { $digits = str_replace(['+', ' ', '(', ')', '-'], '', $number); diff --git a/tests/Messaging/Adapter/SMS/GEOSMS/CallingCodeTest.php b/tests/Messaging/Adapter/SMS/GEOSMS/CallingCodeTest.php index 7a460d83..bf64abf5 100644 --- a/tests/Messaging/Adapter/SMS/GEOSMS/CallingCodeTest.php +++ b/tests/Messaging/Adapter/SMS/GEOSMS/CallingCodeTest.php @@ -1,12 +1,13 @@ assertEquals(CallingCode::NORTH_AMERICA, CallingCode::fromPhoneNumber('+11234567890')); $this->assertEquals(CallingCode::INDIA, CallingCode::fromPhoneNumber('+911234567890')); diff --git a/tests/Messaging/Adapter/SMS/GEOSMSTest.php b/tests/Messaging/Adapter/SMS/GEOSMSTest.php index d635ca45..d10b7799 100644 --- a/tests/Messaging/Adapter/SMS/GEOSMSTest.php +++ b/tests/Messaging/Adapter/SMS/GEOSMSTest.php @@ -1,15 +1,16 @@ createMock(SMSAdapter::class); $defaultAdapterMock->method('getName') @@ -34,7 +35,7 @@ public function testSendSMSUsingDefaultAdapter() $this->assertEquals('success', $result['default']['status']); } - public function testSendSMSUsingLocalAdapter() + public function testSendSMSUsingLocalAdapter(): void { $defaultAdapterMock = $this->createMock(SMSAdapter::class); $localAdapterMock = $this->createMock(SMSAdapter::class); @@ -61,7 +62,7 @@ public function testSendSMSUsingLocalAdapter() $this->assertEquals('success', $result['local']['status']); } - public function testSendSMSUsingLocalAdapterAndDefault() + public function testSendSMSUsingLocalAdapterAndDefault(): void { $defaultAdapterMock = $this->createMock(SMSAdapter::class); $defaultAdapterMock->method('getName') @@ -93,7 +94,7 @@ public function testSendSMSUsingLocalAdapterAndDefault() $this->assertEquals('success', $result['default']['status']); } - public function testSendSMSUsingGroupedLocalAdapter() + public function testSendSMSUsingGroupedLocalAdapter(): void { $defaultAdapterMock = $this->createMock(SMSAdapter::class); $localAdapterMock = $this->createMock(SMSAdapter::class); From d38ab4a55acd95a4a6e7388be4087d998d666d87 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 10 Nov 2023 19:42:01 +1300 Subject: [PATCH 10/11] Lint --- src/Utopia/Messaging/Adapter/SMS/GEOSMS.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Utopia/Messaging/Adapter/SMS/GEOSMS.php b/src/Utopia/Messaging/Adapter/SMS/GEOSMS.php index 12b627e3..b3f66429 100644 --- a/src/Utopia/Messaging/Adapter/SMS/GEOSMS.php +++ b/src/Utopia/Messaging/Adapter/SMS/GEOSMS.php @@ -38,7 +38,6 @@ public function setLocal(string $callingCode, SMSAdapter $adapter): self } /** - * @param SMSAdapter $adapter * @return array */ protected function filterCallingCodesByAdapter(SMSAdapter $adapter): array @@ -85,7 +84,7 @@ protected function process(SMS $message): string } /** - * @param array $recipients + * @param array $recipients * @return array|SMSAdapter> */ protected function getNextRecipientsAndAdapter(array $recipients): array From 40e24843500e6eb65702318eb9568f8e9e4c25f3 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 10 Nov 2023 20:01:35 +1300 Subject: [PATCH 11/11] Test downgrade PHPUnit --- composer.json | 2 +- composer.lock | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index a422b9f3..f76d03af 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ }, "require-dev": { "ext-openssl": "*", - "phpunit/phpunit": "9.6.*", + "phpunit/phpunit": "9.6.10", "phpmailer/phpmailer": "6.8.*", "laravel/pint": "1.13.*", "phpstan/phpstan": "1.10.*" diff --git a/composer.lock b/composer.lock index 80172ea8..d07a8bfb 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "0afb85e3cb0d85adca85fb5d778af118", + "content-hash": "1acdc1e8f88c00fae7fc271daa90a725", "packages": [], "packages-dev": [ { @@ -832,16 +832,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.6.13", + "version": "9.6.10", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "f3d767f7f9e191eab4189abe41ab37797e30b1be" + "reference": "a6d351645c3fe5a30f5e86be6577d946af65a328" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/f3d767f7f9e191eab4189abe41ab37797e30b1be", - "reference": "f3d767f7f9e191eab4189abe41ab37797e30b1be", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a6d351645c3fe5a30f5e86be6577d946af65a328", + "reference": "a6d351645c3fe5a30f5e86be6577d946af65a328", "shasum": "" }, "require": { @@ -856,7 +856,7 @@ "phar-io/manifest": "^2.0.3", "phar-io/version": "^3.0.2", "php": ">=7.3", - "phpunit/php-code-coverage": "^9.2.28", + "phpunit/php-code-coverage": "^9.2.13", "phpunit/php-file-iterator": "^3.0.5", "phpunit/php-invoker": "^3.1.1", "phpunit/php-text-template": "^2.0.3", @@ -915,7 +915,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.13" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.10" }, "funding": [ { @@ -931,7 +931,7 @@ "type": "tidelift" } ], - "time": "2023-09-19T05:39:22+00:00" + "time": "2023-07-10T04:04:23+00:00" }, { "name": "sebastian/cli-parser",