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 |
||
| 32 | trait DelegatorWritableTrait |
||
| 33 | { |
||
| 34 | use WritableTrait, DelegatorTrait; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Override `isWritable()` in the WritableTrait. |
||
| 38 | * |
||
| 39 | * Delegator's writability is base on its registries |
||
| 40 | * |
||
| 41 | * {@inheritDoc} |
||
| 42 | */ |
||
| 43 | public function isWritable()/*# : bool */ |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Override `setWritable()` in the WritableTrait |
||
| 57 | * |
||
| 58 | * {@inheritDoc} |
||
| 59 | */ |
||
| 60 | public function setWritable($writable)/*# : bool */ |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Set writable to FALSE in all registries |
||
| 75 | * |
||
| 76 | * @return bool |
||
| 77 | * @access protected |
||
| 78 | */ |
||
| 79 | View Code Duplication | protected function setRegistryWritableFalse()/*# : bool */ |
|
| 89 | |||
| 90 | /** |
||
| 91 | * Set writable to TRUE at first matching registry |
||
| 92 | * |
||
| 93 | * @return bool |
||
| 94 | * @access protected |
||
| 95 | */ |
||
| 96 | View Code Duplication | protected function setRegistryWritableTrue()/*# : bool */ |
|
| 106 | } |
||
| 107 |