Completed
Branch version-1 (e85622)
by Alex
04:13
created

MessageAction   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 144
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 11
eloc 22
dl 0
loc 144
ccs 0
cts 49
cp 0
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A setTitle() 0 5 1
A getAction() 0 3 1
A setIcon() 0 5 1
A setAction() 0 5 1
A toArray() 0 6 1
A getIcon() 0 3 1
A getTitle() 0 3 1
A jsonSerialize() 0 3 1
A __toString() 0 7 2
A toJson() 0 3 1
1
<?php
2
3
namespace AlexLisenkov\LaravelWebPush;
4
5
use AlexLisenkov\LaravelWebPush\Contracts\MessageActionContract;
6
7
abstract class MessageAction implements MessageActionContract
8
{
9
    /**
10
     * A DOMString identifying a user action to be displayed on the notification.
11
     *
12
     * @var string
13
     */
14
    protected $action;
15
16
    /**
17
     * A DOMString containing action text to be shown to the user.
18
     *
19
     * @var string
20
     */
21
    protected $title;
22
23
    /**
24
     * A USVString containing the URL of an icon to display with the action.
25
     *
26
     * @var string
27
     */
28
    protected $icon;
29
30
    /**
31
     * Get Action
32
     *
33
     * @return string
34
     */
35
    public function getAction(): string
36
    {
37
        return $this->action;
38
    }
39
40
    /**
41
     * Set Action
42
     *
43
     * @param string $action
44
     *
45
     * @return MessageAction
46
     */
47
    public function setAction(string $action): MessageAction
48
    {
49
        $this->action = $action;
50
51
        return $this;
52
    }
53
54
    /**
55
     * Get Title
56
     *
57
     * @return string
58
     */
59
    public function getTitle(): string
60
    {
61
        return $this->title;
62
    }
63
64
    /**
65
     * Set Title
66
     *
67
     * @param string $title
68
     *
69
     * @return MessageAction
70
     */
71
    public function setTitle(string $title): MessageAction
72
    {
73
        $this->title = $title;
74
75
        return $this;
76
    }
77
78
    /**
79
     * Get Icon
80
     *
81
     * @return string
82
     */
83
    public function getIcon(): ?string
84
    {
85
        return $this->icon;
86
    }
87
88
    /**
89
     * Set Icon
90
     *
91
     * @param string $icon
92
     *
93
     * @return MessageAction
94
     */
95
    public function setIcon(string $icon): MessageAction
96
    {
97
        $this->icon = $icon;
98
99
        return $this;
100
    }
101
102
    /**
103
     * Get the instance as an array.
104
     *
105
     * @return array
106
     */
107
    public function toArray()
108
    {
109
        return [
110
            'action' => $this->getAction(),
111
            'title' => $this->getTitle(),
112
            'icon' => $this->getIcon(),
113
        ];
114
    }
115
116
    /**
117
     * Convert the object to its JSON representation.
118
     *
119
     * @param int $options
120
     *
121
     * @return false|string
122
     */
123
    public function toJson($options = PushMessage::DEFAULT_ENCODING_OPTIONS)
124
    {
125
        return json_encode($this->toArray(), $options);
126
    }
127
128
    /**
129
     * @return string
130
     */
131
    public function __toString(): string
132
    {
133
        if( $string = $this->toJson() ){
134
            return (string) $string;
135
        }
136
137
        return '';
138
    }
139
140
    /**
141
     * Specify data which should be serialized to JSON
142
     *
143
     * @link https://php.net/manual/en/jsonserializable.jsonserialize.php
144
     * @return mixed data which can be serialized by <b>json_encode</b>,
145
     * which is a value of any type other than a resource.
146
     * @since 5.4.0
147
     */
148
    public function jsonSerialize(): string
149
    {
150
        return $this->toJson();
151
    }
152
}
153