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 |
||
26 | class IOOutput implements OutputInterface |
||
27 | { |
||
28 | /** |
||
29 | * @var IO |
||
30 | */ |
||
31 | private $io; |
||
32 | |||
33 | /** |
||
34 | * @var bool |
||
35 | */ |
||
36 | private $decorated; |
||
37 | |||
38 | /** |
||
39 | * Creates a new composite output. |
||
40 | * |
||
41 | * @param IO $io The I/O. |
||
42 | */ |
||
43 | 32 | public function __construct(IO $io) |
|
48 | |||
49 | /** |
||
50 | * Returns the standard output. |
||
51 | * |
||
52 | * @return IO The standard output. |
||
53 | */ |
||
54 | public function getIO() |
||
58 | |||
59 | /** |
||
60 | * {@inheritdoc} |
||
61 | */ |
||
62 | 18 | public function write($messages, $newline = false, $type = self::OUTPUT_NORMAL) |
|
72 | |||
73 | /** |
||
74 | * {@inheritdoc} |
||
75 | */ |
||
76 | 2 | public function writeln($messages, $type = self::OUTPUT_NORMAL) |
|
82 | |||
83 | /** |
||
84 | * {@inheritdoc} |
||
85 | */ |
||
86 | 5 | public function setVerbosity($level) |
|
110 | |||
111 | /** |
||
112 | * {@inheritdoc} |
||
113 | */ |
||
114 | 5 | public function getVerbosity() |
|
134 | |||
135 | /** |
||
136 | * {@inheritdoc} |
||
137 | */ |
||
138 | 5 | public function isQuiet() |
|
142 | |||
143 | /** |
||
144 | * {@inheritdoc} |
||
145 | */ |
||
146 | 2 | public function isVerbose() |
|
150 | |||
151 | /** |
||
152 | * {@inheritdoc} |
||
153 | */ |
||
154 | 3 | public function isVeryVerbose() |
|
158 | |||
159 | /** |
||
160 | * {@inheritdoc} |
||
161 | */ |
||
162 | 4 | public function isDebug() |
|
166 | |||
167 | /** |
||
168 | * {@inheritdoc} |
||
169 | */ |
||
170 | 1 | public function setDecorated($decorated) |
|
174 | |||
175 | /** |
||
176 | * {@inheritdoc} |
||
177 | */ |
||
178 | 1 | public function isDecorated() |
|
182 | |||
183 | /** |
||
184 | * {@inheritdoc} |
||
185 | */ |
||
186 | public function setFormatter(OutputFormatterInterface $formatter) |
||
189 | |||
190 | /** |
||
191 | * {@inheritdoc} |
||
192 | */ |
||
193 | 1 | public function getFormatter() |
|
197 | |||
198 | 4 | View Code Duplication | private function doWriteLine($message, $type) |
212 | |||
213 | 16 | View Code Duplication | private function doWrite($message, $type) |
227 | } |
||
228 |
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.