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 |
||
| 2 | class Template extends Html { |
||
| 3 | public function __construct( $_parameters ) { |
||
| 4 | parent::__construct( $_parameters ); |
||
| 5 | $this->makeConnection(); |
||
| 6 | $this->tags["brand"] = "JATE"; |
||
| 7 | $this->tags["brandImg"] = ""; |
||
| 8 | $this->tags["title"] = "JATE - 01essential"; |
||
| 9 | $this->data["template"] = "bundles/views/tradictional.html"; |
||
| 10 | $this->addFilesRequired([ |
||
| 11 | "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" |
||
| 12 | , "https://code.jquery.com/jquery-1.11.3.min.js" |
||
| 13 | , "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" |
||
| 14 | ]); |
||
| 15 | $this->tags["metaDescription"] = "Beautiful description ."; |
||
| 16 | $this->tags["metaKeywords"] = "JATE,PHP,JS,CSS"; |
||
| 17 | $this->tags["metaAuthor"] = "XaBerr"; |
||
| 18 | $this->tags["menu"] = $this->makeMenu(); |
||
| 19 | } |
||
| 20 | public function makeConnection() { |
||
| 21 | $jConfig = $this->parameters["app"]; |
||
| 22 | $connection = null; |
||
| 23 | if( $jConfig != null && $jConfig->connection["enable"]) |
||
| 24 | $connection = new Connection( |
||
| 25 | $jConfig->connection["server"] |
||
| 26 | , $jConfig->connection["database"] |
||
| 27 | , $jConfig->connection["user"] |
||
| 28 | , $jConfig->connection["password"] |
||
| 29 | ); |
||
| 30 | $this->addConnection("base",$connection); |
||
| 31 | } |
||
| 32 | public function makeMenu() { |
||
| 33 | jBlock(); |
||
| 34 | ?> |
||
| 35 | <li> |
||
| 36 | <a href="Home">Home</a> |
||
| 37 | </li> |
||
| 38 | <li> |
||
| 39 | <a href="Page1">Page 1</a> |
||
| 40 | </li> |
||
| 41 | <?php |
||
| 42 | $temp = jBlockEnd(); |
||
| 43 | return $temp; |
||
| 44 | } |
||
| 45 | } |
||
| 46 | ?> |
||
| 47 |