Skip to content

Commit

Permalink
Support MailMessage in UsedEmailViewCollector (#2064)
Browse files Browse the repository at this point in the history
Co-authored-by: Alexey Koryazhkin <[email protected]>
  • Loading branch information
koraga and Alexey Koryazhkin authored Oct 14, 2024
1 parent 70b4889 commit 549c524
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 6 deletions.
7 changes: 6 additions & 1 deletion src/Collectors/UsedEmailViewCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Larastan\Larastan\Collectors;

use Illuminate\Mail\Mailable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\View\ViewName;
use PhpParser\Node;
use PhpParser\Node\Identifier;
Expand Down Expand Up @@ -42,7 +43,11 @@ public function processNode(Node $node, Scope $scope): string|null

$class = $node->var;

if (! (new ObjectType(Mailable::class))->isSuperTypeOf($scope->getType($class))->yes()) {
$type = $scope->getType($class);
if (
! (new ObjectType(Mailable::class))->isSuperTypeOf($type)->yes()
&& ! (new ObjectType(MailMessage::class))->isSuperTypeOf($type)->yes()
) {
return null;
}

Expand Down
20 changes: 17 additions & 3 deletions tests/Rules/data/FooController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Contracts\View\View;
use Illuminate\Mail\Mailable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Support\Facades\Route;
use Illuminate\View\Factory;

Expand All @@ -30,16 +31,29 @@ public function notExisting(): View
}
}

class FooEmail extends Mailable
class FooMailable extends Mailable
{
public function build(): self
{
return $this->markdown('emails.markdown');
return $this->markdown('emails.mailable.markdown');
}

public function bar(): self
{
return $this->view('emails.view');
return $this->view('emails.mailable.view');
}
}

class FooMailMessage extends MailMessage
{
public function build(): self
{
return $this->markdown('emails.mail-message.markdown');
}

public function bar(): self
{
return $this->view('emails.mail-message.view');
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Used with $this->markdown('emails.mail-message.markdown')
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Used with $this->view('emails.mail-message.view')
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Used with $this->markdown('emails.mailable.markdown')
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Used with $this->view('emails.mailable.view')

This file was deleted.

1 change: 0 additions & 1 deletion tests/application/resources/views/emails/view.blade.php

This file was deleted.

0 comments on commit 549c524

Please sign in to comment.