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 |
||
30 | class Border extends Supervisor implements IComparable |
||
31 | { |
||
32 | /* Border style */ |
||
33 | const BORDER_NONE = 'none'; |
||
34 | const BORDER_DASHDOT = 'dashDot'; |
||
35 | const BORDER_DASHDOTDOT = 'dashDotDot'; |
||
36 | const BORDER_DASHED = 'dashed'; |
||
37 | const BORDER_DOTTED = 'dotted'; |
||
38 | const BORDER_DOUBLE = 'double'; |
||
39 | const BORDER_HAIR = 'hair'; |
||
40 | const BORDER_MEDIUM = 'medium'; |
||
41 | const BORDER_MEDIUMDASHDOT = 'mediumDashDot'; |
||
42 | const BORDER_MEDIUMDASHDOTDOT = 'mediumDashDotDot'; |
||
43 | const BORDER_MEDIUMDASHED = 'mediumDashed'; |
||
44 | const BORDER_SLANTDASHDOT = 'slantDashDot'; |
||
45 | const BORDER_THICK = 'thick'; |
||
46 | const BORDER_THIN = 'thin'; |
||
47 | |||
48 | /** |
||
49 | * Border style. |
||
50 | * |
||
51 | * @var string |
||
52 | */ |
||
53 | protected $borderStyle = self::BORDER_NONE; |
||
54 | |||
55 | /** |
||
56 | * Border color. |
||
57 | * |
||
58 | * @var Color |
||
59 | */ |
||
60 | protected $color; |
||
61 | |||
62 | /** |
||
63 | * Parent property name. |
||
64 | * |
||
65 | * @var string |
||
66 | */ |
||
67 | protected $parentPropertyName; |
||
68 | |||
69 | /** |
||
70 | * Create a new Border. |
||
71 | * |
||
72 | * @param bool $isSupervisor Flag indicating if this is a supervisor or not |
||
73 | * Leave this value at default unless you understand exactly what |
||
74 | * its ramifications are |
||
75 | * @param bool $isConditional Flag indicating if this is a conditional style or not |
||
76 | * Leave this value at default unless you understand exactly what |
||
77 | * its ramifications are |
||
78 | */ |
||
79 | 80 | public function __construct($isSupervisor = false, $isConditional = false) |
|
92 | |||
93 | /** |
||
94 | * Bind parent. Only used for supervisor. |
||
95 | * |
||
96 | * @param Borders $parent |
||
97 | * @param string $parentPropertyName |
||
98 | * |
||
99 | * @return Border |
||
100 | */ |
||
101 | 80 | public function bindParent($parent, $parentPropertyName = null) |
|
108 | |||
109 | /** |
||
110 | * Get the shared style component for the currently active cell in currently active sheet. |
||
111 | * Only used for style supervisor. |
||
112 | * |
||
113 | * @throws PhpSpreadsheetException |
||
114 | * |
||
115 | * @return Border |
||
116 | */ |
||
117 | 1 | public function getSharedComponent() |
|
139 | |||
140 | /** |
||
141 | * Build style array from subcomponents. |
||
142 | * |
||
143 | * @param array $array |
||
144 | * |
||
145 | * @return array |
||
146 | */ |
||
147 | 1 | public function getStyleArray($array) |
|
151 | |||
152 | /** |
||
153 | * Apply styles from array. |
||
154 | * |
||
155 | * <code> |
||
156 | * $spreadsheet->getActiveSheet()->getStyle('B2')->getBorders()->getTop()->applyFromArray( |
||
157 | * array( |
||
158 | * 'borderStyle' => Border::BORDER_DASHDOT, |
||
159 | * 'color' => array( |
||
160 | * 'rgb' => '808080' |
||
161 | * ) |
||
162 | * ) |
||
163 | * ); |
||
164 | * </code> |
||
165 | * |
||
166 | * @param array $pStyles Array containing style information |
||
167 | * |
||
168 | * @throws PhpSpreadsheetException |
||
169 | * |
||
170 | * @return Border |
||
171 | */ |
||
172 | 18 | public function applyFromArray(array $pStyles) |
|
187 | |||
188 | /** |
||
189 | * Get Border style. |
||
190 | * |
||
191 | * @return string |
||
192 | */ |
||
193 | 63 | public function getBorderStyle() |
|
201 | |||
202 | /** |
||
203 | * Set Border style. |
||
204 | * |
||
205 | * @param string|bool $pValue |
||
206 | * When passing a boolean, FALSE equates Border::BORDER_NONE |
||
207 | * and TRUE to Border::BORDER_MEDIUM |
||
208 | * |
||
209 | * @return Border |
||
210 | */ |
||
211 | 21 | View Code Duplication | public function setBorderStyle($pValue) |
227 | |||
228 | /** |
||
229 | * Get Border Color. |
||
230 | * |
||
231 | * @return Color |
||
232 | */ |
||
233 | 47 | public function getColor() |
|
237 | |||
238 | /** |
||
239 | * Set Border Color. |
||
240 | * |
||
241 | * @param Color $pValue |
||
242 | * |
||
243 | * @throws PhpSpreadsheetException |
||
244 | * |
||
245 | * @return Border |
||
246 | */ |
||
247 | View Code Duplication | public function setColor(Color $pValue) |
|
261 | |||
262 | /** |
||
263 | * Get hash code. |
||
264 | * |
||
265 | * @return string Hash code |
||
266 | */ |
||
267 | 70 | public function getHashCode() |
|
279 | } |
||
280 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.