Complex classes like Daruma often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Daruma, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
23 | final class Daruma extends DefaultPrinter implements PrinterInterface |
||
24 | { |
||
25 | /** |
||
26 | * List all available code pages. |
||
27 | * |
||
28 | * @var array |
||
29 | */ |
||
30 | protected $aCodePage = array( |
||
31 | 'ISO8859-1' => array('conv' => 'ISO8859-1', 'table' => '0', 'desc' => 'ISO8859-1: Latin1'), |
||
32 | 'CP437' => array('conv' => '437', 'table' => '3', 'desc' => 'PC437: USA, Standard Europe'), |
||
33 | 'CP850' => array('conv' => '850', 'table' => '1', 'desc' => 'PC850: Multilingual') |
||
34 | ); |
||
35 | /** |
||
36 | * List all available region pages. |
||
37 | * |
||
38 | * @var array |
||
39 | */ |
||
40 | protected $aRegion = array( |
||
41 | 'LATIN', |
||
42 | ); |
||
43 | /** |
||
44 | * List all avaiable fonts |
||
45 | * |
||
46 | * @var array |
||
47 | */ |
||
48 | protected $aFont = array(0 => 'normal', 1 => 'elite'); |
||
49 | /** |
||
50 | * Selected internal font. |
||
51 | * |
||
52 | * @var string |
||
53 | */ |
||
54 | protected $font = 'normal'; |
||
55 | /** |
||
56 | * Seleted code page |
||
57 | * Defined in printer class. |
||
58 | * |
||
59 | * @var string |
||
60 | */ |
||
61 | protected $codepage = 'ISO8859-1'; |
||
62 | /** |
||
63 | * Acceptable barcodes list |
||
64 | * @var array |
||
65 | */ |
||
66 | protected $barcode1Dlist = [ |
||
67 | 'EAN13' => 1, |
||
68 | 'EAN8' => 2, |
||
69 | 'S25' => 3, |
||
70 | 'I25' => 4, |
||
71 | 'CODE128' => 5, |
||
72 | 'CODE39' => 6, |
||
73 | 'CODE93' => 7, |
||
74 | 'UPC_A' => 8, |
||
75 | 'CODABAR' => 9, |
||
76 | 'MSI' => 10, |
||
77 | 'CODE11' => 11 |
||
78 | ]; |
||
79 | /** |
||
80 | * List of supported models |
||
81 | * @var array |
||
82 | */ |
||
83 | protected $modelList = [ |
||
84 | 'DR600', |
||
85 | 'DR700' |
||
86 | ]; |
||
87 | /** |
||
88 | * Selected model |
||
89 | * @var string |
||
90 | */ |
||
91 | protected $printerModel = 'DR700'; |
||
92 | |||
93 | //public function __construct(); vide DefaultPrinter |
||
|
|||
94 | //public function defaultCodePage(); vide DefaultPrinter |
||
95 | //public function defaultRegionPage(); vide DefaultPrinter |
||
96 | //public function defaultFont(); vide DefaultPrinter |
||
97 | //public function defaultModel(); vide DefaultPrinter |
||
98 | //public function initialize(); vide DefaultPrinter |
||
99 | // |
||
100 | // 0000000000111111111122222222223333333333 |
||
101 | // 0123456789012345678901234567890123456789 |
||
102 | //[ESC] 228 0XXXX5678X0XXX45XXXXXXXXXXXXXXXXX3456XX9 |
||
103 | |||
104 | /** |
||
105 | * Select printer mode |
||
106 | * |
||
107 | * @param string $mode |
||
108 | */ |
||
109 | public function setPrintMode($mode = null) |
||
113 | |||
114 | //public function setCodePage(); vide DefaultPrinter |
||
115 | |||
116 | /** |
||
117 | * Set a region page. |
||
118 | * The numeric key of array $this->aRegion is the command parameter. |
||
119 | * |
||
120 | * @param string $region |
||
121 | */ |
||
122 | public function setRegionPage($region = null) |
||
126 | |||
127 | /** |
||
128 | * Set a printer font |
||
129 | * If send a valid font name will set the printer otherelse a default font is selected |
||
130 | * ESC ! n |
||
131 | * n (BIT) FUNÇÃO |
||
132 | * 0 ..... 0 fonte normal |
||
133 | * 1 fonte elite |
||
134 | * 3 ..... 0 desliga enfatizado |
||
135 | * 1 liga enfatizado |
||
136 | * 4 ..... 0 desliga dupla altura |
||
137 | * 1 liga dupla altura |
||
138 | * 5 ..... 0 desliga expandido |
||
139 | * 1 liga expandido |
||
140 | * 7 ..... 0 desliga sublinhado |
||
141 | * 1 liga sublinhado |
||
142 | * |
||
143 | * @param string $font |
||
144 | */ |
||
145 | public function setFont($font = null) |
||
156 | |||
157 | /** |
||
158 | * Set emphasys mode on or off. |
||
159 | */ |
||
160 | public function setBold() |
||
169 | |||
170 | /** |
||
171 | * Set Italic mode |
||
172 | * Apenas para V.02.20.00 ou superior. |
||
173 | */ |
||
174 | public function setItalic() |
||
183 | |||
184 | /** |
||
185 | * Set underline mode on or off. |
||
186 | */ |
||
187 | public function setUnderlined() |
||
192 | |||
193 | /** |
||
194 | * Set or unset condensed mode. |
||
195 | */ |
||
196 | public function setCondensed() |
||
205 | |||
206 | /** |
||
207 | * Set or unset expanded mode. |
||
208 | * |
||
209 | * @param integer $size not used |
||
210 | */ |
||
211 | public function setExpanded($size = null) |
||
216 | |||
217 | /** |
||
218 | * Aligns all data in one line to the selected layout in standard mode. |
||
219 | * L - left C - center R - rigth |
||
220 | * OBS: O comando de justificação de texto desliga as configurações de margem. |
||
221 | * Apenas para V.02.20.00 ou superior. |
||
222 | * |
||
223 | * @param string $align |
||
224 | */ |
||
225 | public function setAlign($align = null) |
||
243 | |||
244 | /** |
||
245 | * Turns white/black reverse print On or Off for characters. |
||
246 | */ |
||
247 | public function setReverseColors() |
||
251 | |||
252 | /** |
||
253 | * Set rotate 90 degrees. |
||
254 | */ |
||
255 | public function setRotate90() |
||
259 | |||
260 | /** |
||
261 | * Set horizontal and vertical motion units |
||
262 | * $horizontal => character spacing 1/x" |
||
263 | * $vertical => line spacing 1/y". |
||
264 | * DLE A x y |
||
265 | * Ajusta a unidade de movimento horizontal e vertical para aproximadamente |
||
266 | * 25.4/x mm {1/x"} e 25.4/y mm {1/y"}. A unidade horizontal (x) não é utilizada |
||
267 | * na impressora. |
||
268 | * Faixa: 0 ≤ x ≤ 255 |
||
269 | * 0 ≤ y ≤ 255 |
||
270 | * Padrão: x = 200 (sem uso na impressora) |
||
271 | * y = 400 |
||
272 | * Quando x e y são igual a zero, o valor padrão é carregado. |
||
273 | * |
||
274 | * @param int $horizontal |
||
275 | * @param int $vertical |
||
276 | */ |
||
277 | public function setSpacing($horizontal = 30, $vertical = 30) |
||
283 | |||
284 | /** |
||
285 | * Set right-side character spacing |
||
286 | * 0 ≤ n ≤ 255 => 1/x". |
||
287 | * |
||
288 | * @param int $value |
||
289 | */ |
||
290 | public function setCharSpacing($value = 3) |
||
294 | |||
295 | //public function setParagraph(); vide DefaultPrinter |
||
296 | //public function text(); vide default |
||
297 | |||
298 | /** |
||
299 | * Prints data and feeds paper n lines |
||
300 | * ESC d n Prints data and feeds paper n lines. |
||
301 | * |
||
302 | * @param integer $lines |
||
303 | */ |
||
304 | public function lineFeed($lines = 1) |
||
311 | |||
312 | //public function dotFeed(); vide default |
||
313 | |||
314 | /** |
||
315 | * Insert a image. |
||
316 | * DLE X m xL xH yL yH d1....dk |
||
317 | * m Mode Vertical Dot Density Horizontal Dot Density |
||
318 | * 0 Normal 200 dpi 200 dpi |
||
319 | * 1 Double-width 200 dpi 100 dpi |
||
320 | * 2 Double-height 100 dpi 200 dpi |
||
321 | * 3 Quadruple 100 dpi 100 dpi |
||
322 | * |
||
323 | * @param string $filename Path to image file |
||
324 | * @param int $width |
||
325 | * @param int $height |
||
326 | * @param int $size 0-normal 1-Double Width 2-Double Heigth 3-Quadruple |
||
327 | * @throws RuntimeException |
||
328 | */ |
||
329 | public function putImage($filename = '', $width = null, $height = null, $size = 0) |
||
342 | |||
343 | /** |
||
344 | * Generate a pulse, for opening a cash drawer if one is connected. |
||
345 | * |
||
346 | * @param int $pin not for this printer |
||
347 | * @param int $on_ms not for this printer |
||
348 | * @param int $off_ms not for this printer |
||
349 | */ |
||
350 | public function pulse($pin = 0, $on_ms = 120, $off_ms = 240) |
||
354 | |||
355 | /** |
||
356 | * Cut the paper. |
||
357 | * |
||
358 | * @param int $mode FULL or PARTIAL. not for this printer. |
||
359 | * @param int $lines Number of lines to feed after cut |
||
360 | */ |
||
361 | public function cut($mode = 'PARTIAL', $lines = 3) |
||
366 | |||
367 | /** |
||
368 | * Implements barcodes 1D |
||
369 | * ESC b n1 n2 n3 n4 s1...sn NULL |
||
370 | * n1 – tipo do código a ser impresso |
||
371 | * EAN13 1 |
||
372 | * EAN8 2 |
||
373 | * S2OF5 3 |
||
374 | * I2OF5 4 |
||
375 | * CODE128 5 |
||
376 | * CODE39 6 |
||
377 | * CODE93 7 |
||
378 | * UPC_A 8 |
||
379 | * CODABAR 9 |
||
380 | * MSI 10 |
||
381 | * CODE11 11 |
||
382 | * n2 – largura da barra. De 2 a 5. Se 0, é usado 2. |
||
383 | * n3 – altura da barra. De 50 a 200. Se 0, é usado 50. |
||
384 | * n4 – se 1, imprime o código abaixo das barras |
||
385 | * s1...sn – string contendo o código. |
||
386 | * EAN-13: 12 dígitos de 0 a 9 |
||
387 | * EAN–8: 7 dígitos de 0 a 9 |
||
388 | * UPC–A: 11 dígitos de 0 a 9 |
||
389 | * CODE 39 : Tamanho variável. 0-9, A-Z, '-', '.', '%', '/', '$', ' ', '+' |
||
390 | * O caracter '*' de start/stop é inserido automaticamente. |
||
391 | * Sem dígito de verificação MOD 43 |
||
392 | * CODE 93: Tamanho variável. 0-9, A-Z, '-', '.', ' ', '$', '/', '+', '%' |
||
393 | * O caracter '*' de start/stop é inserido automaticamente. |
||
394 | * CODABAR: tamanho variável. 0 - 9, '$', '-', ':', '/', '.', '+' |
||
395 | * Existem 4 diferentes caracteres de start/stop: A, B, C, and D que são |
||
396 | * usados em pares e não podem aparecer em nenhum outro lugar do código. |
||
397 | * Sem dígito de verificação |
||
398 | * CODE 11: Tamanho variável. 0 a 9 |
||
399 | * Checksum de dois caracteres. |
||
400 | * CODE 128: Tamanho variável. Todos os caracteres ASCII. |
||
401 | * Interleaved 2 of 5: tamanho sempre par. 0 a 9. Sem dígito de verificação |
||
402 | * Standard 2 of 5 (Industrial): 0 a 9. Sem dígito de verificação |
||
403 | * MSI/Plessey: tamanho variável. 0 - 9. 1 dígito de verificação |
||
404 | * |
||
405 | * @param string $type Default CODE128 |
||
406 | * @param int $height |
||
407 | * @param int $lineWidth |
||
408 | * @param string $txtPosition |
||
409 | * @param string $txtFont |
||
410 | * @param string $data |
||
411 | */ |
||
412 | public function barcode( |
||
435 | |||
436 | /** |
||
437 | * Print PDF 417 2D barcode |
||
438 | * @param string $data |
||
439 | * @param integer $ecc |
||
440 | * @param integer $pheight |
||
441 | * @param integer $pwidth |
||
442 | * @param integer $colunms |
||
443 | * @return boolean |
||
444 | */ |
||
445 | public function barcodePDF417($data = '', $ecc = 5, $pheight = 2, $pwidth = 2, $colunms = 3) |
||
482 | |||
483 | /** |
||
484 | * Print QR Code |
||
485 | * [ESC] <129> <–Size><+Size> <Width> <Ecc> <D001> <D002> . . . <Dnnn> |
||
486 | * Size inclui os 2 bytes de controle |
||
487 | * Size ≤ 402 |
||
488 | * nnn = Size – 2 |
||
489 | * Largura do módulo (Width): 0, 4 ≤ Width ≤ 7 ( =0 para default = 5) |
||
490 | * Redundância (ECC): 0, M, Q, H ( =0 para cálculo automático) |
||
491 | * Apenas para V.02.50.00 ou superior. |
||
492 | * |
||
493 | * @param string $data Dados a serem inseridos no QRCode |
||
494 | * @param string $level Nivel de correção L,M,Q ou H |
||
495 | * @param int $modelo modelo de QRCode none |
||
496 | * @param int $wmod largura da barra 4 ~ 7 |
||
497 | */ |
||
498 | public function barcodeQRCode($data = '', $level = 'L', $modelo = 2, $wmod = 4) |
||
523 | //public function send(); vide DefultPrinter |
||
524 | //public function close(); vide DefaultPrinter |
||
525 | } |
||
526 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.