EngageMessage::icon()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace NotificationChannels\Engage;
4
5
class EngageMessage
6
{
7
    /**
8
     * Notification url.
9
     *
10
     * @var string
11
     */
12
    protected $url;
13
14
    /**
15
     * Notification message.
16
     *
17
     * @var string
18
     */
19
    protected $body;
20
21
    /**
22
     * Notification icon.
23
     *
24
     * @var string
25
     */
26
    protected $icon;
27
28
    /**
29
     * Notification title.
30
     *
31
     * @var string
32
     */
33
    protected $subject;
34
35 8
    public function __construct($body = '')
36
    {
37 8
        $this->body = $body;
38 8
    }
39
40
    /**
41
     * Create a message.
42
     *
43
     * @param string $body
44
     * @return static
45
     */
46 1
    public static function create($body = '')
47
    {
48 1
        return new static($body);
49
    }
50
51
    /**
52
     * Set the message body.
53
     *
54
     * @param string $value
55
     * @return $this
56
     */
57 3
    public function body($value)
58
    {
59 3
        $this->body = $value;
60
61 3
        return $this;
62
    }
63
64
    /**
65
     * Set the message subject.
66
     *
67
     * @param string $value
68
     * @return $this
69
     */
70 3
    public function subject($value)
71
    {
72 3
        $this->subject = $value;
73
74 3
        return $this;
75
    }
76
77
    /**
78
     * Set the message url.
79
     *
80
     * @param string $value
81
     * @return $this
82
     */
83 3
    public function url($value)
84
    {
85 3
        $this->url = $value;
86
87 3
        return $this;
88
    }
89
90
    /**
91
     * Set the message icon.
92
     *
93
     * @param string $value
94
     * @return $this
95
     */
96 3
    public function icon($value)
97
    {
98 3
        $this->icon = $value;
99
100 3
        return $this;
101
    }
102
103
    /**
104
     * Get message as array.
105
     *
106
     * @return array
107
     */
108 8
    public function toArray()
109
    {
110
        $message = [
111 8
            'url' => $this->url,
112 8
            'title' => $this->subject,
113 8
            'message' => $this->body,
114
        ];
115
116 8
        if ($this->icon) {
117 3
            $message['image_url'] = $this->icon;
118
        }
119
120 8
        return $message;
121
    }
122
}
123