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 |
||
| 36 | class TableCell extends AbstractElement |
||
| 37 | { |
||
| 38 | /** |
||
| 39 | * |
||
| 40 | * @var string |
||
| 41 | */ |
||
| 42 | private $content; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * |
||
| 46 | * @var ReferenceType |
||
| 47 | */ |
||
| 48 | private $reference; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * |
||
| 52 | * @var TableRow |
||
| 53 | */ |
||
| 54 | private $row; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * a string determining if the row is th or td |
||
| 58 | * |
||
| 59 | * @var string |
||
| 60 | */ |
||
| 61 | private $level; |
||
| 62 | |||
| 63 | const TH = 'th'; |
||
| 64 | const TD = 'td'; |
||
| 65 | |||
| 66 | |||
| 67 | function __construct($level, TableRow $row = null, $content = '') |
||
| 72 | |||
| 73 | /** |
||
| 74 | * |
||
| 75 | * @return string |
||
| 76 | */ |
||
| 77 | function getContent() |
||
| 81 | |||
| 82 | /** |
||
| 83 | * |
||
| 84 | * @param string $content |
||
| 85 | * @return $this |
||
| 86 | */ |
||
| 87 | function setContent($content) |
||
| 93 | |||
| 94 | /** |
||
| 95 | * |
||
| 96 | * @return TableRow |
||
| 97 | */ |
||
| 98 | function getRow(): TableRow |
||
| 102 | |||
| 103 | /** |
||
| 104 | * |
||
| 105 | * @param TableRow $row |
||
| 106 | * @return $this |
||
| 107 | */ |
||
| 108 | function setRow(TableRow $row) |
||
| 114 | |||
| 115 | /** |
||
| 116 | * |
||
| 117 | * @return ReferenceType |
||
| 118 | */ |
||
| 119 | function getReference() |
||
| 123 | |||
| 124 | /** |
||
| 125 | * |
||
| 126 | * @param ReferenceType $reference |
||
| 127 | * @return $this |
||
| 128 | */ |
||
| 129 | function setReference(ReferenceType $reference) |
||
| 135 | |||
| 136 | |||
| 137 | /** |
||
| 138 | * |
||
| 139 | * @return boolean |
||
| 140 | */ |
||
| 141 | public function isEmpty() |
||
| 145 | |||
| 146 | protected function getElementTag(): string |
||
| 150 | |||
| 151 | View Code Duplication | public function toDOMElement(\DOMDocument $doc): \DOMElement |
|
| 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.