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 |
||
7 | class Hacks extends ViewableData |
||
8 | { |
||
9 | /** |
||
10 | * Add a new wrapper method. |
||
11 | * |
||
12 | * Similar to addWrapperMethod() but made public and working on |
||
13 | * custom instances to allow to inject custom wrappers. |
||
14 | * |
||
15 | * @param ViewableData $instance |
||
16 | * @param string $method |
||
17 | * @param string $wrap |
||
18 | */ |
||
19 | View Code Duplication | public static function addWrapperMethodToInstance($instance, $method, $wrap) |
|
28 | |||
29 | /** |
||
30 | * Add callback as a method. |
||
31 | * |
||
32 | * Similar to addCallbackMethod() but made public and working on |
||
33 | * custom instances to allow to inject custom callbacks. |
||
34 | * |
||
35 | * @param ViewableData $instance |
||
36 | * @param string $method |
||
37 | * @param \Closure $callback |
||
38 | */ |
||
39 | 5 | View Code Duplication | public static function addCallbackMethodToInstance($instance, $method, $callback) |
47 | } |
||
48 |
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.