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 |
||
3 | abstract class Ajde_Object_Magic extends Ajde_Object |
||
4 | { |
||
5 | protected $_data = []; |
||
6 | |||
7 | public final function __call($method, $arguments) |
||
35 | |||
36 | /** |
||
37 | * |
||
38 | * @param mixed $name |
||
39 | * @param mixed $value |
||
40 | * @return mixed |
||
41 | */ |
||
42 | public function set($key, $value) |
||
46 | |||
47 | protected function _set($key, $value) |
||
51 | |||
52 | public function remove($key) |
||
56 | |||
57 | public function get($key) |
||
66 | |||
67 | protected function _get($key) |
||
75 | |||
76 | public function has($key) |
||
86 | |||
87 | public function isEmpty($key) |
||
95 | |||
96 | public function hasEmpty($key) |
||
100 | |||
101 | public function hasNotEmpty($key) |
||
109 | |||
110 | public function reset() |
||
114 | |||
115 | public final function values() |
||
119 | |||
120 | public final function merge($key, array $value) |
||
128 | |||
129 | public final function valuesAsSingleDimensionArray() |
||
152 | |||
153 | /** |
||
154 | * Translates a camel case string into a string with underscores (e.g. firstName -> first_name) |
||
155 | * |
||
156 | * @see http://www.paulferrett.com/2009/php-camel-case-functions/ |
||
157 | * @param string $str String in camel case format |
||
158 | * @return string $str Translated into underscore format |
||
159 | */ |
||
160 | public static function fromCamelCase($str) |
||
167 | |||
168 | /** |
||
169 | * Translates a string with underscores into camel case (e.g. first_name -> firstName) |
||
170 | * |
||
171 | * @see http://www.paulferrett.com/2009/php-camel-case-functions/ |
||
172 | * @param string $str String in underscore format |
||
173 | * @param bool $capitalise_first_char If true, capitalise the first char in $str |
||
174 | * @return string $str translated into camel caps |
||
175 | */ |
||
176 | public static function toCamelCase($str, $capitalise_first_char = false) |
||
185 | |||
186 | public static function classnameToUppercase($classname) |
||
190 | } |
||
191 |
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.