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 |
||
25 | class WebPage |
||
26 | { |
||
27 | /** The webpage title */ |
||
28 | public $title; |
||
29 | /** An array of tags to be added to the HTML head section */ |
||
30 | protected $headTags; |
||
31 | /** A string represnting the body of the page */ |
||
32 | public $body; |
||
33 | /** The browsecap object */ |
||
34 | private $browscap; |
||
35 | /** Data about the browser used to load the page */ |
||
36 | public $browser; |
||
37 | /** A string to add to the body open tag */ |
||
38 | public $body_tags; |
||
39 | /** Does the browser support import of CSS or HTML? */ |
||
40 | public $importSupport; |
||
41 | |||
42 | /** |
||
43 | * Create a new WebPage |
||
44 | * |
||
45 | * Create a new webpage abstraction object |
||
46 | * |
||
47 | * @param string $title The webpage title |
||
48 | */ |
||
49 | public function __construct($title) |
||
70 | |||
71 | /** |
||
72 | * Get the Browscap instance for the system |
||
73 | * |
||
74 | * @return Browscap The Browscap instance for the system |
||
75 | * |
||
76 | * @SuppressWarnings("Superglobals") |
||
77 | */ |
||
78 | protected function getBrowscap() |
||
93 | |||
94 | /** |
||
95 | * Use the Browsecap library to determine what browser is being used to load this page |
||
96 | */ |
||
97 | private function getBrowser() |
||
106 | |||
107 | /** |
||
108 | * Get the name of the browser used to load this page |
||
109 | */ |
||
110 | private function getBrowserName() |
||
118 | |||
119 | /** |
||
120 | * Get the first part of the browser version number |
||
121 | * |
||
122 | * Determine what version of the browser is being used to load the page. This |
||
123 | * is used to determine if the version of IE is too old to be used |
||
124 | */ |
||
125 | private function getBrowserMajorVer() |
||
133 | |||
134 | /** |
||
135 | * Print the HTML doctype header |
||
136 | */ |
||
137 | protected function printDoctype() |
||
142 | |||
143 | /** |
||
144 | * Print the opening HTML tag |
||
145 | */ |
||
146 | protected function printOpenHtml() |
||
150 | |||
151 | /** |
||
152 | * Print the closing HTML tag |
||
153 | */ |
||
154 | protected function printCloseHtml() |
||
158 | |||
159 | /** |
||
160 | * Print the page |
||
161 | * |
||
162 | * @deprecated 1.0.0 This funciton is deprectated and will be remoted. Please use printPage() instead |
||
163 | */ |
||
164 | public function print_page() |
||
168 | |||
169 | /** |
||
170 | * Print the webpage to standard out |
||
171 | */ |
||
172 | public function printPage() |
||
180 | |||
181 | /** |
||
182 | * Add a tag to the head element |
||
183 | * |
||
184 | * @param string $tag The tag to add to the page header |
||
185 | */ |
||
186 | public function addHeadTag($tag) |
||
190 | |||
191 | /** |
||
192 | * Create a tag to be added to the document |
||
193 | * |
||
194 | * @param string $tagName The tag's name (i.e. the string right after the open sign |
||
195 | * @param array $attribs Attributes to be added to the tag in the form key=value |
||
196 | * @param boolean $selfClose Does this tag end with a close (/>)? |
||
197 | * |
||
198 | * @return string The tag as a string |
||
199 | */ |
||
200 | protected function createOpenTag($tagName, $attribs = array(), $selfClose = false) |
||
218 | |||
219 | /** |
||
220 | * Create a close tag to be added to the document |
||
221 | * |
||
222 | * @param string $tagName The tag's name (i.e. the string right after the open sign |
||
223 | * |
||
224 | * @return string The close tag as a string |
||
225 | */ |
||
226 | protected function createCloseTag($tagName) |
||
230 | |||
231 | /** |
||
232 | * Create a link to be added to the document |
||
233 | * |
||
234 | * @param string $linkName The text inside the link |
||
235 | * @param string $linkTarget The location the link goes to |
||
236 | * |
||
237 | * @return string The link |
||
238 | */ |
||
239 | public function createLink($linkName, $linkTarget = '#', $class=false) |
||
250 | |||
251 | /** |
||
252 | * Add tags to the header to make the IE family of browsers behave better |
||
253 | * |
||
254 | * The IE family of browsers lower than version 9 do not support HTML 5 so we need |
||
255 | * to add a polyfill for those feaures. Additionally, IE versions greater than 8 |
||
256 | * have a compatibility mode. We need to tell them to act as the latest greatest version |
||
257 | * |
||
258 | * @param string $prefix The prefix to append to each line |
||
259 | */ |
||
260 | protected function printIeCompatability($prefix = '') |
||
272 | |||
273 | /** |
||
274 | * Print the HTML HEAD section |
||
275 | * |
||
276 | * @param string $prefix The prefix to append to each line |
||
277 | */ |
||
278 | protected function printHead($prefix = '') |
||
293 | |||
294 | /** |
||
295 | * Print the HTML BODY section |
||
296 | * |
||
297 | * @param string $prefix The prefix to append to each line |
||
298 | */ |
||
299 | protected function printBody($prefix = '') |
||
305 | |||
306 | /** |
||
307 | * Get the currently requested URL |
||
308 | * |
||
309 | * @return string The full URL of the requested page |
||
310 | * |
||
311 | * @SuppressWarnings("Superglobals") |
||
312 | */ |
||
313 | View Code Duplication | public function currentURL() |
|
326 | } |
||
327 | /* vim: set tabstop=4 shiftwidth=4 expandtab: */ |
||
328 |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.