Skip to content

Commit

Permalink
Added return types
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman Ackermann committed Jul 8, 2021
1 parent c8705bb commit 81f70ae
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Exceptions/CouldNotGetToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class CouldNotGetToken extends Exception {

public static function serviceRespondedWithError(string $code, string $message) {
public static function serviceRespondedWithError(string $code, string $message): CouldNotGetToken {
return new static('Microsoft Identity platform responded with code ' . $code . ': ' . $message);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Exceptions/CouldNotReachService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

class CouldNotReachService extends Exception {

public static function networkError() {
public static function networkError(): CouldNotReachService {
return new static('The server couldn\'t be reached');
}

public static function unknownError() {
public static function unknownError(): CouldNotReachService {
return new static('An unknown error occured');
}

Expand Down
4 changes: 2 additions & 2 deletions src/Exceptions/CouldNotSendMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

class CouldNotSendMail extends Exception {

public static function invalidConfig() {
public static function invalidConfig(): CouldNotSendMail {
return new static('The mail.php configuration is missing from address, transport, client and/or secret key configuration');
}

public static function serviceRespondedWithError(string $code, string $message) {
public static function serviceRespondedWithError(string $code, string $message): CouldNotSendMail {
return new static('Microsoft Graph API responded with code ' . $code . ': ' . $message);
}

Expand Down
12 changes: 6 additions & 6 deletions src/MsGraphMailTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function __construct(array $config, ClientInterface $client = null) {
* @throws CouldNotReachService
* @throws CouldNotGetToken
*/
public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = null) {
public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = null): int {
$this->beforeSendPerformed($message);
$payload = $this->getPayload($message);
$url = str_replace('{from}', urlencode($payload['from']['emailAddress']['address']), $this->apiEndpoint);
Expand Down Expand Up @@ -90,7 +90,7 @@ public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = nul
* @param Swift_Mime_SimpleMessage $message
* @return array
*/
protected function getPayload(Swift_Mime_SimpleMessage $message) {
protected function getPayload(Swift_Mime_SimpleMessage $message): array {
$from = $message->getFrom();
$priority = $message->getPriority();
$attachments = $message->getChildren();
Expand Down Expand Up @@ -118,7 +118,7 @@ protected function getPayload(Swift_Mime_SimpleMessage $message) {
* @param array|string $recipients
* @return array
*/
protected function toRecipientCollection($recipients) {
protected function toRecipientCollection($recipients): array {
$collection = [];

// If the provided list is empty
Expand Down Expand Up @@ -158,7 +158,7 @@ protected function toRecipientCollection($recipients) {
* @param $attachments
* @return array
*/
protected function toAttachmentCollection($attachments) {
protected function toAttachmentCollection($attachments): array {
$collection = [];

foreach ($attachments as $attachment) {
Expand Down Expand Up @@ -187,7 +187,7 @@ protected function toAttachmentCollection($attachments) {
* @throws CouldNotGetToken
* @throws CouldNotReachService
*/
protected function getHeaders() {
protected function getHeaders(): array {
return [
'Accept' => 'application/json',
'Authorization' => 'Bearer ' . $this->getAccessToken(),
Expand All @@ -200,7 +200,7 @@ protected function getHeaders() {
* @throws CouldNotReachService
* @throws CouldNotGetToken
*/
protected function getAccessToken() {
protected function getAccessToken(): string {
try {
return Cache::remember('mail-msgraph-accesstoken', 45, function () {
$url = str_replace('{tenant}', $this->config['tenant'] ?? 'common', $this->tokenEndpoint);
Expand Down

0 comments on commit 81f70ae

Please sign in to comment.