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 |
||
| 20 | class Path extends DataObject implements PathInterface |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * Overwrite data in the object. |
||
| 24 | * |
||
| 25 | * The $key parameter can be string or array. |
||
| 26 | * If $key is string, the attribute value will be overwritten by $value |
||
| 27 | * |
||
| 28 | * If $key is an array, it will overwrite all the data in the object. |
||
| 29 | * |
||
| 30 | * @param string|array $key |
||
| 31 | * @param mixed $value |
||
| 32 | * |
||
| 33 | * @return $this |
||
| 34 | */ |
||
| 35 | View Code Duplication | public function setData($key, $value = null) |
|
| 45 | |||
| 46 | /** |
||
| 47 | * {@inheritdoc} |
||
| 48 | */ |
||
| 49 | public function getPath($key = null) |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Returns default paths for config item |
||
| 66 | * |
||
| 67 | * @return array |
||
| 68 | */ |
||
| 69 | public function initDefaultPaths() |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Returns the user's home directory |
||
| 80 | * |
||
| 81 | * @return null|string |
||
| 82 | * @SuppressWarnings(PHPMD.Superglobals) |
||
| 83 | */ |
||
| 84 | private function getHomePath() |
||
| 102 | } |
||
| 103 |