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 |
||
31 | class Benchmark extends Fwolflib { |
||
|
|||
32 | |||
33 | /** |
||
34 | * Define color group |
||
35 | * |
||
36 | * Seq: fast to slow |
||
37 | * |
||
38 | * @var array |
||
39 | */ |
||
40 | public $aColor = array( |
||
41 | "#00FF00", |
||
42 | "#CCFFCC", |
||
43 | "#77FF77", |
||
44 | "#FFCCCC", |
||
45 | "#FF7777", |
||
46 | "#FF0000" |
||
47 | ); |
||
48 | |||
49 | /** |
||
50 | * Group data |
||
51 | * |
||
52 | * array( |
||
53 | * iGroup => array( |
||
54 | * desc |
||
55 | * time_start |
||
56 | * time_stop |
||
57 | * ) |
||
58 | * ) |
||
59 | * @var array |
||
60 | */ |
||
61 | protected $aGroup = array(); |
||
62 | |||
63 | /** |
||
64 | * Marker data |
||
65 | * |
||
66 | * array( |
||
67 | * iGroup => array( |
||
68 | * iMark => array( |
||
69 | * desc |
||
70 | * time |
||
71 | * dur |
||
72 | * color |
||
73 | * pct |
||
74 | * ) |
||
75 | * ) |
||
76 | * ) |
||
77 | * @var array |
||
78 | */ |
||
79 | protected $aMark = array(); |
||
80 | |||
81 | /** |
||
82 | * Current mark group no. |
||
83 | * |
||
84 | * 1 group meas start->stop, another start will be group 2. |
||
85 | * @var int |
||
86 | */ |
||
87 | protected $iGroup = 0; |
||
88 | |||
89 | /** |
||
90 | * Seq of marker in group, start from 1 |
||
91 | * @var int |
||
92 | */ |
||
93 | protected $iMark = 1; |
||
94 | |||
95 | |||
96 | /** |
||
97 | * Constructor |
||
98 | * |
||
99 | * @param string $options Eg: autostart |
||
100 | */ |
||
101 | public function __construct($options = '') { |
||
107 | |||
108 | |||
109 | /** |
||
110 | * Display benchmark result |
||
111 | * |
||
112 | * @param string $options |
||
113 | */ |
||
114 | public function Display($options = '') { |
||
117 | |||
118 | |||
119 | /** |
||
120 | * Format cell bg color |
||
121 | * |
||
122 | * Split max/min marker dur by color number, and put each mark in it's color |
||
123 | * @param int $i_group |
||
124 | */ |
||
125 | protected function FormatColor($i_group) { |
||
167 | |||
168 | |||
169 | /** |
||
170 | * Format time to output |
||
171 | * |
||
172 | * @param float $time |
||
173 | * @return string |
||
174 | */ |
||
175 | View Code Duplication | protected function FormatTime($time) { |
|
192 | |||
193 | |||
194 | /** |
||
195 | * Get current time, mesured by microsecond |
||
196 | * |
||
197 | * @return float |
||
198 | */ |
||
199 | protected function GetTime() { |
||
203 | |||
204 | |||
205 | /** |
||
206 | * Set a marker |
||
207 | * |
||
208 | * @param string $desc Marker description |
||
209 | * @param string $color Specific color like '#FF0000' or 'red' |
||
210 | */ |
||
211 | public function Mark($desc = '', $color = '') { |
||
230 | |||
231 | |||
232 | /** |
||
233 | * Get html result |
||
234 | * |
||
235 | * @param string $options |
||
236 | * @return string |
||
237 | */ |
||
238 | public function Result($options = '') { |
||
343 | |||
344 | |||
345 | /** |
||
346 | * Start the timer |
||
347 | * |
||
348 | * @param string $desc Group description |
||
349 | */ |
||
350 | public function Start($desc = '') { |
||
362 | |||
363 | |||
364 | /** |
||
365 | * Stop the timer |
||
366 | */ |
||
367 | public function Stop() { |
||
378 | |||
379 | |||
380 | } // end of class Benchmark |
||
381 | ?> |
||
382 |
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.