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 |
||
17 | class JsonMapper |
||
18 | { |
||
19 | /** |
||
20 | * Maps data into object class |
||
21 | * |
||
22 | * @param object $json to be casted |
||
23 | * @param object $object Class to receive data |
||
24 | * @throws InvalidArgumentException |
||
25 | * @return object |
||
26 | */ |
||
27 | public function map($json, $object) |
||
53 | |||
54 | /** |
||
55 | * Removes - and _ and makes the next letter uppercase |
||
56 | * |
||
57 | * @param string $name Property name |
||
58 | * |
||
59 | * @return string CamelCasedVariableName |
||
60 | */ |
||
61 | protected function getCamelCaseName($name) |
||
67 | |||
68 | /** |
||
69 | * Since hyphens cannot be used in variables we have to uppercase them. |
||
70 | * |
||
71 | * @param string $name Property name |
||
72 | * |
||
73 | * @return string Name without hyphen |
||
74 | */ |
||
75 | protected function getSafeName($name) |
||
83 | } |
||
84 | ?> |
||
|
Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.
A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.