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 |
||
| 10 | View Code Duplication | class Bootstrap5DismissibleTemplate extends BaseTemplate implements TemplateInterface |
|
| 11 | { |
||
| 12 | protected $prefix = ''; // every line prefix |
||
| 13 | protected $postfix = '<br>'; // every postfix |
||
| 14 | protected $wrapper = '<div class="alert alert-%s alert-dismissible fade show" role="alert"> |
||
| 15 | %s |
||
| 16 | <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> |
||
| 17 | </div>'; // wrapper over messages of same type |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @param $messages - message text |
||
| 21 | * @param $type - message type: success, info, warning, error |
||
| 22 | * |
||
| 23 | * @return string |
||
| 24 | */ |
||
| 25 | public function wrapMessages($messages, $type) |
||
| 31 | } |
||
| 32 | |||
| 60 |
If you suppress an error, we recommend checking for the error condition explicitly: