NotificationService   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 111
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 13
eloc 44
c 1
b 0
f 0
dl 0
loc 111
rs 10

12 Methods

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