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:
Complex classes like DocReStructuredText often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use DocReStructuredText, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
32 | class DocReStructuredText extends Fwolflib { |
||
|
|||
33 | |||
34 | /** |
||
35 | * Cmd options when used rst2xxx.py |
||
36 | * |
||
37 | * Param is combined in, eg: tab-width=4 |
||
38 | * @var array |
||
39 | */ |
||
40 | public $aCmdOption = array( |
||
41 | 'embed-stylesheet', |
||
42 | //'link-stylesheet', |
||
43 | |||
44 | // h1 is for title |
||
45 | 'initial-header-level=2', |
||
46 | |||
47 | //'no-doc-title', |
||
48 | //'no-xml-declaration', |
||
49 | |||
50 | // Params why not support ? |
||
51 | //'indents', |
||
52 | //'newlines', |
||
53 | ); |
||
54 | |||
55 | /** |
||
56 | * Result html |
||
57 | * @var string |
||
58 | */ |
||
59 | public $sHtml = ''; |
||
60 | |||
61 | /** |
||
62 | * Actural path of docutils execute file. |
||
63 | * @var string |
||
64 | * @see SetPathDocutils() |
||
65 | */ |
||
66 | protected $sPathDocutils = ''; |
||
67 | |||
68 | |||
69 | /** |
||
70 | * construct |
||
71 | * |
||
72 | * @var param string $path_docutils Path of docutils exec file |
||
73 | */ |
||
74 | public function __construct ($path_docutils = '') { |
||
87 | |||
88 | |||
89 | /** |
||
90 | * Add my html footer |
||
91 | * |
||
92 | * Some code is cp from fwolfweb |
||
93 | * |
||
94 | * @param string $s_html |
||
95 | * @return string |
||
96 | */ |
||
97 | public function AddFooter ($s_html) { |
||
163 | |||
164 | |||
165 | /** |
||
166 | * Add jquery lib link in <head> |
||
167 | * |
||
168 | * @param string $s_html |
||
169 | * @return string |
||
170 | */ |
||
171 | protected function AddJsJquery ($s_html) { |
||
181 | |||
182 | |||
183 | /** |
||
184 | * Add js code, which can show source of prefered part. |
||
185 | * |
||
186 | * Need: $this->aCfg['js_jquery'] = true; |
||
187 | * |
||
188 | * @return string |
||
189 | */ |
||
190 | public function AddJsShowSource () { |
||
220 | |||
221 | |||
222 | /** |
||
223 | * Put log bottom at document |
||
224 | * |
||
225 | * @param $level Only output log which's level >= $level |
||
226 | * @return string |
||
227 | */ |
||
228 | public function AddLog ($level = 3) { |
||
237 | |||
238 | |||
239 | /** |
||
240 | * Add some code to footer |
||
241 | * |
||
242 | * @param string $s_html |
||
243 | * @param string $s_add |
||
244 | * @return stirng |
||
245 | */ |
||
246 | View Code Duplication | public function AddToFooter ($s_html, $s_add) { |
|
255 | |||
256 | |||
257 | /** |
||
258 | * Add some code before footer div |
||
259 | * |
||
260 | * @param string $s_html |
||
261 | * @param string $s_add |
||
262 | * @return stirng |
||
263 | */ |
||
264 | View Code Duplication | public function AddToFooterBefore ($s_html, $s_add) { |
|
273 | |||
274 | |||
275 | /** |
||
276 | * Gen cmd options |
||
277 | * |
||
278 | * @return string |
||
279 | */ |
||
280 | View Code Duplication | protected function GenCmdOption () { |
|
299 | |||
300 | |||
301 | /** |
||
302 | * Gen magic comment including mode, coding |
||
303 | * |
||
304 | * @return string |
||
305 | */ |
||
306 | public function GenRstMagicComment () { |
||
310 | |||
311 | |||
312 | /** |
||
313 | * Gen simple table by rst syntax |
||
314 | * |
||
315 | * Param $ar_thead[] format: |
||
316 | * array( |
||
317 | * idx, index of data in $ar_data |
||
318 | * title, text display in <th>, can be empty. |
||
319 | * width, possible max length of text display in <td> |
||
320 | * ) |
||
321 | * All text in th/td will be cut short if length > width. |
||
322 | * Columns' width will become td's width by their proportion, |
||
323 | * so it should make narrow col a bit wider. |
||
324 | * |
||
325 | * $ar_data is 2-dim array, index of 1st dim is ignored, |
||
326 | * index of 2st dim will be called by $ar_thead[][idx]. |
||
327 | * |
||
328 | * @param array $ar_thead |
||
329 | * @param array $ar_data |
||
330 | * @return string |
||
331 | */ |
||
332 | public function GenRstTable ($ar_thead, $ar_data) { |
||
372 | |||
373 | |||
374 | /** |
||
375 | * Gen title by rst syntax |
||
376 | * |
||
377 | * @param string $s_title |
||
378 | * @return string |
||
379 | */ |
||
380 | public function GenRstTitle ($s_title) { |
||
385 | |||
386 | |||
387 | /** |
||
388 | * Get default path of docutils writer html4css1 |
||
389 | * |
||
390 | * @return string |
||
391 | */ |
||
392 | public function GetDocutilsCssPath () { |
||
411 | |||
412 | |||
413 | /** |
||
414 | * Detect and set path of docutils |
||
415 | * |
||
416 | * @param $s_path Manual additional path |
||
417 | * @return string |
||
418 | */ |
||
419 | public function GetPathDocutils ($s_path) { |
||
460 | |||
461 | |||
462 | /** |
||
463 | * Got path of rst2html.py cmd |
||
464 | * |
||
465 | * @return string |
||
466 | */ |
||
467 | public function GetPathRst2Html () { |
||
474 | |||
475 | |||
476 | /** |
||
477 | * Init config vars, give default value. |
||
478 | * |
||
479 | * @return this |
||
480 | */ |
||
481 | public function Init () { |
||
507 | |||
508 | |||
509 | /** |
||
510 | * Modify html doctype declare |
||
511 | * |
||
512 | * @param string $s_html |
||
513 | * @return string |
||
514 | */ |
||
515 | protected function ModifyHtmlDoctype ($s_html) { |
||
521 | |||
522 | |||
523 | /** |
||
524 | * Modify html <style> tag, to met validator.w3.org |
||
525 | * |
||
526 | * @param string $s_html |
||
527 | * @return string |
||
528 | */ |
||
529 | protected function ModifyHtmlTagStyle ($s_html) { |
||
537 | |||
538 | |||
539 | /** |
||
540 | * Tidy output html |
||
541 | * |
||
542 | * @param &$s_html |
||
543 | * @return string |
||
544 | */ |
||
545 | protected function Tidy (&$s_html) { |
||
548 | |||
549 | |||
550 | /** |
||
551 | * Convert reStructuredText content to html format |
||
552 | * |
||
553 | * Note: I had run benchmark to compare pipe and tmpfile, |
||
554 | * result is, they are almost same. |
||
555 | * |
||
556 | * @param string $s_rst |
||
557 | * @return string |
||
558 | */ |
||
559 | public function ToHtml ($s_rst) { |
||
608 | |||
609 | |||
610 | /** |
||
611 | * Convert reStructuredText content to html, and adjust |
||
612 | * |
||
613 | * @param string $s_rst |
||
614 | * @return string |
||
615 | */ |
||
616 | public function ToHtmlFull ($s_rst) { |
||
637 | |||
638 | |||
639 | /** |
||
640 | * Convert reStructuredText to html, only html body part. |
||
641 | * |
||
642 | * Without <body> tag. |
||
643 | * |
||
644 | * @param string $s_rst |
||
645 | * @return string |
||
646 | */ |
||
647 | public function ToHtmlSimple ($s_rst) { |
||
663 | |||
664 | |||
665 | } // end of class DocReStructuredText |
||
666 | ?> |
||
667 |
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.