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 TemplatedView extends BaseView { |
||
| 27 | |||
| 28 | use PluginHelper; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Validate an URI. |
||
| 32 | * |
||
| 33 | * @since %VERSION% |
||
| 34 | * |
||
| 35 | * @param string $uri URI to validate. |
||
| 36 | * |
||
| 37 | * @return string Validated URI. |
||
| 38 | * @throws InvalidURI If an invalid URI was passed into the View. |
||
| 39 | */ |
||
| 40 | View Code Duplication | protected function validate( $uri ) { |
|
| 55 | |||
| 56 | /** |
||
| 57 | * Get the possible locations for the view. |
||
| 58 | * |
||
| 59 | * @since %VERSION% |
||
| 60 | * |
||
| 61 | * @param string $uri URI of the view to get the locations for. |
||
| 62 | * |
||
| 63 | * @return array Array of possible locations. |
||
| 64 | */ |
||
| 65 | protected function get_locations( $uri ) { |
||
| 84 | } |
||
| 85 |
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.