From 113aa4fc517dedf33bb76a183df52007c864c37d Mon Sep 17 00:00:00 2001 From: prateek banga Date: Tue, 19 Dec 2023 21:01:54 +0530 Subject: [PATCH 1/5] adds expiration message for fcm provider --- src/Utopia/Messaging/Adapter.php | 2 +- src/Utopia/Messaging/Adapter/Push/FCM.php | 18 ++++++++++++++---- src/Utopia/Messaging/Response.php | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Utopia/Messaging/Adapter.php b/src/Utopia/Messaging/Adapter.php index 2732f50..ee30283 100644 --- a/src/Utopia/Messaging/Adapter.php +++ b/src/Utopia/Messaging/Adapter.php @@ -35,7 +35,7 @@ abstract public function getMaxMessagesPerRequest(): int; * deliveredTo: int, * type: string, * results: array> - * }> + * }> GEOSMS adapter returns an array of results keyed by adapter name. * * @throws \Exception */ diff --git a/src/Utopia/Messaging/Adapter/Push/FCM.php b/src/Utopia/Messaging/Adapter/Push/FCM.php index eaa2890..42e5bf9 100644 --- a/src/Utopia/Messaging/Adapter/Push/FCM.php +++ b/src/Utopia/Messaging/Adapter/Push/FCM.php @@ -144,10 +144,20 @@ protected function process(PushMessage $message): array if ($result['statusCode'] === 200) { $response->incrementDeliveredTo(); } - $response->addResultForRecipient( - $message->getTo()[$index], - $result['response']['error']['message'] ?? '' - ); + + if (isset($result['response']['error'])) { + $response->addResultForRecipient( + $message->getTo()[$index], + $result['response']['error']['status'] === 'UNREGISTERED' || + $result['response']['error']['status'] === 'INVALID_ARGUMENT' + ? 'Expired device token.' + : $result['response']['error']['message'] ?? '' + ); + + continue; + } + + $response->addResultForRecipient($message->getTo()[$index]); } return $response->toArray(); diff --git a/src/Utopia/Messaging/Response.php b/src/Utopia/Messaging/Response.php index 2b92ce3..9b22146 100644 --- a/src/Utopia/Messaging/Response.php +++ b/src/Utopia/Messaging/Response.php @@ -68,7 +68,7 @@ public function getDetails(): array } /** - * @return array + * @return array{deliveredTo: int, type: string, results: array>} */ public function toArray(): array { From a6ae06f1450a7f5a5f4d75dd24d8c41cb4aba692 Mon Sep 17 00:00:00 2001 From: prateek banga Date: Tue, 19 Dec 2023 23:14:10 +0530 Subject: [PATCH 2/5] moves expired error to push adapter and removes unnnecessary error messages --- src/Utopia/Messaging/Adapter/Push.php | 5 +++++ src/Utopia/Messaging/Adapter/Push/APNS.php | 18 +++--------------- src/Utopia/Messaging/Adapter/Push/FCM.php | 2 +- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/Utopia/Messaging/Adapter/Push.php b/src/Utopia/Messaging/Adapter/Push.php index f2ae469..2989041 100644 --- a/src/Utopia/Messaging/Adapter/Push.php +++ b/src/Utopia/Messaging/Adapter/Push.php @@ -17,6 +17,11 @@ public function getMessageType(): string return PushMessage::class; } + protected static function getExpiredErrorMessage(): string + { + return 'Expired device token.'; + } + /** * Send a push message. * diff --git a/src/Utopia/Messaging/Adapter/Push/APNS.php b/src/Utopia/Messaging/Adapter/Push/APNS.php index fbe0172..4f46e28 100644 --- a/src/Utopia/Messaging/Adapter/Push/APNS.php +++ b/src/Utopia/Messaging/Adapter/Push/APNS.php @@ -103,7 +103,9 @@ public function process(PushMessage $message): array default: $response->addResultForRecipient( $device, - self::getSpecificErrorMessage($result['response']['reason']) + $result['response']['reason'] === 'ExpiredToken' || + $result['response']['reason'] === 'BadDeviceToken' ? + self::getExpiredErrorMessage() : $result['response']['reason'], ); break; } @@ -111,18 +113,4 @@ public function process(PushMessage $message): array return $response->toArray(); } - - private static function getSpecificErrorMessage(string $error): string - { - return match ($error) { - 'MissingDeviceToken' => 'Bad Request. Missing token.', - 'BadDeviceToken' => 'Invalid device token.', - 'ExpiredToken' => 'Expired device token.', - 'PayloadTooLarge' => 'Payload is too large. Messages must be less than 4096 bytes.', - 'TooManyRequests' => 'Too many requests were made to the same device token.', - 'InternalServerError' => 'Internal server error.', - 'PayloadEmpty' => 'Missing payload.', - default => $error, - }; - } } diff --git a/src/Utopia/Messaging/Adapter/Push/FCM.php b/src/Utopia/Messaging/Adapter/Push/FCM.php index 42e5bf9..7a2eec9 100644 --- a/src/Utopia/Messaging/Adapter/Push/FCM.php +++ b/src/Utopia/Messaging/Adapter/Push/FCM.php @@ -150,7 +150,7 @@ protected function process(PushMessage $message): array $message->getTo()[$index], $result['response']['error']['status'] === 'UNREGISTERED' || $result['response']['error']['status'] === 'INVALID_ARGUMENT' - ? 'Expired device token.' + ? self::getExpiredErrorMessage() : $result['response']['error']['message'] ?? '' ); From 15cca1955afdaa9b521d5ff084f8384cd9b635e5 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 10 Jan 2024 21:16:57 +1300 Subject: [PATCH 3/5] Update consts --- composer.json | 4 ++-- src/Utopia/Messaging/Adapter/Chat/Discord.php | 10 +++++++--- src/Utopia/Messaging/Adapter/Email.php | 7 +++++-- src/Utopia/Messaging/Adapter/Email/Mailgun.php | 4 +++- src/Utopia/Messaging/Adapter/Email/Mock.php | 4 +++- src/Utopia/Messaging/Adapter/Email/Sendgrid.php | 4 +++- src/Utopia/Messaging/Adapter/Push.php | 12 ++++++++---- src/Utopia/Messaging/Adapter/Push/APNS.php | 9 ++++++--- src/Utopia/Messaging/Adapter/Push/FCM.php | 9 ++++----- src/Utopia/Messaging/Adapter/SMS.php | 7 +++++-- src/Utopia/Messaging/Adapter/SMS/Clickatell.php | 4 +++- src/Utopia/Messaging/Adapter/SMS/GEOSMS.php | 4 +++- src/Utopia/Messaging/Adapter/SMS/Infobip.php | 4 +++- src/Utopia/Messaging/Adapter/SMS/Mock.php | 5 ----- src/Utopia/Messaging/Adapter/SMS/Msg91.php | 4 +++- src/Utopia/Messaging/Adapter/SMS/Plivo.php | 4 +++- src/Utopia/Messaging/Adapter/SMS/Seven.php | 4 +++- src/Utopia/Messaging/Adapter/SMS/Sinch.php | 4 +++- src/Utopia/Messaging/Adapter/SMS/Telesign.php | 4 +++- src/Utopia/Messaging/Adapter/SMS/Telnyx.php | 4 +++- src/Utopia/Messaging/Adapter/SMS/TextMagic.php | 4 +++- src/Utopia/Messaging/Adapter/SMS/Twilio.php | 4 +++- src/Utopia/Messaging/Adapter/SMS/Vonage.php | 4 +++- 23 files changed, 82 insertions(+), 41 deletions(-) diff --git a/composer.json b/composer.json index 660ff82..35cb342 100644 --- a/composer.json +++ b/composer.json @@ -7,8 +7,8 @@ "minimum-stability": "stable", "scripts": { "test": "./vendor/bin/phpunit", - "lint": "./vendor/bin/pint --test", - "format": "./vendor/bin/pint", + "lint": "./vendor/bin/pint --preset psr12 --test", + "format": "./vendor/bin/pint --preset psr12", "analyse": "./vendor/bin/phpstan analyse --memory-limit=2G --level=6 src tests" }, "autoload": { diff --git a/src/Utopia/Messaging/Adapter/Chat/Discord.php b/src/Utopia/Messaging/Adapter/Chat/Discord.php index 30b4691..61ea3f4 100644 --- a/src/Utopia/Messaging/Adapter/Chat/Discord.php +++ b/src/Utopia/Messaging/Adapter/Chat/Discord.php @@ -8,6 +8,10 @@ class Discord extends Adapter { + private const NAME = 'Discord'; + private const TYPE = 'chat'; + private const MESSAGE_TYPE = DiscordMessage::class; + /** * @param string $webhookId Your Discord webhook ID. * @param string $webhookToken Your Discord webhook token. @@ -20,17 +24,17 @@ public function __construct( public function getName(): string { - return 'Discord'; + return self::NAME; } public function getType(): string { - return 'app'; + return self::TYPE; } public function getMessageType(): string { - return DiscordMessage::class; + return self::MESSAGE_TYPE; } public function getMaxMessagesPerRequest(): int diff --git a/src/Utopia/Messaging/Adapter/Email.php b/src/Utopia/Messaging/Adapter/Email.php index c541428..0bbafba 100644 --- a/src/Utopia/Messaging/Adapter/Email.php +++ b/src/Utopia/Messaging/Adapter/Email.php @@ -7,14 +7,17 @@ abstract class Email extends Adapter { + private const TYPE = 'email'; + private const MESSAGE_TYPE = EmailMessage::class; + public function getType(): string { - return 'email'; + return self::TYPE; } public function getMessageType(): string { - return EmailMessage::class; + return self::MESSAGE_TYPE; } /** diff --git a/src/Utopia/Messaging/Adapter/Email/Mailgun.php b/src/Utopia/Messaging/Adapter/Email/Mailgun.php index 5a5bba2..dac80e9 100644 --- a/src/Utopia/Messaging/Adapter/Email/Mailgun.php +++ b/src/Utopia/Messaging/Adapter/Email/Mailgun.php @@ -8,6 +8,8 @@ class Mailgun extends EmailAdapter { + private const NAME = 'Mailgun'; + /** * @param string $apiKey Your Mailgun API key to authenticate with the API. * @param string $domain Your Mailgun domain to send messages from. @@ -24,7 +26,7 @@ public function __construct( */ public function getName(): string { - return 'Mailgun'; + return self::NAME; } /** diff --git a/src/Utopia/Messaging/Adapter/Email/Mock.php b/src/Utopia/Messaging/Adapter/Email/Mock.php index 81f8c36..fbb8d41 100644 --- a/src/Utopia/Messaging/Adapter/Email/Mock.php +++ b/src/Utopia/Messaging/Adapter/Email/Mock.php @@ -9,9 +9,11 @@ class Mock extends EmailAdapter { + private const NAME = 'Mock'; + public function getName(): string { - return 'Mock'; + return self::NAME; } public function getMaxMessagesPerRequest(): int diff --git a/src/Utopia/Messaging/Adapter/Email/Sendgrid.php b/src/Utopia/Messaging/Adapter/Email/Sendgrid.php index 91ed927..815eccd 100644 --- a/src/Utopia/Messaging/Adapter/Email/Sendgrid.php +++ b/src/Utopia/Messaging/Adapter/Email/Sendgrid.php @@ -8,6 +8,8 @@ class Sendgrid extends EmailAdapter { + private const NAME = 'Sendgrid'; + /** * @param string $apiKey Your Sendgrid API key to authenticate with the API. * @return void @@ -21,7 +23,7 @@ public function __construct(private string $apiKey) */ public function getName(): string { - return 'Sendgrid'; + return self::NAME; } /** diff --git a/src/Utopia/Messaging/Adapter/Push.php b/src/Utopia/Messaging/Adapter/Push.php index 2989041..e1ee92c 100644 --- a/src/Utopia/Messaging/Adapter/Push.php +++ b/src/Utopia/Messaging/Adapter/Push.php @@ -7,19 +7,23 @@ abstract class Push extends Adapter { + private const TYPE = 'push'; + private const MESSAGE_TYPE = PushMessage::class; + private const EXPIRED_MESSAGE = 'Expired device token.'; + public function getType(): string { - return 'push'; + return self::TYPE; } public function getMessageType(): string { - return PushMessage::class; + return self::MESSAGE_TYPE; } - protected static function getExpiredErrorMessage(): string + protected function getExpiredErrorMessage(): string { - return 'Expired device token.'; + return self::EXPIRED_MESSAGE; } /** diff --git a/src/Utopia/Messaging/Adapter/Push/APNS.php b/src/Utopia/Messaging/Adapter/Push/APNS.php index 4f46e28..a2b0000 100644 --- a/src/Utopia/Messaging/Adapter/Push/APNS.php +++ b/src/Utopia/Messaging/Adapter/Push/APNS.php @@ -9,6 +9,8 @@ class APNS extends PushAdapter { + private const NAME = 'APNS'; + /** * @return void */ @@ -26,7 +28,7 @@ public function __construct( */ public function getName(): string { - return 'APNS'; + return self::NAME; } /** @@ -104,8 +106,9 @@ public function process(PushMessage $message): array $response->addResultForRecipient( $device, $result['response']['reason'] === 'ExpiredToken' || - $result['response']['reason'] === 'BadDeviceToken' ? - self::getExpiredErrorMessage() : $result['response']['reason'], + $result['response']['reason'] === 'BadDeviceToken' + ? $this->getExpiredErrorMessage() + : $result['response']['reason'], ); break; } diff --git a/src/Utopia/Messaging/Adapter/Push/FCM.php b/src/Utopia/Messaging/Adapter/Push/FCM.php index 7a2eec9..dd4d0d6 100644 --- a/src/Utopia/Messaging/Adapter/Push/FCM.php +++ b/src/Utopia/Messaging/Adapter/Push/FCM.php @@ -9,10 +9,9 @@ class FCM extends PushAdapter { + private const NAME = 'FCM'; private const DEFAULT_EXPIRY_SECONDS = 3600; // 1 hour - private const DEFAULT_SKEW_SECONDS = 60; // 1 minute - private const GOOGLE_TOKEN_URL = 'https://www.googleapis.com/oauth2/v4/token'; /** @@ -28,7 +27,7 @@ public function __construct( */ public function getName(): string { - return 'FCM'; + return self::NAME; } /** @@ -150,8 +149,8 @@ protected function process(PushMessage $message): array $message->getTo()[$index], $result['response']['error']['status'] === 'UNREGISTERED' || $result['response']['error']['status'] === 'INVALID_ARGUMENT' - ? self::getExpiredErrorMessage() - : $result['response']['error']['message'] ?? '' + ? $this->getExpiredErrorMessage() + : $result['response']['error']['message'] ?? '' ); continue; diff --git a/src/Utopia/Messaging/Adapter/SMS.php b/src/Utopia/Messaging/Adapter/SMS.php index 84ae6da..aa681e9 100644 --- a/src/Utopia/Messaging/Adapter/SMS.php +++ b/src/Utopia/Messaging/Adapter/SMS.php @@ -7,14 +7,17 @@ abstract class SMS extends Adapter { + private const TYPE = 'sms'; + private const MESSAGE_TYPE = SMSMessage::class; + public function getType(): string { - return 'sms'; + return self::TYPE; } public function getMessageType(): string { - return SMSMessage::class; + return self::MESSAGE_TYPE; } /** diff --git a/src/Utopia/Messaging/Adapter/SMS/Clickatell.php b/src/Utopia/Messaging/Adapter/SMS/Clickatell.php index 291f56e..9cd47bd 100644 --- a/src/Utopia/Messaging/Adapter/SMS/Clickatell.php +++ b/src/Utopia/Messaging/Adapter/SMS/Clickatell.php @@ -10,6 +10,8 @@ // https://docs.clickatell.com/channels/sms-channels/sms-api-reference/#tag/SMS-API/operation/sendMessageREST_1 class Clickatell extends SMSAdapter { + private const NAME = 'Clickatell'; + /** * @param string $apiKey Clickatell API Key */ @@ -21,7 +23,7 @@ public function __construct( public function getName(): string { - return 'Clickatell'; + return self::NAME; } public function getMaxMessagesPerRequest(): int diff --git a/src/Utopia/Messaging/Adapter/SMS/GEOSMS.php b/src/Utopia/Messaging/Adapter/SMS/GEOSMS.php index b62c86f..a15297d 100644 --- a/src/Utopia/Messaging/Adapter/SMS/GEOSMS.php +++ b/src/Utopia/Messaging/Adapter/SMS/GEOSMS.php @@ -8,6 +8,8 @@ class GEOSMS extends SMSAdapter { + private const NAME = 'GEOSMS'; + protected SMSAdapter $defaultAdapter; /** @@ -22,7 +24,7 @@ public function __construct(SMSAdapter $defaultAdapter) public function getName(): string { - return 'GEOSMS'; + return self::NAME; } public function getMaxMessagesPerRequest(): int diff --git a/src/Utopia/Messaging/Adapter/SMS/Infobip.php b/src/Utopia/Messaging/Adapter/SMS/Infobip.php index 693733e..378ea7a 100644 --- a/src/Utopia/Messaging/Adapter/SMS/Infobip.php +++ b/src/Utopia/Messaging/Adapter/SMS/Infobip.php @@ -10,6 +10,8 @@ // https://www.infobip.com/docs/api/channels/sms/sms-messaging/outbound-sms/send-sms-message class Infobip extends SMSAdapter { + private const NAME = 'Infobip'; + /** * @param string $apiBaseUrl Infobip API Base Url * @param string $apiKey Infobip API Key @@ -23,7 +25,7 @@ public function __construct( public function getName(): string { - return 'Infobip'; + return self::NAME; } public function getMaxMessagesPerRequest(): int diff --git a/src/Utopia/Messaging/Adapter/SMS/Mock.php b/src/Utopia/Messaging/Adapter/SMS/Mock.php index 983a3e5..dea6ae4 100644 --- a/src/Utopia/Messaging/Adapter/SMS/Mock.php +++ b/src/Utopia/Messaging/Adapter/SMS/Mock.php @@ -18,11 +18,6 @@ public function __construct( ) { } - public function getName(): string - { - return 'Mock'; - } - public function getMaxMessagesPerRequest(): int { return 1000; diff --git a/src/Utopia/Messaging/Adapter/SMS/Msg91.php b/src/Utopia/Messaging/Adapter/SMS/Msg91.php index 7b427d7..4307865 100644 --- a/src/Utopia/Messaging/Adapter/SMS/Msg91.php +++ b/src/Utopia/Messaging/Adapter/SMS/Msg91.php @@ -11,6 +11,8 @@ class Msg91 extends SMSAdapter { + private const NAME = 'Msg91'; + /** * @param string $senderId Msg91 Sender ID * @param string $authKey Msg91 Auth Key @@ -25,7 +27,7 @@ public function __construct( public function getName(): string { - return 'Msg91'; + return self::NAME; } public function getMaxMessagesPerRequest(): int diff --git a/src/Utopia/Messaging/Adapter/SMS/Plivo.php b/src/Utopia/Messaging/Adapter/SMS/Plivo.php index 072b168..a287e12 100644 --- a/src/Utopia/Messaging/Adapter/SMS/Plivo.php +++ b/src/Utopia/Messaging/Adapter/SMS/Plivo.php @@ -10,6 +10,8 @@ // https://www.plivo.com/docs/sms/api/message#send-a-message class Plivo extends SMSAdapter { + private const NAME = 'Plivo'; + /** * @param string $authId Plivo Auth ID * @param string $authToken Plivo Auth Token @@ -23,7 +25,7 @@ public function __construct( public function getName(): string { - return 'Plivo'; + return self::NAME; } public function getMaxMessagesPerRequest(): int diff --git a/src/Utopia/Messaging/Adapter/SMS/Seven.php b/src/Utopia/Messaging/Adapter/SMS/Seven.php index ecba9b3..7a01333 100644 --- a/src/Utopia/Messaging/Adapter/SMS/Seven.php +++ b/src/Utopia/Messaging/Adapter/SMS/Seven.php @@ -10,6 +10,8 @@ // https://www.seven.io/en/docs/gateway/http-api/sms-dispatch/ class Seven extends SMSAdapter { + private const NAME = 'Seven'; + /** * @param string $apiKey Seven API token */ @@ -21,7 +23,7 @@ public function __construct( public function getName(): string { - return 'Seven'; + return self::NAME; } public function getMaxMessagesPerRequest(): int diff --git a/src/Utopia/Messaging/Adapter/SMS/Sinch.php b/src/Utopia/Messaging/Adapter/SMS/Sinch.php index 8a1a242..d37e367 100644 --- a/src/Utopia/Messaging/Adapter/SMS/Sinch.php +++ b/src/Utopia/Messaging/Adapter/SMS/Sinch.php @@ -10,6 +10,8 @@ // https://developers.sinch.com/docs/sms/api-reference/ class Sinch extends SMSAdapter { + private const NAME = 'Sinch'; + /** * @param string $servicePlanId Sinch Service plan ID * @param string $apiToken Sinch API token @@ -23,7 +25,7 @@ public function __construct( public function getName(): string { - return 'Sinch'; + return self::NAME; } public function getMaxMessagesPerRequest(): int diff --git a/src/Utopia/Messaging/Adapter/SMS/Telesign.php b/src/Utopia/Messaging/Adapter/SMS/Telesign.php index 54b45fd..41871dc 100644 --- a/src/Utopia/Messaging/Adapter/SMS/Telesign.php +++ b/src/Utopia/Messaging/Adapter/SMS/Telesign.php @@ -11,6 +11,8 @@ class Telesign extends SMSAdapter { + private const NAME = 'Telesign'; + /** * @param string $username Telesign account username * @param string $password Telesign account password @@ -23,7 +25,7 @@ public function __construct( public function getName(): string { - return 'Telesign'; + return self::NAME; } public function getMaxMessagesPerRequest(): int diff --git a/src/Utopia/Messaging/Adapter/SMS/Telnyx.php b/src/Utopia/Messaging/Adapter/SMS/Telnyx.php index f05c7f4..d79aff4 100644 --- a/src/Utopia/Messaging/Adapter/SMS/Telnyx.php +++ b/src/Utopia/Messaging/Adapter/SMS/Telnyx.php @@ -8,6 +8,8 @@ class Telnyx extends SMSAdapter { + private const NAME = 'Telnyx'; + /** * @param string $apiKey Telnyx APIv2 Key */ @@ -19,7 +21,7 @@ public function __construct( public function getName(): string { - return 'Telnyx'; + return self::NAME; } public function getMaxMessagesPerRequest(): int diff --git a/src/Utopia/Messaging/Adapter/SMS/TextMagic.php b/src/Utopia/Messaging/Adapter/SMS/TextMagic.php index b540aa3..8abfa7a 100644 --- a/src/Utopia/Messaging/Adapter/SMS/TextMagic.php +++ b/src/Utopia/Messaging/Adapter/SMS/TextMagic.php @@ -11,6 +11,8 @@ class TextMagic extends SMSAdapter { + private const NAME = 'Textmagic'; + /** * @param string $username Textmagic account username * @param string $apiKey Textmagic account API key @@ -24,7 +26,7 @@ public function __construct( public function getName(): string { - return 'Textmagic'; + return self::NAME; } public function getMaxMessagesPerRequest(): int diff --git a/src/Utopia/Messaging/Adapter/SMS/Twilio.php b/src/Utopia/Messaging/Adapter/SMS/Twilio.php index e9e46b0..b72a1c4 100644 --- a/src/Utopia/Messaging/Adapter/SMS/Twilio.php +++ b/src/Utopia/Messaging/Adapter/SMS/Twilio.php @@ -8,6 +8,8 @@ class Twilio extends SMSAdapter { + private const NAME = 'Twilio'; + /** * @param string $accountSid Twilio Account SID * @param string $authToken Twilio Auth Token @@ -21,7 +23,7 @@ public function __construct( public function getName(): string { - return 'Twilio'; + return self::NAME; } public function getMaxMessagesPerRequest(): int diff --git a/src/Utopia/Messaging/Adapter/SMS/Vonage.php b/src/Utopia/Messaging/Adapter/SMS/Vonage.php index ce3ff09..47fbf72 100644 --- a/src/Utopia/Messaging/Adapter/SMS/Vonage.php +++ b/src/Utopia/Messaging/Adapter/SMS/Vonage.php @@ -11,6 +11,8 @@ class Vonage extends SMSAdapter { + private const NAME = 'Vonage'; + /** * @param string $apiKey Vonage API Key * @param string $apiSecret Vonage API Secret @@ -24,7 +26,7 @@ public function __construct( public function getName(): string { - return 'Vonage'; + return self::NAME; } public function getMaxMessagesPerRequest(): int From 9824c9111116ac451418d7123127d403e14b9df5 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 11 Jan 2024 12:45:59 +1300 Subject: [PATCH 4/5] PSR12 format --- src/Utopia/Messaging/Adapter.php | 8 ++++---- src/Utopia/Messaging/Adapter/Chat/Discord.php | 4 ++-- src/Utopia/Messaging/Adapter/Email/Mailgun.php | 8 ++++---- src/Utopia/Messaging/Adapter/Email/Mock.php | 2 +- src/Utopia/Messaging/Adapter/Email/Sendgrid.php | 8 ++++---- src/Utopia/Messaging/Adapter/Push/FCM.php | 16 ++++++++-------- src/Utopia/Messaging/Helpers/JWT.php | 6 +++--- src/Utopia/Messaging/Messages/Email.php | 8 ++++---- 8 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/Utopia/Messaging/Adapter.php b/src/Utopia/Messaging/Adapter.php index ee30283..5419755 100644 --- a/src/Utopia/Messaging/Adapter.php +++ b/src/Utopia/Messaging/Adapter.php @@ -41,13 +41,13 @@ abstract public function getMaxMessagesPerRequest(): int; */ public function send(Message $message): array { - if (! \is_a($message, $this->getMessageType())) { + if (!\is_a($message, $this->getMessageType())) { throw new \Exception('Invalid message type.'); } 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')) { + if (!\method_exists($this, 'process')) { throw new \Exception('Adapter does not implement process method.'); } @@ -80,7 +80,7 @@ protected function request( ): array { $ch = \curl_init(); - if (! \is_null($body)) { + if (!\is_null($body)) { $headers[] = 'Content-Length: '.\strlen($body); \curl_setopt($ch, CURLOPT_POSTFIELDS, $body); } @@ -173,7 +173,7 @@ protected function requestMulti( } foreach (\array_combine($urls, $bodies) as $url => $body) { - if (! empty($body)) { + if (!empty($body)) { $headers[] = 'Content-Length: '.\strlen($body); } diff --git a/src/Utopia/Messaging/Adapter/Chat/Discord.php b/src/Utopia/Messaging/Adapter/Chat/Discord.php index 61ea3f4..bc84ff1 100644 --- a/src/Utopia/Messaging/Adapter/Chat/Discord.php +++ b/src/Utopia/Messaging/Adapter/Chat/Discord.php @@ -51,10 +51,10 @@ protected function process(DiscordMessage $message): array { $query = []; - if (! \is_null($message->getWait())) { + if (!\is_null($message->getWait())) { $query['wait'] = $message->getWait(); } - if (! \is_null($message->getThreadId())) { + if (!\is_null($message->getThreadId())) { $query['thread_id'] = $message->getThreadId(); } diff --git a/src/Utopia/Messaging/Adapter/Email/Mailgun.php b/src/Utopia/Messaging/Adapter/Email/Mailgun.php index dac80e9..253f84f 100644 --- a/src/Utopia/Messaging/Adapter/Email/Mailgun.php +++ b/src/Utopia/Messaging/Adapter/Email/Mailgun.php @@ -55,9 +55,9 @@ protected function process(EmailMessage $message): array 'html' => $message->isHtml() ? $message->getContent() : null, ]; - if (! \is_null($message->getCC())) { + if (!\is_null($message->getCC())) { foreach ($message->getCC() as $cc) { - if (! empty($cc['name'])) { + if (!empty($cc['name'])) { $body['cc'] = "{$body['cc']},{$cc['name']}<{$cc['email']}>"; } else { $body['cc'] = "{$body['cc']}, <{$cc['email']}>"; @@ -65,9 +65,9 @@ protected function process(EmailMessage $message): array } } - if (! \is_null($message->getBCC())) { + if (!\is_null($message->getBCC())) { foreach ($message->getBCC() as $bcc) { - if (! empty($bcc['name'])) { + if (!empty($bcc['name'])) { $body['bcc'] = "{$body['bcc']},{$bcc['name']}<{$bcc['email']}>"; } else { $body['bcc'] = "{$body['bcc']}, <{$bcc['email']}>"; diff --git a/src/Utopia/Messaging/Adapter/Email/Mock.php b/src/Utopia/Messaging/Adapter/Email/Mock.php index fbb8d41..0a1454e 100644 --- a/src/Utopia/Messaging/Adapter/Email/Mock.php +++ b/src/Utopia/Messaging/Adapter/Email/Mock.php @@ -50,7 +50,7 @@ protected function process(EmailMessage $message): array $mail->addAddress($to); } - if (! $mail->send()) { + if (!$mail->send()) { foreach ($message->getTo() as $to) { $response->addResultForRecipient($to, $mail->ErrorInfo); } diff --git a/src/Utopia/Messaging/Adapter/Email/Sendgrid.php b/src/Utopia/Messaging/Adapter/Email/Sendgrid.php index 815eccd..c9d0b75 100644 --- a/src/Utopia/Messaging/Adapter/Email/Sendgrid.php +++ b/src/Utopia/Messaging/Adapter/Email/Sendgrid.php @@ -49,9 +49,9 @@ protected function process(EmailMessage $message): array ], ]; - if (! \is_null($message->getCC())) { + if (!\is_null($message->getCC())) { foreach ($message->getCC() as $cc) { - if (! empty($cc['name'])) { + if (!empty($cc['name'])) { $personalizations[0]['cc'][] = [ 'name' => $cc['name'], 'email' => $cc['email'], @@ -64,9 +64,9 @@ protected function process(EmailMessage $message): array } } - if (! \is_null($message->getBCC())) { + if (!\is_null($message->getBCC())) { foreach ($message->getBCC() as $bcc) { - if (! empty($bcc['name'])) { + if (!empty($bcc['name'])) { $personalizations[0]['bcc'][] = [ 'name' => $bcc['name'], 'email' => $bcc['email'], diff --git a/src/Utopia/Messaging/Adapter/Push/FCM.php b/src/Utopia/Messaging/Adapter/Push/FCM.php index dd4d0d6..b976b0e 100644 --- a/src/Utopia/Messaging/Adapter/Push/FCM.php +++ b/src/Utopia/Messaging/Adapter/Push/FCM.php @@ -90,32 +90,32 @@ protected function process(PushMessage $message): array ], ]; - if (! \is_null($message->getData())) { + if (!\is_null($message->getData())) { $shared['message']['data'] = $message->getData(); } - if (! \is_null($message->getAction())) { + if (!\is_null($message->getAction())) { $shared['message']['android']['notification']['click_action'] = $message->getAction(); $shared['message']['apns']['payload']['aps']['category'] = $message->getAction(); } - if (! \is_null($message->getImage())) { + if (!\is_null($message->getImage())) { $shared['message']['android']['notification']['image'] = $message->getImage(); $shared['message']['apns']['payload']['aps']['mutable-content'] = 1; $shared['message']['apns']['fcm_options']['image'] = $message->getImage(); } - if (! \is_null($message->getSound())) { + if (!\is_null($message->getSound())) { $shared['message']['android']['notification']['sound'] = $message->getSound(); $shared['message']['apns']['payload']['aps']['sound'] = $message->getSound(); } - if (! \is_null($message->getIcon())) { + if (!\is_null($message->getIcon())) { $shared['message']['android']['notification']['icon'] = $message->getIcon(); } - if (! \is_null($message->getColor())) { + if (!\is_null($message->getColor())) { $shared['message']['android']['notification']['color'] = $message->getColor(); } - if (! \is_null($message->getTag())) { + if (!\is_null($message->getTag())) { $shared['message']['android']['notification']['tag'] = $message->getTag(); } - if (! \is_null($message->getBadge())) { + if (!\is_null($message->getBadge())) { $shared['message']['apns']['payload']['aps']['badge'] = $message->getBadge(); } diff --git a/src/Utopia/Messaging/Helpers/JWT.php b/src/Utopia/Messaging/Helpers/JWT.php index 58ce506..fe92407 100644 --- a/src/Utopia/Messaging/Helpers/JWT.php +++ b/src/Utopia/Messaging/Helpers/JWT.php @@ -30,7 +30,7 @@ public static function encode(array $payload, string $key, string $algorithm, st 'alg' => $algorithm, ]; - if (! \is_null($keyId)) { + if (!\is_null($keyId)) { $header['kid'] = $keyId; } @@ -67,7 +67,7 @@ private static function sign(string $data, string $key, string $alg): string $success = \openssl_sign($data, $signature, $key, $algorithm); - if (! $success) { + if (!$success) { throw new \Exception('OpenSSL sign failed for JWT'); } @@ -144,7 +144,7 @@ private static function readDER(string $der, int $offset = 0): array $pos++; // Skip the first contents octet (padding indicator) $data = \substr($der, $pos, $len - 1); $pos += $len - 1; - } elseif (! $constructed) { + } elseif (!$constructed) { $data = \substr($der, $pos, $len); $pos += $len; } else { diff --git a/src/Utopia/Messaging/Messages/Email.php b/src/Utopia/Messaging/Messages/Email.php index 268a4dd..2a02e93 100644 --- a/src/Utopia/Messaging/Messages/Email.php +++ b/src/Utopia/Messaging/Messages/Email.php @@ -42,17 +42,17 @@ public function __construct( $this->replyToEmail = $this->fromEmail; } - if (! \is_null($this->cc)) { + if (!\is_null($this->cc)) { foreach ($this->cc as $recipient) { - if (! isset($recipient['name']) || ! isset($recipient['email'])) { + if (!isset($recipient['name']) || !isset($recipient['email'])) { throw new \InvalidArgumentException('Each recipient in cc must have a name and email'); } } } - if (! \is_null($this->bcc)) { + if (!\is_null($this->bcc)) { foreach ($this->bcc as $recipient) { - if (! isset($recipient['name']) || ! isset($recipient['email'])) { + if (!isset($recipient['name']) || !isset($recipient['email'])) { throw new \InvalidArgumentException('Each recipient in bcc must have a name and email'); } } From 57609f2615459e0c54eea4d9ca81d79b2374f49a Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 11 Jan 2024 12:51:44 +1300 Subject: [PATCH 5/5] Fix analysis --- src/Utopia/Messaging/Adapter/Chat/Discord.php | 12 ++++++------ src/Utopia/Messaging/Adapter/Email.php | 8 ++++---- src/Utopia/Messaging/Adapter/Email/Mailgun.php | 4 ++-- src/Utopia/Messaging/Adapter/Email/Mock.php | 4 ++-- src/Utopia/Messaging/Adapter/Email/Sendgrid.php | 4 ++-- src/Utopia/Messaging/Adapter/Push.php | 12 ++++++------ src/Utopia/Messaging/Adapter/Push/APNS.php | 4 ++-- src/Utopia/Messaging/Adapter/Push/FCM.php | 10 +++++----- src/Utopia/Messaging/Adapter/SMS.php | 8 ++++---- src/Utopia/Messaging/Adapter/SMS/Clickatell.php | 4 ++-- src/Utopia/Messaging/Adapter/SMS/GEOSMS.php | 4 ++-- src/Utopia/Messaging/Adapter/SMS/Infobip.php | 4 ++-- src/Utopia/Messaging/Adapter/SMS/Mock.php | 7 +++++++ src/Utopia/Messaging/Adapter/SMS/Msg91.php | 4 ++-- src/Utopia/Messaging/Adapter/SMS/Plivo.php | 4 ++-- src/Utopia/Messaging/Adapter/SMS/Seven.php | 4 ++-- src/Utopia/Messaging/Adapter/SMS/Sinch.php | 4 ++-- src/Utopia/Messaging/Adapter/SMS/Telesign.php | 4 ++-- src/Utopia/Messaging/Adapter/SMS/Telnyx.php | 4 ++-- src/Utopia/Messaging/Adapter/SMS/TextMagic.php | 4 ++-- src/Utopia/Messaging/Adapter/SMS/Twilio.php | 4 ++-- src/Utopia/Messaging/Adapter/SMS/Vonage.php | 4 ++-- src/Utopia/Messaging/Helpers/JWT.php | 6 +++--- 23 files changed, 67 insertions(+), 60 deletions(-) diff --git a/src/Utopia/Messaging/Adapter/Chat/Discord.php b/src/Utopia/Messaging/Adapter/Chat/Discord.php index bc84ff1..b17ecc5 100644 --- a/src/Utopia/Messaging/Adapter/Chat/Discord.php +++ b/src/Utopia/Messaging/Adapter/Chat/Discord.php @@ -8,9 +8,9 @@ class Discord extends Adapter { - private const NAME = 'Discord'; - private const TYPE = 'chat'; - private const MESSAGE_TYPE = DiscordMessage::class; + protected const NAME = 'Discord'; + protected const TYPE = 'chat'; + protected const MESSAGE_TYPE = DiscordMessage::class; /** * @param string $webhookId Your Discord webhook ID. @@ -24,17 +24,17 @@ public function __construct( public function getName(): string { - return self::NAME; + return static::NAME; } public function getType(): string { - return self::TYPE; + return static::TYPE; } public function getMessageType(): string { - return self::MESSAGE_TYPE; + return static::MESSAGE_TYPE; } public function getMaxMessagesPerRequest(): int diff --git a/src/Utopia/Messaging/Adapter/Email.php b/src/Utopia/Messaging/Adapter/Email.php index 0bbafba..267e88c 100644 --- a/src/Utopia/Messaging/Adapter/Email.php +++ b/src/Utopia/Messaging/Adapter/Email.php @@ -7,17 +7,17 @@ abstract class Email extends Adapter { - private const TYPE = 'email'; - private const MESSAGE_TYPE = EmailMessage::class; + protected const TYPE = 'email'; + protected const MESSAGE_TYPE = EmailMessage::class; public function getType(): string { - return self::TYPE; + return static::TYPE; } public function getMessageType(): string { - return self::MESSAGE_TYPE; + return static::MESSAGE_TYPE; } /** diff --git a/src/Utopia/Messaging/Adapter/Email/Mailgun.php b/src/Utopia/Messaging/Adapter/Email/Mailgun.php index 253f84f..48c85ae 100644 --- a/src/Utopia/Messaging/Adapter/Email/Mailgun.php +++ b/src/Utopia/Messaging/Adapter/Email/Mailgun.php @@ -8,7 +8,7 @@ class Mailgun extends EmailAdapter { - private const NAME = 'Mailgun'; + protected const NAME = 'Mailgun'; /** * @param string $apiKey Your Mailgun API key to authenticate with the API. @@ -26,7 +26,7 @@ public function __construct( */ public function getName(): string { - return self::NAME; + return static::NAME; } /** diff --git a/src/Utopia/Messaging/Adapter/Email/Mock.php b/src/Utopia/Messaging/Adapter/Email/Mock.php index 0a1454e..8caa9f3 100644 --- a/src/Utopia/Messaging/Adapter/Email/Mock.php +++ b/src/Utopia/Messaging/Adapter/Email/Mock.php @@ -9,11 +9,11 @@ class Mock extends EmailAdapter { - private const NAME = 'Mock'; + protected const NAME = 'Mock'; public function getName(): string { - return self::NAME; + return static::NAME; } public function getMaxMessagesPerRequest(): int diff --git a/src/Utopia/Messaging/Adapter/Email/Sendgrid.php b/src/Utopia/Messaging/Adapter/Email/Sendgrid.php index c9d0b75..8c22594 100644 --- a/src/Utopia/Messaging/Adapter/Email/Sendgrid.php +++ b/src/Utopia/Messaging/Adapter/Email/Sendgrid.php @@ -8,7 +8,7 @@ class Sendgrid extends EmailAdapter { - private const NAME = 'Sendgrid'; + protected const NAME = 'Sendgrid'; /** * @param string $apiKey Your Sendgrid API key to authenticate with the API. @@ -23,7 +23,7 @@ public function __construct(private string $apiKey) */ public function getName(): string { - return self::NAME; + return static::NAME; } /** diff --git a/src/Utopia/Messaging/Adapter/Push.php b/src/Utopia/Messaging/Adapter/Push.php index e1ee92c..54c8571 100644 --- a/src/Utopia/Messaging/Adapter/Push.php +++ b/src/Utopia/Messaging/Adapter/Push.php @@ -7,23 +7,23 @@ abstract class Push extends Adapter { - private const TYPE = 'push'; - private const MESSAGE_TYPE = PushMessage::class; - private const EXPIRED_MESSAGE = 'Expired device token.'; + protected const TYPE = 'push'; + protected const MESSAGE_TYPE = PushMessage::class; + protected const EXPIRED_MESSAGE = 'Expired device token.'; public function getType(): string { - return self::TYPE; + return static::TYPE; } public function getMessageType(): string { - return self::MESSAGE_TYPE; + return static::MESSAGE_TYPE; } protected function getExpiredErrorMessage(): string { - return self::EXPIRED_MESSAGE; + return static::EXPIRED_MESSAGE; } /** diff --git a/src/Utopia/Messaging/Adapter/Push/APNS.php b/src/Utopia/Messaging/Adapter/Push/APNS.php index a2b0000..dd12bba 100644 --- a/src/Utopia/Messaging/Adapter/Push/APNS.php +++ b/src/Utopia/Messaging/Adapter/Push/APNS.php @@ -9,7 +9,7 @@ class APNS extends PushAdapter { - private const NAME = 'APNS'; + protected const NAME = 'APNS'; /** * @return void @@ -28,7 +28,7 @@ public function __construct( */ public function getName(): string { - return self::NAME; + return static::NAME; } /** diff --git a/src/Utopia/Messaging/Adapter/Push/FCM.php b/src/Utopia/Messaging/Adapter/Push/FCM.php index b976b0e..aa5fbb9 100644 --- a/src/Utopia/Messaging/Adapter/Push/FCM.php +++ b/src/Utopia/Messaging/Adapter/Push/FCM.php @@ -9,10 +9,10 @@ class FCM extends PushAdapter { - private const NAME = 'FCM'; - private const DEFAULT_EXPIRY_SECONDS = 3600; // 1 hour - private const DEFAULT_SKEW_SECONDS = 60; // 1 minute - private const GOOGLE_TOKEN_URL = 'https://www.googleapis.com/oauth2/v4/token'; + protected const NAME = 'FCM'; + protected const DEFAULT_EXPIRY_SECONDS = 3600; // 1 hour + protected const DEFAULT_SKEW_SECONDS = 60; // 1 minute + protected const GOOGLE_TOKEN_URL = 'https://www.googleapis.com/oauth2/v4/token'; /** * @param string $serviceAccountJSON Service account JSON file contents @@ -27,7 +27,7 @@ public function __construct( */ public function getName(): string { - return self::NAME; + return static::NAME; } /** diff --git a/src/Utopia/Messaging/Adapter/SMS.php b/src/Utopia/Messaging/Adapter/SMS.php index aa681e9..4dbcb87 100644 --- a/src/Utopia/Messaging/Adapter/SMS.php +++ b/src/Utopia/Messaging/Adapter/SMS.php @@ -7,17 +7,17 @@ abstract class SMS extends Adapter { - private const TYPE = 'sms'; - private const MESSAGE_TYPE = SMSMessage::class; + protected const TYPE = 'sms'; + protected const MESSAGE_TYPE = SMSMessage::class; public function getType(): string { - return self::TYPE; + return static::TYPE; } public function getMessageType(): string { - return self::MESSAGE_TYPE; + return static::MESSAGE_TYPE; } /** diff --git a/src/Utopia/Messaging/Adapter/SMS/Clickatell.php b/src/Utopia/Messaging/Adapter/SMS/Clickatell.php index 9cd47bd..915ca62 100644 --- a/src/Utopia/Messaging/Adapter/SMS/Clickatell.php +++ b/src/Utopia/Messaging/Adapter/SMS/Clickatell.php @@ -10,7 +10,7 @@ // https://docs.clickatell.com/channels/sms-channels/sms-api-reference/#tag/SMS-API/operation/sendMessageREST_1 class Clickatell extends SMSAdapter { - private const NAME = 'Clickatell'; + protected const NAME = 'Clickatell'; /** * @param string $apiKey Clickatell API Key @@ -23,7 +23,7 @@ public function __construct( public function getName(): string { - return self::NAME; + return static::NAME; } public function getMaxMessagesPerRequest(): int diff --git a/src/Utopia/Messaging/Adapter/SMS/GEOSMS.php b/src/Utopia/Messaging/Adapter/SMS/GEOSMS.php index a15297d..b1955ca 100644 --- a/src/Utopia/Messaging/Adapter/SMS/GEOSMS.php +++ b/src/Utopia/Messaging/Adapter/SMS/GEOSMS.php @@ -8,7 +8,7 @@ class GEOSMS extends SMSAdapter { - private const NAME = 'GEOSMS'; + protected const NAME = 'GEOSMS'; protected SMSAdapter $defaultAdapter; @@ -24,7 +24,7 @@ public function __construct(SMSAdapter $defaultAdapter) public function getName(): string { - return self::NAME; + return static::NAME; } public function getMaxMessagesPerRequest(): int diff --git a/src/Utopia/Messaging/Adapter/SMS/Infobip.php b/src/Utopia/Messaging/Adapter/SMS/Infobip.php index 378ea7a..1ea53b5 100644 --- a/src/Utopia/Messaging/Adapter/SMS/Infobip.php +++ b/src/Utopia/Messaging/Adapter/SMS/Infobip.php @@ -10,7 +10,7 @@ // https://www.infobip.com/docs/api/channels/sms/sms-messaging/outbound-sms/send-sms-message class Infobip extends SMSAdapter { - private const NAME = 'Infobip'; + protected const NAME = 'Infobip'; /** * @param string $apiBaseUrl Infobip API Base Url @@ -25,7 +25,7 @@ public function __construct( public function getName(): string { - return self::NAME; + return static::NAME; } public function getMaxMessagesPerRequest(): int diff --git a/src/Utopia/Messaging/Adapter/SMS/Mock.php b/src/Utopia/Messaging/Adapter/SMS/Mock.php index dea6ae4..0079d8d 100644 --- a/src/Utopia/Messaging/Adapter/SMS/Mock.php +++ b/src/Utopia/Messaging/Adapter/SMS/Mock.php @@ -8,6 +8,8 @@ class Mock extends SMSAdapter { + protected const NAME = 'Mock'; + /** * @param string $user User ID * @param string $secret User secret @@ -18,6 +20,11 @@ public function __construct( ) { } + public function getName(): string + { + return static::NAME; + } + public function getMaxMessagesPerRequest(): int { return 1000; diff --git a/src/Utopia/Messaging/Adapter/SMS/Msg91.php b/src/Utopia/Messaging/Adapter/SMS/Msg91.php index 4307865..c0d52f1 100644 --- a/src/Utopia/Messaging/Adapter/SMS/Msg91.php +++ b/src/Utopia/Messaging/Adapter/SMS/Msg91.php @@ -11,7 +11,7 @@ class Msg91 extends SMSAdapter { - private const NAME = 'Msg91'; + protected const NAME = 'Msg91'; /** * @param string $senderId Msg91 Sender ID @@ -27,7 +27,7 @@ public function __construct( public function getName(): string { - return self::NAME; + return static::NAME; } public function getMaxMessagesPerRequest(): int diff --git a/src/Utopia/Messaging/Adapter/SMS/Plivo.php b/src/Utopia/Messaging/Adapter/SMS/Plivo.php index a287e12..061fa11 100644 --- a/src/Utopia/Messaging/Adapter/SMS/Plivo.php +++ b/src/Utopia/Messaging/Adapter/SMS/Plivo.php @@ -10,7 +10,7 @@ // https://www.plivo.com/docs/sms/api/message#send-a-message class Plivo extends SMSAdapter { - private const NAME = 'Plivo'; + protected const NAME = 'Plivo'; /** * @param string $authId Plivo Auth ID @@ -25,7 +25,7 @@ public function __construct( public function getName(): string { - return self::NAME; + return static::NAME; } public function getMaxMessagesPerRequest(): int diff --git a/src/Utopia/Messaging/Adapter/SMS/Seven.php b/src/Utopia/Messaging/Adapter/SMS/Seven.php index 7a01333..681313e 100644 --- a/src/Utopia/Messaging/Adapter/SMS/Seven.php +++ b/src/Utopia/Messaging/Adapter/SMS/Seven.php @@ -10,7 +10,7 @@ // https://www.seven.io/en/docs/gateway/http-api/sms-dispatch/ class Seven extends SMSAdapter { - private const NAME = 'Seven'; + protected const NAME = 'Seven'; /** * @param string $apiKey Seven API token @@ -23,7 +23,7 @@ public function __construct( public function getName(): string { - return self::NAME; + return static::NAME; } public function getMaxMessagesPerRequest(): int diff --git a/src/Utopia/Messaging/Adapter/SMS/Sinch.php b/src/Utopia/Messaging/Adapter/SMS/Sinch.php index d37e367..0cbaaa5 100644 --- a/src/Utopia/Messaging/Adapter/SMS/Sinch.php +++ b/src/Utopia/Messaging/Adapter/SMS/Sinch.php @@ -10,7 +10,7 @@ // https://developers.sinch.com/docs/sms/api-reference/ class Sinch extends SMSAdapter { - private const NAME = 'Sinch'; + protected const NAME = 'Sinch'; /** * @param string $servicePlanId Sinch Service plan ID @@ -25,7 +25,7 @@ public function __construct( public function getName(): string { - return self::NAME; + return static::NAME; } public function getMaxMessagesPerRequest(): int diff --git a/src/Utopia/Messaging/Adapter/SMS/Telesign.php b/src/Utopia/Messaging/Adapter/SMS/Telesign.php index 41871dc..e9c1674 100644 --- a/src/Utopia/Messaging/Adapter/SMS/Telesign.php +++ b/src/Utopia/Messaging/Adapter/SMS/Telesign.php @@ -11,7 +11,7 @@ class Telesign extends SMSAdapter { - private const NAME = 'Telesign'; + protected const NAME = 'Telesign'; /** * @param string $username Telesign account username @@ -25,7 +25,7 @@ public function __construct( public function getName(): string { - return self::NAME; + return static::NAME; } public function getMaxMessagesPerRequest(): int diff --git a/src/Utopia/Messaging/Adapter/SMS/Telnyx.php b/src/Utopia/Messaging/Adapter/SMS/Telnyx.php index d79aff4..118be67 100644 --- a/src/Utopia/Messaging/Adapter/SMS/Telnyx.php +++ b/src/Utopia/Messaging/Adapter/SMS/Telnyx.php @@ -8,7 +8,7 @@ class Telnyx extends SMSAdapter { - private const NAME = 'Telnyx'; + protected const NAME = 'Telnyx'; /** * @param string $apiKey Telnyx APIv2 Key @@ -21,7 +21,7 @@ public function __construct( public function getName(): string { - return self::NAME; + return static::NAME; } public function getMaxMessagesPerRequest(): int diff --git a/src/Utopia/Messaging/Adapter/SMS/TextMagic.php b/src/Utopia/Messaging/Adapter/SMS/TextMagic.php index 8abfa7a..81da593 100644 --- a/src/Utopia/Messaging/Adapter/SMS/TextMagic.php +++ b/src/Utopia/Messaging/Adapter/SMS/TextMagic.php @@ -11,7 +11,7 @@ class TextMagic extends SMSAdapter { - private const NAME = 'Textmagic'; + protected const NAME = 'Textmagic'; /** * @param string $username Textmagic account username @@ -26,7 +26,7 @@ public function __construct( public function getName(): string { - return self::NAME; + return static::NAME; } public function getMaxMessagesPerRequest(): int diff --git a/src/Utopia/Messaging/Adapter/SMS/Twilio.php b/src/Utopia/Messaging/Adapter/SMS/Twilio.php index b72a1c4..8e15e8c 100644 --- a/src/Utopia/Messaging/Adapter/SMS/Twilio.php +++ b/src/Utopia/Messaging/Adapter/SMS/Twilio.php @@ -8,7 +8,7 @@ class Twilio extends SMSAdapter { - private const NAME = 'Twilio'; + protected const NAME = 'Twilio'; /** * @param string $accountSid Twilio Account SID @@ -23,7 +23,7 @@ public function __construct( public function getName(): string { - return self::NAME; + return static::NAME; } public function getMaxMessagesPerRequest(): int diff --git a/src/Utopia/Messaging/Adapter/SMS/Vonage.php b/src/Utopia/Messaging/Adapter/SMS/Vonage.php index 47fbf72..c950e17 100644 --- a/src/Utopia/Messaging/Adapter/SMS/Vonage.php +++ b/src/Utopia/Messaging/Adapter/SMS/Vonage.php @@ -11,7 +11,7 @@ class Vonage extends SMSAdapter { - private const NAME = 'Vonage'; + protected const NAME = 'Vonage'; /** * @param string $apiKey Vonage API Key @@ -26,7 +26,7 @@ public function __construct( public function getName(): string { - return self::NAME; + return static::NAME; } public function getMaxMessagesPerRequest(): int diff --git a/src/Utopia/Messaging/Helpers/JWT.php b/src/Utopia/Messaging/Helpers/JWT.php index fe92407..ba4f4b8 100644 --- a/src/Utopia/Messaging/Helpers/JWT.php +++ b/src/Utopia/Messaging/Helpers/JWT.php @@ -4,7 +4,7 @@ class JWT { - private const ALGORITHMS = [ + protected const ALGORITHMS = [ 'ES384' => ['openssl', OPENSSL_ALGO_SHA384], 'ES256' => ['openssl', OPENSSL_ALGO_SHA256], 'ES256K' => ['openssl', OPENSSL_ALGO_SHA256], @@ -55,11 +55,11 @@ public static function encode(array $payload, string $key, string $algorithm, st */ private static function sign(string $data, string $key, string $alg): string { - if (empty(self::ALGORITHMS[$alg])) { + if (empty(static::ALGORITHMS[$alg])) { throw new \Exception('Algorithm not supported'); } - [$function, $algorithm] = self::ALGORITHMS[$alg]; + [$function, $algorithm] = static::ALGORITHMS[$alg]; switch ($function) { case 'openssl':