Passed
Push — main ( e2b24b...b1209d )
by PRATIK
04:16
created

AnnouncementNotification::toSlack()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Adminetic\Announcement\Notifications;
4
5
use Adminetic\Announcement\Mail\AnnouncementMail;
6
use Adminetic\Announcement\Models\Admin\Announcement;
7
use Illuminate\Bus\Queueable;
8
use Illuminate\Notifications\Messages\SlackMessage;
9
use Illuminate\Notifications\Notification;
10
11
class AnnouncementNotification extends Notification
12
{
13
    use Queueable;
14
15
    protected $announcement;
16
17
    /**
18
     * Create a new notification instance.
19
     *
20
     * @return void
21
     */
22
    public function __construct(Announcement $announcement)
23
    {
24
        $this->announcement = $announcement;
25
    }
26
27
    /**
28
     * Get the notification's delivery channels.
29
     *
30
     * @param  mixed  $notifiable
31
     * @return array
32
     */
33
    public function via($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

33
    public function via(/** @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...
34
    {
35
        return $this->announcement->mediums();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->announcement->mediums() targeting Adminetic\Announcement\M...Announcement::mediums() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
36
    }
37
38
    /**
39
     * Get the mail representation of the notification.
40
     *
41
     * @param  mixed  $notifiable
42
     * @return \Illuminate\Notifications\Messages\MailMessage
43
     */
44
    public function toMail($notifiable)
45
    {
46
        return (new AnnouncementMail($this->announcement))
0 ignored issues
show
Bug Best Practice introduced by
The expression return new Adminetic\Ann...>to($notifiable->email) returns the type Adminetic\Announcement\Mail\AnnouncementMail which is incompatible with the documented return type Illuminate\Notifications\Messages\MailMessage.
Loading history...
47
            ->to($notifiable->email);
48
    }
49
50
    /**
51
     * Get the array representation of the notification.
52
     *
53
     * @param  mixed  $notifiable
54
     * @return array
55
     */
56
    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

56
    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...
57
    {
58
        return [
59
            'model' => 'announcement',
60
            'id' => $this->announcement->id,
61
            'date_time' => $this->announcement->created_at->diffForHumans(),
0 ignored issues
show
Bug introduced by
The method diffForHumans() does not exist on DateTime. It seems like you code against a sub-type of DateTime such as Carbon\Carbon. ( Ignorable by Annotation )

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

61
            'date_time' => $this->announcement->created_at->/** @scrutinizer ignore-call */ diffForHumans(),
Loading history...
62
            'announcement_by' => $this->announcement->user->name ?? 'N/A',
63
            'announcement' => $this->announcement->body,
64
        ];
65
    }
66
}
67