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 |
||
22 | class DatetimeToJson implements ModelObjectToJsonConverterInterface |
||
23 | { |
||
24 | |||
25 | /** |
||
26 | * @param EE_Datetime[] $datetimes |
||
27 | * @return array |
||
28 | * @throws EE_Error |
||
29 | * @throws InvalidArgumentException |
||
30 | * @throws InvalidDataTypeException |
||
31 | * @throws InvalidInterfaceException |
||
32 | * @throws ReflectionException |
||
33 | * @since $VID:$ |
||
34 | */ |
||
35 | View Code Duplication | public function convertAndEncodeArrayOf(array $datetimes) |
|
45 | |||
46 | |||
47 | /** |
||
48 | * @param EE_Datetime $datetime |
||
49 | * @return false|string |
||
50 | * @throws EE_Error |
||
51 | * @throws InvalidArgumentException |
||
52 | * @throws InvalidDataTypeException |
||
53 | * @throws InvalidInterfaceException |
||
54 | * @throws ReflectionException |
||
55 | * @since $VID:$ |
||
56 | */ |
||
57 | public function convertAndEncode($datetime) |
||
61 | |||
62 | |||
63 | /** |
||
64 | * @param EE_Datetime[] $datetimes |
||
65 | * @return array |
||
66 | * @throws EE_Error |
||
67 | * @throws InvalidArgumentException |
||
68 | * @throws InvalidDataTypeException |
||
69 | * @throws InvalidInterfaceException |
||
70 | * @throws ReflectionException |
||
71 | * @since $VID:$ |
||
72 | */ |
||
73 | public function convertArrayOf(array $datetimes) |
||
83 | |||
84 | |||
85 | /** |
||
86 | * @param EE_Datetime $datetime |
||
87 | * @return array |
||
88 | * @throws EE_Error |
||
89 | * @throws InvalidDataTypeException |
||
90 | * @throws InvalidInterfaceException |
||
91 | * @throws InvalidArgumentException |
||
92 | * @throws ReflectionException |
||
93 | * @since $VID:$ |
||
94 | */ |
||
95 | public function convert($datetime) |
||
113 | |||
114 | |||
115 | /** |
||
116 | * @param EE_Datetime[] $datetimes |
||
117 | * @return array |
||
118 | * @throws EE_Error |
||
119 | * @throws InvalidArgumentException |
||
120 | * @throws InvalidDataTypeException |
||
121 | * @throws InvalidInterfaceException |
||
122 | * @throws ReflectionException |
||
123 | * @since $VID:$ |
||
124 | */ |
||
125 | View Code Duplication | public function encodeArrayOf(array $datetimes) |
|
135 | |||
136 | |||
137 | /** |
||
138 | * @param array $datetime_array |
||
139 | * @return false|string |
||
140 | * @since $VID:$ |
||
141 | */ |
||
142 | public function encode(array $datetime_array) |
||
146 | } |