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

NotificationService::make()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace CleaniqueCoders\LaravelHelper\Services;
4
5
use CleaniqueCoders\LaravelHelper\Notifications\Notification;
6
7
class NotificationService
8
{
9
    public $user;
10
    public $subject;
11
    public $content;
12
    public $link;
13
    public $link_label;
14
    public $data;
15
    public $template = 'laravel-helper::mail.notification';
16
    public $cc;
17
    public $bcc;
18
    public $attachments;
19
20
    public function __construct($identifier, $column = 'id')
21
    {
22
        $this->user = config('helper.models.user')::where($column, $identifier)->firstOrFail();
23
    }
24
25
    public static function make($identifier)
26
    {
27
        return new self($identifier);
28
    }
29
30
    public function subject($subject)
31
    {
32
        $this->subject = $subject;
33
34
        return $this;
35
    }
36
37
    public function message($content)
38
    {
39
        $this->content = $content;
40
41
        return $this;
42
    }
43
44
    public function link($link)
45
    {
46
        $this->link = $link;
47
48
        return $this;
49
    }
50
51
    public function link_label($link_label)
52
    {
53
        $this->link_label = $link_label;
54
55
        return $this;
56
    }
57
58
    public function data($data)
59
    {
60
        $this->data = $data;
61
62
        return $this;
63
    }
64
65
    public function template($template)
66
    {
67
        $this->template = $template;
68
69
        return $this;
70
    }
71
72
    public function attachments($attachments)
73
    {
74
        $this->attachments = $attachments;
75
76
        return $this;
77
    }
78
79
    public function cc(array $cc)
80
    {
81
        $this->cc = $cc;
82
83
        return $this;
84
    }
85
86
    public function bcc(array $bcc)
87
    {
88
        $this->bcc = $bcc;
89
90
        return $this;
91
    }
92
93
    public function send()
94
    {
95
        if ($this->user) {
96
            $this->user->notify(new Notification(
97
                $this->subject,
98
                $this->content,
99
                $this->link,
100
                $this->link_label,
101
                $this->data,
102
                $this->attachments,
103
                $this->cc,
104
                $this->bcc,
105
                $this->template
106
            ));
107
        } else {
108
            throw new \CleaniqueCoders\LaravelHelper\Exceptions\NoUserSpecifiedException('No User Specified.', 1);
109
        }
110
    }
111
}
112