HooksMessage::url()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace NotificationChannels\Hooks;
4
5
class HooksMessage implements \JsonSerializable
6
{
7
    /** @var int Alert ID. */
8
    public $alertId;
9
10
    /** @var string Notification Message. */
11
    public $message;
12
13
    /** @var string Notification URL. */
14
    public $url;
15
16
    /**
17
     * @param int    $alertId
18
     * @param string $message
19
     * @param string $url
20
     *
21
     * @return static
22
     */
23
    public static function create($alertId = null, $message = '', $url = '')
24
    {
25
        return new static($alertId, $message, $url);
26
    }
27
28
    /**
29
     * @param int    $alertId
30
     * @param string $message
31
     * @param string $url
32
     */
33
    public function __construct($alertId = null, $message = '', $url = '')
34
    {
35
        $this->alertId = $alertId;
36
        $this->message = $message;
37
        $this->url = $url;
38
    }
39
40
    /**
41
     * Alert ID associated with this notification.
42
     *
43
     * @param int $alertId
44
     *
45
     * @return $this
46
     */
47
    public function alertId($alertId)
48
    {
49
        $this->alertId = $alertId;
50
51
        return $this;
52
    }
53
54
    /**
55
     * Notification message.
56
     *
57
     * @param $message
58
     *
59
     * @return $this
60
     */
61
    public function message($message)
62
    {
63
        $this->message = $message;
64
65
        return $this;
66
    }
67
68
    /**
69
     * Notification Url.
70
     *
71
     * @param string $url
72
     *
73
     * @return $this
74
     */
75
    public function url($url)
76
    {
77
        $this->url = $url;
78
79
        return $this;
80
    }
81
82
    /**
83
     * Determine if alert id is not given.
84
     *
85
     * @return bool
86
     */
87
    public function alertIdNotGiven()
88
    {
89
        return !isset($this->alertId);
90
    }
91
92
    /**
93
     * Convert the object into something JSON serializable.
94
     *
95
     * @return array
96
     */
97
    public function jsonSerialize()
98
    {
99
        return $this->toArray();
100
    }
101
102
    /**
103
     * Returns payload.
104
     *
105
     * @return array
106
     */
107
    public function toArray()
108
    {
109
        $payload = [];
110
        $payload['alertId'] = $this->alertId;
111
        $payload['message'] = $this->message;
112
113
        if (isset($this->url)) {
114
            $payload['url'] = $this->url;
115
        }
116
117
        return $payload;
118
    }
119
}
120