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 |
||
27 | class Prompt |
||
28 | { |
||
29 | /** |
||
30 | * @var QuestionHelper |
||
31 | */ |
||
32 | protected $prompt; |
||
33 | |||
34 | /** |
||
35 | * Prompt constructor. |
||
36 | */ |
||
37 | public function __construct() |
||
41 | |||
42 | /** |
||
43 | * Asks a question to the user. |
||
44 | * |
||
45 | * @param InputInterface $input An InputInterface instance |
||
46 | * @param OutputInterface $output An OutputInterface instance |
||
47 | * @param Question $question The question to ask |
||
48 | * |
||
49 | * @return mixed The user answer |
||
50 | * |
||
51 | * @throws RuntimeException If there is no data to read in the input stream |
||
52 | */ |
||
53 | public function ask(InputInterface $input, OutputInterface $output, Question $question) |
||
57 | |||
58 | /** |
||
59 | * Get JIRA URL question |
||
60 | * |
||
61 | * @return Question |
||
62 | */ |
||
63 | View Code Duplication | public function getJiraUrlQuestion() |
|
76 | |||
77 | /** |
||
78 | * Get JIRA username question |
||
79 | * |
||
80 | * @return Question |
||
81 | */ |
||
82 | View Code Duplication | public function getJiraUsernameQuestion() |
|
95 | |||
96 | /** |
||
97 | * Get JIRA password question |
||
98 | * |
||
99 | * @return Question |
||
100 | */ |
||
101 | public function getJiraPasswordQuestion() |
||
116 | |||
117 | /** |
||
118 | * Choose server timezone question |
||
119 | * |
||
120 | * @return ChoiceQuestion |
||
121 | */ |
||
122 | public function chooseTimezoneQuestion() |
||
134 | |||
135 | /** |
||
136 | * Select cache mode question |
||
137 | * |
||
138 | * @return ConfirmationQuestion |
||
139 | */ |
||
140 | public function chooseCacheModeQuestion() |
||
146 | } |
||
147 |