Passed
Pull Request — master (#66)
by Vitaliy
03:59 queued 02:18
created

Sound::__construct()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 3
nc 2
nop 3
1
<?php
2
3
declare(strict_types = 1);
4
5
/*
6
 * This file is part of the AppleApnPush package
7
 *
8
 * (c) Vitaliy Zhuk <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code
12
 */
13
14
namespace Apple\ApnPush\Model;
15
16
/**
17
 * Value object for store sound object
18
 */
19
class Sound
20
{
21
    /**
22
     * @var bool
23
     */
24
    private $critical;
25
26
    /**
27
     * @var string
28
     */
29
    private $name;
30
31
    /**
32
     * @var float
33
     */
34
    private $volume;
35
36
    /**
37
     * Constructor.
38
     *
39
     * @param string    $name
40
     * @param float|int $volume
41
     * @param bool      $critical
42
     */
43
    public function __construct(string $name, float $volume = 1.0, bool $critical = false)
44
    {
45
        if ($volume < 0 || $volume > 1) {
46
            throw new \InvalidArgumentException(\sprintf(
47
                'Invalid volume %.2f. Must be between 0.0 and 1.0',
48
                $volume
49
            ));
50
        }
51
52
        $this->name = $name;
53
        $this->volume = $volume;
54
        $this->critical = $critical;
55
    }
56
57
    /**
58
     * Is critical?
59
     *
60
     * @return bool
61
     */
62
    public function isCritical(): bool
63
    {
64
        return $this->critical;
65
    }
66
67
    /**
68
     * Get the name of volume
69
     *
70
     * @return string
71
     */
72
    public function getName(): string
73
    {
74
        return $this->name;
75
    }
76
77
    /**
78
     * Get the volume
79
     *
80
     * @return float
81
     */
82
    public function getVolume(): float
83
    {
84
        return $this->volume;
85
    }
86
}
87