Issues (85)

app/Notifications/MessageCreated.php (4 issues)

1
<?php
2
3
namespace App\Notifications;
4
5
use App\Http\Resources\MessageResource;
6
use App\Models\Message;
7
use Illuminate\Bus\Queueable;
8
use Illuminate\Contracts\Queue\ShouldQueue;
9
use Illuminate\Notifications\Messages\BroadcastMessage;
10
use Illuminate\Notifications\Messages\MailMessage;
11
use Illuminate\Notifications\Notification;
12
13
class MessageCreated extends Notification implements ShouldQueue
14
{
15
    use Queueable;
16
17
    /**
18
     * @var Message
19
     */
20
    public Message $message;
21
22
    /**
23
     * Create a new notification instance.
24
     *
25
     * @param  Message  $message
26
     * @return void
27
     */
28
    public function __construct(Message $message)
29
    {
30
        $this->message = $message;
31
    }
32
33
    /**
34
     * Get the notification's delivery channels.
35
     *
36
     * @param  mixed  $notifiable
37
     * @return array
38
     */
39
    public function via($notifiable)
40
    {
41
        return $notifiable->notify_via;
42
    }
43
44
    /**
45
     * Get the array representation of the notification.
46
     *
47
     * @param  mixed  $notifiable
48
     * @return array
49
     */
50
    public function toArray($notifiable)
0 ignored issues
show
The parameter $notifiable is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

50
    public function toArray(/** @scrutinizer ignore-unused */ $notifiable)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
51
    {
52
        return [
53
            'payload' => (new MessageResource($this->message))->resolve(),
54
        ];
55
    }
56
57
    /**
58
     * Get the mail representation of the notification.
59
     *
60
     * @param  mixed  $notifiable
61
     * @return \Illuminate\Notifications\Messages\MailMessage
62
     */
63
    public function toMail($notifiable)
0 ignored issues
show
The parameter $notifiable is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

63
    public function toMail(/** @scrutinizer ignore-unused */ $notifiable)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
64
    {
65
        $body = json_encode($this->message->body);
0 ignored issues
show
Bug Best Practice introduced by
The property body does not exist on App\Models\Message. Since you implemented __get, consider adding a @property annotation.
Loading history...
66
        $user = $this->message->user();
67
68
        return (new MailMessage)
69
            ->subject('New Message from: '.$user->name)
0 ignored issues
show
The property name does not seem to exist on Illuminate\Database\Eloquent\Relations\BelongsTo.
Loading history...
70
            ->greeting('Hello!')
71
            ->line("{$user->name} pinged you!")
72
            ->line("{$body}")
73
            ->line('Thank you for using our application!');
74
    }
75
}
76