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 |
||
28 | trait DelegatorWritableTrait |
||
29 | { |
||
30 | use WritableTrait; |
||
31 | |||
32 | /** |
||
33 | * Override `isWritable()` in the WritableTrait |
||
34 | * |
||
35 | * {@inheritDoc} |
||
36 | */ |
||
37 | View Code Duplication | public function isWritable()/*# : bool */ |
|
49 | |||
50 | /** |
||
51 | * Override `setWritable()` in the WritableTrait |
||
52 | * |
||
53 | * {@inheritDoc} |
||
54 | */ |
||
55 | public function setWritable($writable) |
||
69 | |||
70 | /** |
||
71 | * Set underlying registries's writability |
||
72 | * |
||
73 | * @param bool $writable |
||
74 | * @return $this |
||
75 | * @access protected |
||
76 | */ |
||
77 | protected function setRegistryWritable(/*# bool */ $writable) |
||
85 | |||
86 | /** |
||
87 | * Set writable to FALSE in all registries |
||
88 | * |
||
89 | * @return $this |
||
90 | * @access protected |
||
91 | */ |
||
92 | protected function setRegistryWritableFalse() |
||
101 | |||
102 | /** |
||
103 | * Set writable to TRUE at first matching registry |
||
104 | * |
||
105 | * @return $this |
||
106 | * @access protected |
||
107 | */ |
||
108 | View Code Duplication | protected function setRegistryWritableTrue() |
|
118 | } |
||
119 |
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.