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 |
||
| 27 | abstract class ConfigurationAbstract extends XoopsArray |
||
| 28 | { |
||
| 29 | /** |
||
| 30 | * Get a copy of all attributes |
||
| 31 | * |
||
| 32 | * @return array An array of attributes |
||
| 33 | */ |
||
| 34 | 1 | public function getAll() |
|
| 38 | |||
| 39 | /** |
||
| 40 | * Get a list of all attribute names |
||
| 41 | * |
||
| 42 | * @return array An array of attribute names/keys |
||
| 43 | */ |
||
| 44 | 1 | public function getNames() |
|
| 48 | |||
| 49 | /** |
||
| 50 | * Replace all attribute with new set |
||
| 51 | * |
||
| 52 | * @param mixed $values array (or object) of new attributes |
||
| 53 | * |
||
| 54 | * @return array old values |
||
| 55 | */ |
||
| 56 | 1 | public function setAll($values) |
|
| 61 | |||
| 62 | /** |
||
| 63 | * Set multiple attributes by using an associative array |
||
| 64 | * |
||
| 65 | * @param array $values array of new attributes |
||
| 66 | * |
||
| 67 | * @return void |
||
| 68 | */ |
||
| 69 | 1 | public function setMerge($values) |
|
| 74 | |||
| 75 | /** |
||
| 76 | * Set an element attribute array |
||
| 77 | * |
||
| 78 | * This allows an attribute which is an array to be built one |
||
| 79 | * element at a time. |
||
| 80 | * |
||
| 81 | * @param string $stem An attribute array name. |
||
| 82 | * @param string $name An attribute array item name. If empty, the |
||
| 83 | * value will be appended to the end of the |
||
| 84 | * array rather than added with the key $name. |
||
| 85 | * @param mixed $value An attribute array item value. |
||
| 86 | * |
||
| 87 | * @return void |
||
| 88 | */ |
||
| 89 | 1 | public function setArrayItem($stem, $name, $value) |
|
| 105 | |||
| 106 | /** |
||
| 107 | * Retrieve a set of attributes based on a partial name |
||
| 108 | * |
||
| 109 | * @param string|null $nameLike restrict output to only attributes with a name starting with |
||
| 110 | * this string. |
||
| 111 | * |
||
| 112 | * @return array an array of all attributes with names matching $nameLike |
||
| 113 | */ |
||
| 114 | 1 | View Code Duplication | public function getAllLike($nameLike = null) |
| 128 | } |
||
| 129 |