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 |
||
| 21 | class FormatterHelper extends Helper |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * Formats a message within a section. |
||
| 25 | * |
||
| 26 | * @param string $section The section name |
||
| 27 | * @param string $message The message |
||
| 28 | * @param string $style The style to apply to the section |
||
| 29 | * |
||
| 30 | * @return string The format section |
||
| 31 | */ |
||
| 32 | public function formatSection($section, $message, $style = 'info') |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Formats a message as a block of text. |
||
| 39 | * |
||
| 40 | * @param string|array $messages The message to write in the block |
||
| 41 | * @param string $style The style to apply to the whole block |
||
| 42 | * @param bool $large Whether to return a large block |
||
| 43 | * |
||
| 44 | * @return string The formatter message |
||
| 45 | */ |
||
| 46 | public function formatBlock($messages, $style, $large = false) |
||
| 74 | |||
| 75 | /** |
||
| 76 | * {@inheritdoc} |
||
| 77 | */ |
||
| 78 | public function getName() |
||
| 82 | } |
||
| 83 |