Completed
Push — master ( 27c2d8...4e28bb )
by Nasrul Hazim
02:29
created

Notification::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 9
dl 0
loc 16
rs 9.9666
c 0
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace CleaniqueCoders\LaravelHelper\Notifications;
4
5
use Illuminate\Bus\Queueable;
6
use Illuminate\Notifications\Messages\MailMessage;
7
use Illuminate\Notifications\Notification as BaseNotification;
8
9
class Notification extends BaseNotification
10
{
11
    use Queueable;
12
13
    public $subject;
14
    public $content;
15
    public $link;
16
    public $link_label;
17
    public $data;
18
    public $template;
19
    public $cc;
20
    public $bcc;
21
    public $attachments;
22
23
    /**
24
     * Create a new notification instance.
25
     */
26
    public function __construct(
27
        $subject, $content,
28
        $link = null, $link_label = null,
29
        $data = null, $attachments = null,
30
        $cc = null, $bcc = null,
31
        $template = 'mail.notification'
32
    ) {
33
        $this->subject     = $subject;
34
        $this->content     = $content;
35
        $this->link        = $link;
36
        $this->link_label  = $link_label;
37
        $this->data        = $data;
38
        $this->template    = $template;
39
        $this->cc          = $cc;
40
        $this->bcc         = $bcc;
41
        $this->attachments = $attachments;
42
    }
43
44
    /**
45
     * Get the notification's delivery channels.
46
     *
47
     * @param mixed $notifiable
48
     *
49
     * @return array
50
     */
51
    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

51
    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...
52
    {
53
        return ['mail', 'database'];
54
    }
55
56
    /**
57
     * Get the mail representation of the notification.
58
     *
59
     * @param mixed $notifiable
60
     *
61
     * @return \Illuminate\Notifications\Messages\MailMessage
62
     */
63
    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

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
        $mail = (new MailMessage())
66
            ->subject($this->subject)
67
            ->markdown($this->template, [
68
                'subject'    => $this->subject,
69
                'content'    => $this->content,
70
                'link'       => $this->link,
71
                'link_label' => $this->link_label,
72
                'data'       => $this->data,
73
            ]);
74
75
        if ($this->cc) {
76
            $mail->cc($this->cc);
77
        }
78
79
        if ($this->bcc) {
80
            $mail->bcc($this->bcc);
81
        }
82
83
        if ($this->attachments) {
84
            if (is_array($this->attachments)) {
85
                foreach ($this->attachments as $attachment) {
86
                    $mail->attach($attachment);
87
                }
88
            } else {
89
                $mail->attach($this->attachments);
90
            }
91
        }
92
93
        return $mail;
94
    }
95
96
    /**
97
     * Get the array representation of the notification.
98
     *
99
     * @param mixed $notifiable
100
     *
101
     * @return array
102
     */
103
    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

103
    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...
104
    {
105
        return [
106
            'subject'     => $this->subject,
107
            'content'     => $this->content,
108
            'link'        => $this->link,
109
            'link_label'  => $this->link_label,
110
            'data'        => $this->data,
111
            'template'    => $this->template,
112
            'cc'          => $this->cc,
113
            'bcc'         => $this->bcc,
114
            'attachments' => $this->attachments,
115
        ];
116
    }
117
}
118