Yandex   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 120
Duplicated Lines 13.33 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 13
c 2
b 0
f 0
lcom 1
cbo 3
dl 16
loc 120
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
B synthesize() 16 26 2
A getUri() 0 5 1
A getSpeaker() 0 4 1
A setOksanaSpeaker() 0 5 1
A setAlyssSpeaker() 0 5 1
A setJaneSpeaker() 0 5 1
A setOmazhSpeaker() 0 5 1
A setZaharSpeaker() 0 5 1
A setErmilSpeaker() 0 5 1
A setSpeaker() 0 5 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 *
4
 * PHP version 5.5
5
 *
6
 * @package TTS
7
 * @author  Sergey V.Kuzin <[email protected]>
8
 * @license MIT
9
 */
10
11
namespace TTS;
12
13
14
use Psr\Log\LoggerInterface;
15
use TTS\Helper\SplitterText;
16
use TTS\Traits\OnlineTrait;
17
18
class Yandex extends TextToSpeechAbstract
19
{
20
    use OnlineTrait;
21
22
    const SPEAKER_JANE = 'jane';
23
    const SPEAKER_OKSANA = 'oksana';
24
    const SPEAKER_ALYSS = 'alyss';
25
    const SPEAKER_OMAZH = 'omazh';
26
    const SPEAKER_ZAHAR = 'zahar';
27
    const SPEAKER_ERMIL = 'ermil';
28
29
    protected $driver = 'Yandex';
30
31
    protected $vote = self::VOTE_FEMALE;
32
33
    protected $speaker = 'oksana';
34
35
    protected $apiKey;
36
    /**
37
     * @param string $apiKey
38
     * @param LoggerInterface $logger
39
     * @param array $options
40
     */
41
    public function __construct($apiKey, LoggerInterface $logger = null, array $options = [])
42
    {
43
        if (!is_string($apiKey)) {
44
            throw new \InvalidArgumentException('$apiKey must string');
45
        }
46
47
        $this->apiKey = $apiKey;
48
        parent::__construct($logger, $options);
49
    }
50
51
    protected function synthesize($text, $outFile)
52
    {
53
        $sp = new SplitterText();
54
        $text = iconv('UTF-8', 'UTF-8', $text);
55
56
        $lines = $sp->split($text, 512);
57
        $content = '';
58 View Code Duplication
        foreach ($lines as $line) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
59
            $query = [
60
                'format'    => 'mp3',
61
                'quality'   => 'hi',
62
                'text'      => $line,
63
                'speaker'   => $this->speaker, // jane, omazh, zahar, ermil
64
                'emotion'   => 'good', // neutral (доброжелательный), neutral(нейтральный), evil (злой).
0 ignored issues
show
Unused Code Comprehensibility introduced by
40% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
65
                'lang'      => 'ru‑RU',
66
                'speed'     => 1.2,
67
                //'drunk' => 'true',
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
68
                //'robot' => 'true',
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
69
                //'ill'   => 'true',
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
70
                'key'       => $this->apiKey
71
            ];
72
            $content .= $this->reguestGet($query);
73
        }
74
        file_put_contents($outFile, $content);
75
        return true;
76
    }
77
78
    public function getUri()
79
    {
80
        //return 'http://tts.voicetech.yandex.net/tts';
81
        return 'https://tts.voicetech.yandex.net/generate';
82
    }
83
84
    /**
85
     * @return string
86
     */
87
    public function getSpeaker()
88
    {
89
        return $this->speaker;
90
    }
91
92
    public function setOksanaSpeaker()
93
    {
94
        $this->speaker = self::SPEAKER_OKSANA;
95
        $this->vote = self::VOTE_FEMALE;
96
    }
97
98
    public function setAlyssSpeaker()
99
    {
100
        $this->speaker = self::SPEAKER_ALYSS;
101
        $this->vote = self::VOTE_FEMALE;
102
    }
103
104
    public function setJaneSpeaker()
105
    {
106
        $this->speaker = self::SPEAKER_JANE;
107
        $this->vote = self::VOTE_FEMALE;
108
    }
109
110
    public function setOmazhSpeaker()
111
    {
112
        $this->speaker = self::SPEAKER_OMAZH;
113
        $this->vote = self::VOTE_FEMALE;
114
    }
115
116
    public function setZaharSpeaker()
117
    {
118
        $this->speaker = self::SPEAKER_ZAHAR;
119
        $this->vote = self::VOTE_MALE;
120
    }
121
122
    public function setErmilSpeaker()
123
    {
124
        $this->speaker = self::SPEAKER_ERMIL;
125
        $this->vote = self::VOTE_MALE;
126
    }
127
128
    /**
129
     * @param string $speaker
130
     */
131
    public function setSpeaker($speaker)
132
    {
133
        $this->speaker = $speaker;
134
        return $this;
135
    }
136
137
}
138