TtsVoiceFormat::getGender()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace GinoPane\PHPolyglot\API\Supplemental\TTS;
4
5
use GinoPane\PHPolyglot\Supplemental\Language\Language;
6
use GinoPane\PHPolyglot\Exception\InvalidGenderCodeException;
7
8
/**
9
 * Class TtsVoiceFormat
10
 *
11
 * @author Sergey <Gino Pane> Karavay
12
 */
13
class TtsVoiceFormat
14
{
15
    const GENDER_MALE = 'm';
16
    const GENDER_FEMALE = 'f';
17
18
    /**
19
     * Language to which the voice corresponds
20
     *
21
     * @var Language
22
     */
23
    private $language = null;
24
25
    /**
26
     * Gender to which the voice corresponds
27
     *
28
     * @var string
29
     */
30
    private $gender = '';
31
32
    /**
33
     * TtsVoiceFormat constructor
34
     *
35
     * @param Language $language
36
     * @param string   $gender
37
     *
38
     * @throws InvalidGenderCodeException
39
     */
40
    public function __construct(Language $language, string $gender)
41
    {
42
        $this->language = $language;
43
44
        $this->setGender($gender);
45
    }
46
47
    /**
48
     * @return Language
49
     */
50
    public function getLanguage(): Language
51
    {
52
        return $this->language;
53
    }
54
55
    /**
56
     * @return string
57
     */
58
    public function getGender(): string
59
    {
60
        return $this->gender;
61
    }
62
63
    /**
64
     * @param string $gender
65
     *
66
     * @throws InvalidGenderCodeException
67
     */
68
    private function setGender(string $gender)
69
    {
70
        $gender = strtolower($gender);
71
72
        if (!in_array($gender, [self::GENDER_MALE, self::GENDER_FEMALE])) {
73
            throw new InvalidGenderCodeException($gender);
74
        }
75
76
        $this->gender = $gender;
77
    }
78
}
79