diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index d2ecb11..5fc51d0 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,5 +1,15 @@ parameters: ignoreErrors: + - + message: "#^Method InnoGE\\\\LaravelMsGraphMail\\\\MicrosoftGraphTransport\\:\\:transformEmailAddress\\(\\) return type has no value type specified in iterable type array\\.$#" + count: 1 + path: src/MicrosoftGraphTransport.php + + - + message: "#^Method InnoGE\\\\LaravelMsGraphMail\\\\MicrosoftGraphTransport\\:\\:transformEmailAddresses\\(\\) should return array\\\\>\\> but returns array\\.$#" + count: 1 + path: src/MicrosoftGraphTransport.php + - message: "#^Parameter \\#1 \\$message of static method Symfony\\\\Component\\\\Mime\\\\MessageConverter\\:\\:toEmail\\(\\) expects Symfony\\\\Component\\\\Mime\\\\Message, Symfony\\\\Component\\\\Mime\\\\RawMessage given\\.$#" count: 1 @@ -9,3 +19,13 @@ parameters: message: "#^Parameter \\#2 \\$html of method InnoGE\\\\LaravelMsGraphMail\\\\MicrosoftGraphTransport\\:\\:prepareAttachments\\(\\) expects string\\|null, resource\\|string\\|null given\\.$#" count: 1 path: src/MicrosoftGraphTransport.php + + - + message: "#^Method InnoGE\\\\LaravelMsGraphMail\\\\Services\\\\MicrosoftGraphApiService\\:\\:getAccessToken\\(\\) should return string but returns mixed\\.$#" + count: 1 + path: src/Services/MicrosoftGraphApiService.php + + - + message: "#^Method InnoGE\\\\LaravelMsGraphMail\\\\Services\\\\MicrosoftGraphApiService\\:\\:sendMail\\(\\) has parameter \\$payload with no value type specified in iterable type array\\.$#" + count: 1 + path: src/Services/MicrosoftGraphApiService.php diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 9aa5399..40e24a1 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -8,5 +8,3 @@ parameters: tmpDir: build/phpstan checkOctaneCompatibility: true checkModelProperties: true - checkMissingIterableValueType: false - checkGenericClassInNonGenericObjectType: false diff --git a/src/Exceptions/InvalidResponse.php b/src/Exceptions/InvalidResponse.php index d63b963..d72a436 100644 --- a/src/Exceptions/InvalidResponse.php +++ b/src/Exceptions/InvalidResponse.php @@ -4,6 +4,4 @@ use Exception; -class InvalidResponse extends Exception -{ -} +class InvalidResponse extends Exception {} diff --git a/src/MicrosoftGraphTransport.php b/src/MicrosoftGraphTransport.php index 9264699..517100c 100644 --- a/src/MicrosoftGraphTransport.php +++ b/src/MicrosoftGraphTransport.php @@ -61,6 +61,9 @@ protected function doSend(SentMessage $message): void $this->microsoftGraphApiService->sendMail($envelope->getSender()->getAddress(), $payload); } + /** + * @return array, array>|string|null> + */ protected function prepareAttachments(Email $email, ?string $html): array { $attachments = []; @@ -83,6 +86,7 @@ protected function prepareAttachments(Email $email, ?string $html): array /** * @param Collection $recipients + * @return array>> */ protected function transformEmailAddresses(Collection $recipients): array { diff --git a/src/Services/MicrosoftGraphApiService.php b/src/Services/MicrosoftGraphApiService.php index 17e0c69..08e7bb8 100644 --- a/src/Services/MicrosoftGraphApiService.php +++ b/src/Services/MicrosoftGraphApiService.php @@ -3,7 +3,6 @@ namespace InnoGE\LaravelMsGraphMail\Services; use Illuminate\Http\Client\PendingRequest; -use Illuminate\Http\Client\RequestException; use Illuminate\Http\Client\Response; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Http; @@ -16,12 +15,8 @@ public function __construct( protected readonly string $clientId, protected readonly string $clientSecret, protected readonly int $accessTokenTtl - ) { - } + ) {} - /** - * @throws RequestException - */ public function sendMail(string $from, array $payload): Response { return $this->getBaseRequest() @@ -50,10 +45,7 @@ protected function getAccessToken(): string $response->throw(); $accessToken = $response->json('access_token'); - if (! is_string($accessToken)) { - $notString = var_export($accessToken, true); - throw new InvalidResponse("Expected response to contain key access_token of type string, got: {$notString}."); - } + throw_unless(is_string($accessToken), new InvalidResponse('Expected response to contain key access_token of type string, got: '.var_export($accessToken, true).'.')); return $accessToken; }); diff --git a/tests/MicrosoftGraphTransportTest.php b/tests/MicrosoftGraphTransportTest.php index 259d7bd..219f69b 100644 --- a/tests/MicrosoftGraphTransportTest.php +++ b/tests/MicrosoftGraphTransportTest.php @@ -33,7 +33,7 @@ Mail::to('caleb@livewire.com') ->bcc('tim@innoge.de') ->cc('nuno@laravel.com') - ->send(new TestMail()); + ->send(new TestMail); Http::assertSent(function (Request $value) { expect($value) @@ -371,11 +371,11 @@ Mail::to('caleb@livewire.com') ->bcc('tim@innoge.de') ->cc('nuno@laravel.com') - ->send(new TestMailWithInlineImage()); + ->send(new TestMailWithInlineImage); Http::assertSent(function (Request $value) { // ContentId gets random generated, so get this value first and check for equality later - $inlineImageContentId = json_decode($value->body())->message->attachments[1]->contentId; + $inlineImageContentId = json_decode($value->body())->message->attachments[0]->contentId; expect($value) ->url()->toBe('https://graph.microsoft.com/v1.0/users/taylor@laravel.com/sendMail') @@ -415,14 +415,6 @@ ], ], 'attachments' => [ - [ - '@odata.type' => '#microsoft.graph.fileAttachment', - 'name' => 'test-file-1.txt', - 'contentType' => 'text', - 'contentBytes' => 'Zm9vCg==', - 'contentId' => 'test-file-1.txt', - 'isInline' => false, - ], [ '@odata.type' => '#microsoft.graph.fileAttachment', 'name' => $inlineImageContentId, diff --git a/tests/Stubs/TestMail.php b/tests/Stubs/TestMail.php index 7a05440..4660801 100644 --- a/tests/Stubs/TestMail.php +++ b/tests/Stubs/TestMail.php @@ -18,9 +18,7 @@ class TestMail extends Mailable * * @return void */ - public function __construct(private readonly bool $isHtml = true) - { - } + public function __construct(private readonly bool $isHtml = true) {} /** * Get the message envelope. diff --git a/tests/Stubs/TestMailWithInlineImage.php b/tests/Stubs/TestMailWithInlineImage.php index f22f305..0bd0373 100644 --- a/tests/Stubs/TestMailWithInlineImage.php +++ b/tests/Stubs/TestMailWithInlineImage.php @@ -3,7 +3,6 @@ namespace InnoGE\LaravelMsGraphMail\Tests\Stubs; use Illuminate\Bus\Queueable; -use Illuminate\Mail\Attachment; use Illuminate\Mail\Mailable; use Illuminate\Mail\Mailables\Content; use Illuminate\Mail\Mailables\Envelope; @@ -18,9 +17,7 @@ class TestMailWithInlineImage extends Mailable * * @return void */ - public function __construct(private readonly bool $isHtml = true) - { - } + public function __construct(private readonly bool $isHtml = true) {} /** * Get the message envelope. @@ -47,14 +44,4 @@ public function content() return new Content(html: 'html-mail-with-inline-image'); } - - /** - * Get the attachments for the message. - */ - public function attachments(): array - { - return [ - Attachment::fromPath('tests/Resources/files/test-file-1.txt'), - ]; - } }