Skip to content

Commit

Permalink
Update consts
Browse files Browse the repository at this point in the history
  • Loading branch information
abnegate committed Jan 10, 2024
1 parent a6ae06f commit 15cca19
Show file tree
Hide file tree
Showing 23 changed files with 82 additions and 41 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
10 changes: 7 additions & 3 deletions src/Utopia/Messaging/Adapter/Chat/Discord.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions src/Utopia/Messaging/Adapter/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/Utopia/Messaging/Adapter/Email/Mailgun.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -24,7 +26,7 @@ public function __construct(
*/
public function getName(): string
{
return 'Mailgun';
return self::NAME;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/Utopia/Messaging/Adapter/Email/Mock.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/Utopia/Messaging/Adapter/Email/Sendgrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,7 +23,7 @@ public function __construct(private string $apiKey)
*/
public function getName(): string
{
return 'Sendgrid';
return self::NAME;
}

/**
Expand Down
12 changes: 8 additions & 4 deletions src/Utopia/Messaging/Adapter/Push.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
9 changes: 6 additions & 3 deletions src/Utopia/Messaging/Adapter/Push/APNS.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

class APNS extends PushAdapter
{
private const NAME = 'APNS';

/**
* @return void
*/
Expand All @@ -26,7 +28,7 @@ public function __construct(
*/
public function getName(): string
{
return 'APNS';
return self::NAME;
}

/**
Expand Down Expand Up @@ -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;
}
Expand Down
9 changes: 4 additions & 5 deletions src/Utopia/Messaging/Adapter/Push/FCM.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand All @@ -28,7 +27,7 @@ public function __construct(
*/
public function getName(): string
{
return 'FCM';
return self::NAME;
}

/**
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions src/Utopia/Messaging/Adapter/SMS.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/Utopia/Messaging/Adapter/SMS/Clickatell.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -21,7 +23,7 @@ public function __construct(

public function getName(): string
{
return 'Clickatell';
return self::NAME;
}

public function getMaxMessagesPerRequest(): int
Expand Down
4 changes: 3 additions & 1 deletion src/Utopia/Messaging/Adapter/SMS/GEOSMS.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

class GEOSMS extends SMSAdapter
{
private const NAME = 'GEOSMS';

protected SMSAdapter $defaultAdapter;

/**
Expand All @@ -22,7 +24,7 @@ public function __construct(SMSAdapter $defaultAdapter)

public function getName(): string
{
return 'GEOSMS';
return self::NAME;
}

public function getMaxMessagesPerRequest(): int
Expand Down
4 changes: 3 additions & 1 deletion src/Utopia/Messaging/Adapter/SMS/Infobip.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,7 +25,7 @@ public function __construct(

public function getName(): string
{
return 'Infobip';
return self::NAME;
}

public function getMaxMessagesPerRequest(): int
Expand Down
5 changes: 0 additions & 5 deletions src/Utopia/Messaging/Adapter/SMS/Mock.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ public function __construct(
) {
}

public function getName(): string
{
return 'Mock';
}

public function getMaxMessagesPerRequest(): int
{
return 1000;
Expand Down
4 changes: 3 additions & 1 deletion src/Utopia/Messaging/Adapter/SMS/Msg91.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

class Msg91 extends SMSAdapter
{
private const NAME = 'Msg91';

/**
* @param string $senderId Msg91 Sender ID
* @param string $authKey Msg91 Auth Key
Expand All @@ -25,7 +27,7 @@ public function __construct(

public function getName(): string
{
return 'Msg91';
return self::NAME;
}

public function getMaxMessagesPerRequest(): int
Expand Down
4 changes: 3 additions & 1 deletion src/Utopia/Messaging/Adapter/SMS/Plivo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,7 +25,7 @@ public function __construct(

public function getName(): string
{
return 'Plivo';
return self::NAME;
}

public function getMaxMessagesPerRequest(): int
Expand Down
4 changes: 3 additions & 1 deletion src/Utopia/Messaging/Adapter/SMS/Seven.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -21,7 +23,7 @@ public function __construct(

public function getName(): string
{
return 'Seven';
return self::NAME;
}

public function getMaxMessagesPerRequest(): int
Expand Down
4 changes: 3 additions & 1 deletion src/Utopia/Messaging/Adapter/SMS/Sinch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,7 +25,7 @@ public function __construct(

public function getName(): string
{
return 'Sinch';
return self::NAME;
}

public function getMaxMessagesPerRequest(): int
Expand Down
4 changes: 3 additions & 1 deletion src/Utopia/Messaging/Adapter/SMS/Telesign.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

class Telesign extends SMSAdapter
{
private const NAME = 'Telesign';

/**
* @param string $username Telesign account username
* @param string $password Telesign account password
Expand All @@ -23,7 +25,7 @@ public function __construct(

public function getName(): string
{
return 'Telesign';
return self::NAME;
}

public function getMaxMessagesPerRequest(): int
Expand Down
4 changes: 3 additions & 1 deletion src/Utopia/Messaging/Adapter/SMS/Telnyx.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

class Telnyx extends SMSAdapter
{
private const NAME = 'Telnyx';

/**
* @param string $apiKey Telnyx APIv2 Key
*/
Expand All @@ -19,7 +21,7 @@ public function __construct(

public function getName(): string
{
return 'Telnyx';
return self::NAME;
}

public function getMaxMessagesPerRequest(): int
Expand Down
Loading

0 comments on commit 15cca19

Please sign in to comment.