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