Passed
Push — main ( 4834b9...990a94 )
by Usama
03:51
created

CommentPostedNotification   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 18
c 1
b 0
f 1
dl 0
loc 55
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 8 1
A via() 0 6 1
A __construct() 0 3 1
A toMail() 0 10 1
1
<?php
2
3
namespace Usamamuneerchaudhary\Commentify\Notifications;
4
5
use Illuminate\Bus\Queueable;
6
use Illuminate\Contracts\Queue\ShouldQueue;
7
use Illuminate\Notifications\Messages\MailMessage;
8
use Illuminate\Notifications\Notification;
9
use Usamamuneerchaudhary\Commentify\Events\CommentPosted;
10
11
class CommentPostedNotification extends Notification implements ShouldQueue
12
{
13
    use Queueable;
14
15
    /**
16
     * Create a new notification instance.
17
     */
18
    public function __construct(
19
        public CommentPosted $event
20
    ) {
21
    }
22
23
    /**
24
     * Get the notification's delivery channels.
25
     *
26
     * @return array<int, string>
27
     */
28
    public function via(object $notifiable): array
0 ignored issues
show
Unused Code introduced by
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

28
    public function via(/** @scrutinizer ignore-unused */ object $notifiable): array

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...
29
    {
30
        $channels = config('commentify.notification_channels', ['database']);
31
32
        return array_filter($channels, function ($channel) {
33
            return in_array($channel, ['database', 'mail', 'broadcast']);
34
        });
35
    }
36
37
    /**
38
     * Get the mail representation of the notification.
39
     */
40
    public function toMail(object $notifiable): MailMessage
0 ignored issues
show
Unused Code introduced by
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

40
    public function toMail(/** @scrutinizer ignore-unused */ object $notifiable): MailMessage

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...
41
    {
42
        return (new MailMessage)
43
            ->subject(__('commentify::commentify.notifications.comment_posted_subject'))
44
            ->line(__('commentify::commentify.notifications.comment_posted_line', [
45
                'user' => $this->event->comment->user->name,
46
            ]))
47
            ->action(
48
                __('commentify::commentify.notifications.view_comment'),
49
                url('/comments/' . $this->event->comment->id)
50
            );
51
    }
52
53
    /**
54
     * Get the array representation of the notification.
55
     *
56
     * @return array<string, mixed>
57
     */
58
    public function toArray(object $notifiable): array
0 ignored issues
show
Unused Code introduced by
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

58
    public function toArray(/** @scrutinizer ignore-unused */ object $notifiable): array

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...
59
    {
60
        return [
61
            'comment_id' => $this->event->comment->id,
62
            'user_id' => $this->event->comment->user_id,
0 ignored issues
show
Bug introduced by
The property user_id does not exist on Usamamuneerchaudhary\Commentify\Models\Comment. Did you mean user?
Loading history...
63
            'user_name' => $this->event->comment->user->name,
64
            'message' => __('commentify::commentify.notifications.comment_posted_message', [
65
                'user' => $this->event->comment->user->name,
66
            ]),
67
        ];
68
    }
69
}
70
71