Passed
Push — master ( 955c25...e9527a )
by Burak
09:28
created

MessageCreated   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Test Coverage

Coverage 26.32%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
eloc 16
c 5
b 0
f 0
dl 0
loc 72
ccs 5
cts 19
cp 0.2632
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A via() 0 3 1
A toBroadcast() 0 4 1
A toMail() 0 11 1
A toArray() 0 3 1
A __construct() 0 3 1
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 10
    public function __construct(Message $message)
29
    {
30 10
        $this->message = $message;
31 10
    }
32
33
    /**
34
     * Get the notification's delivery channels.
35
     *
36
     * @param  mixed  $notifiable
37
     * @return array
38
     */
39 10
    public function via($notifiable)
40
    {
41 10
        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
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

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 (new MessageResource($this->message))->resolve();
53
    }
54
55
    /**
56
     * Get the broadcastable representation of the notification.
57
     *
58
     * @param  mixed  $notifiable
59
     * @return BroadcastMessage
60
     */
61
    public function toBroadcast($notifiable)
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

61
    public function toBroadcast(/** @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...
62
    {
63
        return new BroadcastMessage(
64
            (new MessageResource($this->message))->resolve()
65
        );
66
    }
67
68
    /**
69
     * Get the mail representation of the notification.
70
     *
71
     * @param  mixed  $notifiable
72
     * @return \Illuminate\Notifications\Messages\MailMessage
73
     */
74
    public function toMail($notifiable)
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

74
    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...
75
    {
76
        $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...
77
        $user = $this->message->user();
78
79
        return (new MailMessage)
80
            ->subject('New Message from: '.$user->name)
0 ignored issues
show
Bug introduced by
The property name does not seem to exist on Illuminate\Database\Eloquent\Relations\BelongsTo.
Loading history...
81
            ->greeting('Hello!')
82
            ->line("{$user->name} pinged you!")
83
            ->line("{$body}")
84
            ->line('Thank you for using our application!');
85
    }
86
}
87