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 |
||
| 9 | class WebPage |
||
| 10 | { |
||
| 11 | /** The webpage title */ |
||
| 12 | public $title; |
||
| 13 | /** An array of tags to be added to the HTML head section */ |
||
| 14 | protected $headTags; |
||
| 15 | /** A string represnting the body of the page */ |
||
| 16 | public $body; |
||
| 17 | /** A string to add to the body open tag */ |
||
| 18 | public $body_tags; |
||
| 19 | |||
| 20 | protected $request = null; |
||
| 21 | |||
| 22 | public function __construct($title = '') |
||
| 27 | |||
| 28 | public function handleRequest($request, $response, $args) |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Add a tag to the head element |
||
| 37 | * |
||
| 38 | * @param string $tag The tag to add to the page header |
||
| 39 | */ |
||
| 40 | public function addHeadTag($tag) |
||
| 44 | /** |
||
| 45 | * Create a tag to be added to the document |
||
| 46 | * |
||
| 47 | * @param string $tagName The tag's name (i.e. the string right after the open sign |
||
| 48 | * @param array $attribs Attributes to be added to the tag in the form key=value |
||
| 49 | * @param boolean $selfClose Does this tag end with a close (/>)? |
||
| 50 | * |
||
| 51 | * @return string The tag as a string |
||
| 52 | */ |
||
| 53 | View Code Duplication | protected function createOpenTag($tagName, $attribs = array(), $selfClose = false) |
|
| 71 | |||
| 72 | /** |
||
| 73 | * Create a close tag to be added to the document |
||
| 74 | * |
||
| 75 | * @param string $tagName The tag's name (i.e. the string right after the open sign |
||
| 76 | * |
||
| 77 | * @return string The close tag as a string |
||
| 78 | */ |
||
| 79 | protected function createCloseTag($tagName) |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Create a link to be added to the document |
||
| 86 | * |
||
| 87 | * @param string $linkName The text inside the link |
||
| 88 | * @param string $linkTarget The location the link goes to |
||
| 89 | * |
||
| 90 | * @return string The link |
||
| 91 | */ |
||
| 92 | public function createLink($linkName, $linkTarget = '#') |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Print the HTML doctype header |
||
| 101 | */ |
||
| 102 | protected function printDoctype($response) |
||
| 106 | |||
| 107 | /** |
||
| 108 | * Print the opening HTML tag |
||
| 109 | */ |
||
| 110 | protected function printOpenHtml($response) |
||
| 114 | /** |
||
| 115 | * Print the closing HTML tag |
||
| 116 | */ |
||
| 117 | protected function printCloseHtml($response) |
||
| 121 | |||
| 122 | /** |
||
| 123 | * Print the HTML HEAD section |
||
| 124 | */ |
||
| 125 | protected function printHead($response) |
||
| 136 | |||
| 137 | /** |
||
| 138 | * Print the HTML BODY section |
||
| 139 | */ |
||
| 140 | protected function printBody($response) |
||
| 144 | |||
| 145 | protected function printPage($response) |
||
| 154 | |||
| 155 | public function getCurrentUrl() |
||
| 163 | } |
||
| 164 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.