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 |
||
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 = []) |
||
50 | |||
51 | protected function synthesize($text, $outFile) |
||
77 | |||
78 | public function getUri() |
||
83 | |||
84 | /** |
||
85 | * @return string |
||
86 | */ |
||
87 | public function getSpeaker() |
||
91 | |||
92 | public function setOksanaSpeaker() |
||
97 | |||
98 | public function setAlyssSpeaker() |
||
103 | |||
104 | public function setJaneSpeaker() |
||
109 | |||
110 | public function setOmazhSpeaker() |
||
115 | |||
116 | public function setZaharSpeaker() |
||
121 | |||
122 | public function setErmilSpeaker() |
||
127 | |||
128 | /** |
||
129 | * @param string $speaker |
||
130 | */ |
||
131 | public function setSpeaker($speaker) |
||
136 | |||
137 | } |
||
138 |
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.