Completed
Push — master ( 26655b...34e7f3 )
by Arthur
01:23 queued 11s
created

Sound::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the Pushok package.
5
 *
6
 * (c) Arthur Edamov <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Pushok\Payload;
13
14
/**
15
 * Class Sound
16
 *
17
 * @package Pushok\Payload
18
 *
19
 * @see http://bit.ly/payload-key-reference
20
 */
21
class Sound implements \JsonSerializable
22
{
23
    const SOUND_CRITICAL_KEY = 'critical';
24
    const SOUND_NAME_KEY = 'name';
25
    const SOUND_VOLUME_KEY = 'volume';
26
27
    /**
28
     * Whether the sound should be played as a critical notification or not
29
     *
30
     * @var integer
31
     */
32
    private $critical;
33
34
    /**
35
     * The sound file name.
36
     *
37
     * @var string
38
     */
39
    private $name;
40
41
    /**
42
     * The sound volume.
43
     *
44
     * @var float
45
     */
46
    private $volume;
47
48
    protected function __construct()
49
    {
50
    }
51
52
    public static function create()
53
    {
54
        return new self();
55
    }
56
57
    /**
58
     * Set Sound critical.
59
     *
60
     * @param int $value
61
     * @return Sound
62
     */
63
    public function setCritical(int $value): Sound
64
    {
65
        $this->critical = $value;
66
67
        return $this;
68
    }
69
70
    /**
71
     * Get Sound critical.
72
     *
73
     * @return string
74
     */
75
    public function getCritical()
76
    {
77
        return $this->critical;
78
    }
79
80
    /**
81
     * Set Sound name.
82
     *
83
     * @param string $value
84
     * @return Sound
85
     */
86
    public function setName(string $value): Sound
87
    {
88
        $this->name = $value;
89
90
        return $this;
91
    }
92
93
    /**
94
     * Get Sound name.
95
     *
96
     * @return string
97
     */
98
    public function getName()
99
    {
100
        return $this->name;
101
    }
102
103
    /**
104
     * Set Sound volume.
105
     *
106
     * @param float $value
107
     * @return Sound
108
     */
109
    public function setVolume(float $value): Sound
110
    {
111
        $this->volume = $value;
112
113
        return $this;
114
    }
115
116
    /**
117
     * Get Sound volume.
118
     *
119
     * @return float
120
     */
121
    public function getVolume()
122
    {
123
        return $this->volume;
124
    }
125
126
    /**
127
     * Convert Sound to JSON.
128
     *
129
     * @return string
130
     */
131
    public function toJson(): string
132
    {
133
        return json_encode($this, JSON_UNESCAPED_UNICODE);
134
    }
135
136
    /**
137
     * Specify data which should be serialized to JSON.
138
     *
139
     * @return array
140
     * @link   http://php.net/manual/en/jsonserializable.jsonserialize.php
141
     */
142
    public function jsonSerialize()
143
    {
144
        $sound = [];
145
146
        if (is_integer($this->critical)) {
147
            $sound[self::SOUND_CRITICAL_KEY] = $this->critical;
148
        }
149
150
        if (is_string($this->name)) {
151
            $sound[self::SOUND_NAME_KEY] = $this->name;
152
        }
153
154
        if (is_float($this->volume)) {
155
            $sound[self::SOUND_VOLUME_KEY] = $this->volume;
156
        }
157
158
        return $sound;
159
    }
160
}
161