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:
Complex classes like Make 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 Make, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 25 | class Make extends BaseMake |
||
| 26 | { |
||
| 27 | /** |
||
| 28 | * versao |
||
| 29 | * numero da versão do xml da MDFe |
||
| 30 | * |
||
| 31 | * @var string |
||
| 32 | */ |
||
| 33 | public $versao = '1.00'; |
||
| 34 | /** |
||
| 35 | * mod |
||
| 36 | * modelo da MDFe 58 |
||
| 37 | * |
||
| 38 | * @var integer |
||
| 39 | */ |
||
| 40 | public $mod = '58'; |
||
| 41 | /** |
||
| 42 | * chave da MDFe |
||
| 43 | * |
||
| 44 | * @var string |
||
| 45 | */ |
||
| 46 | public $chMDFe = ''; |
||
| 47 | |||
| 48 | //propriedades privadas utilizadas internamente pela classe |
||
| 49 | /** |
||
| 50 | * @type string|\DOMNode |
||
| 51 | */ |
||
| 52 | private $MDFe = ''; |
||
| 53 | /** |
||
| 54 | * @type string|\DOMNode |
||
| 55 | */ |
||
| 56 | private $infMDFe = ''; |
||
| 57 | /** |
||
| 58 | * @type string|\DOMNode |
||
| 59 | */ |
||
| 60 | private $ide = ''; |
||
| 61 | /** |
||
| 62 | * @type string|\DOMNode |
||
| 63 | */ |
||
| 64 | private $emit = ''; |
||
| 65 | /** |
||
| 66 | * @type string|\DOMNode |
||
| 67 | */ |
||
| 68 | private $enderEmit = ''; |
||
| 69 | /** |
||
| 70 | * @type string|\DOMNode |
||
| 71 | */ |
||
| 72 | private $infModal = ''; |
||
| 73 | /** |
||
| 74 | * @type string|\DOMNode |
||
| 75 | */ |
||
| 76 | private $tot = ''; |
||
| 77 | /** |
||
| 78 | * @type string|\DOMNode |
||
| 79 | */ |
||
| 80 | private $infAdic = ''; |
||
| 81 | /** |
||
| 82 | * @type string|\DOMNode |
||
| 83 | */ |
||
| 84 | private $rodo = ''; |
||
| 85 | /** |
||
| 86 | * @type string|\DOMNode |
||
| 87 | */ |
||
| 88 | private $veicTracao = ''; |
||
| 89 | /** |
||
| 90 | * @type string|\DOMNode |
||
| 91 | */ |
||
| 92 | private $aereo = ''; |
||
| 93 | /** |
||
| 94 | * @type string|\DOMNode |
||
| 95 | */ |
||
| 96 | private $trem = ''; |
||
| 97 | /** |
||
| 98 | * @type string|\DOMNode |
||
| 99 | */ |
||
| 100 | private $aqua = ''; |
||
| 101 | |||
| 102 | // Arrays |
||
| 103 | private $aInfMunCarrega = []; //array de DOMNode |
||
| 104 | private $aInfPercurso = []; //array de DOMNode |
||
| 105 | private $aInfMunDescarga = []; //array de DOMNode |
||
| 106 | private $aInfCTe = []; //array de DOMNode |
||
| 107 | private $aInfNFe = []; //array de DOMNode |
||
| 108 | private $aInfMDFe = []; //array de DOMNode |
||
| 109 | private $aLacres = []; //array de DOMNode |
||
| 110 | private $aAutXML = []; //array de DOMNode |
||
| 111 | private $aCondutor = []; //array de DOMNode |
||
| 112 | private $aReboque = []; //array de DOMNode |
||
| 113 | private $aDisp = []; //array de DOMNode |
||
| 114 | private $aVag = []; //array de DOMNode |
||
| 115 | private $aInfTermCarreg = []; //array de DOMNode |
||
| 116 | private $aInfTermDescarreg = []; //array de DOMNode |
||
| 117 | private $aInfEmbComb = []; //array de DOMNode |
||
| 118 | private $aCountDoc = []; //contador de documentos fiscais |
||
| 119 | |||
| 120 | /** |
||
| 121 | * |
||
| 122 | * @return boolean |
||
| 123 | */ |
||
| 124 | public function montaMDFe() |
||
| 167 | |||
| 168 | |||
| 169 | /** |
||
| 170 | * taginfMDFe |
||
| 171 | * Informações da MDFe 1 pai MDFe |
||
| 172 | * tag MDFe/infMDFe |
||
| 173 | * |
||
| 174 | * @param string $chave |
||
| 175 | * @param string $versao |
||
| 176 | * |
||
| 177 | * @return DOMElement |
||
| 178 | */ |
||
| 179 | public function taginfMDFe($chave = '', $versao = '') |
||
| 180 | { |
||
| 181 | $this->infMDFe = $this->dom->createElement("infMDFe"); |
||
| 182 | $this->infMDFe->setAttribute("Id", 'MDFe'.$chave); |
||
| 183 | $this->infMDFe->setAttribute("versao", $versao); |
||
| 184 | $this->chMDFe = $chave; |
||
| 185 | $this->versao = $versao; |
||
| 186 | return $this->infMDFe; |
||
| 187 | } |
||
| 188 | |||
| 189 | /** |
||
| 190 | * tgaide |
||
| 191 | * Informações de identificação da MDFe 4 pai 1 |
||
| 192 | * tag MDFe/infMDFe/ide |
||
| 193 | * |
||
| 194 | * @param string $cUF |
||
| 195 | * @param string $tpAmb |
||
| 196 | * @param string $tpEmit |
||
| 197 | * @param string $mod |
||
| 198 | * @param string $serie |
||
| 199 | * @param string $nMDF |
||
| 200 | * @param string $cMDF |
||
| 201 | * @param string $cDV |
||
| 202 | * @param string $modal |
||
| 203 | * @param string $dhEmi |
||
| 204 | * @param string $tpEmis |
||
| 205 | * @param string $procEmi |
||
| 206 | * @param string $verProc |
||
| 207 | * @param string $ufIni |
||
| 208 | * @param string $ufFim |
||
| 209 | * |
||
| 210 | * @return DOMElement |
||
| 211 | */ |
||
| 212 | public function tagide( |
||
| 344 | |||
| 345 | /** |
||
| 346 | * tagInfMunCarrega |
||
| 347 | * |
||
| 348 | * tag MDFe/infMDFe/ide/infMunCarrega |
||
| 349 | * |
||
| 350 | * @param string $cMunCarrega |
||
| 351 | * @param string $xMunCarrega |
||
| 352 | * |
||
| 353 | * @return DOMElement |
||
| 354 | */ |
||
| 355 | public function tagInfMunCarrega( |
||
| 377 | |||
| 378 | /** |
||
| 379 | * tagInfPercurso |
||
| 380 | * |
||
| 381 | * tag MDFe/infMDFe/ide/infPercurso |
||
| 382 | * |
||
| 383 | * @param string $ufPer |
||
| 384 | * |
||
| 385 | * @return DOMElement |
||
| 386 | */ |
||
| 387 | public function tagInfPercurso($ufPer = '') |
||
| 400 | |||
| 401 | /** |
||
| 402 | * tagemit |
||
| 403 | * Identificação do emitente da MDFe [25] pai 1 |
||
| 404 | * tag MDFe/infMDFe/emit |
||
| 405 | * |
||
| 406 | * @param string $cnpj |
||
| 407 | * @param string $numIE |
||
| 408 | * @param string $xNome |
||
| 409 | * @param string $xFant |
||
| 410 | * |
||
| 411 | * @return DOMElement |
||
| 412 | */ |
||
| 413 | public function tagemit( |
||
| 427 | |||
| 428 | /** |
||
| 429 | * tagenderEmit |
||
| 430 | * Endereço do emitente [30] pai [25] |
||
| 431 | * tag MDFe/infMDFe/emit/endEmit |
||
| 432 | * |
||
| 433 | * @param string $xLgr |
||
| 434 | * @param string $nro |
||
| 435 | * @param string $xCpl |
||
| 436 | * @param string $xBairro |
||
| 437 | * @param string $cMun |
||
| 438 | * @param string $xMun |
||
| 439 | * @param string $cep |
||
| 440 | * @param string $siglaUF |
||
| 441 | * @param string $fone |
||
| 442 | * @param string $email |
||
| 443 | * |
||
| 444 | * @return DOMElement |
||
| 445 | */ |
||
| 446 | public function tagenderEmit( |
||
| 532 | |||
| 533 | /** |
||
| 534 | * tagInfMunDescarga |
||
| 535 | * tag MDFe/infMDFe/infDoc/infMunDescarga |
||
| 536 | * |
||
| 537 | * @param integer $nItem |
||
| 538 | * @param string $cMunDescarga |
||
| 539 | * @param string $xMunDescarga |
||
| 540 | * |
||
| 541 | * @return DOMElement |
||
| 542 | */ |
||
| 543 | public function tagInfMunDescarga( |
||
| 566 | |||
| 567 | /** |
||
| 568 | * tagInfCTe |
||
| 569 | * tag MDFe/infMDFe/infDoc/infMunDescarga/infCTe |
||
| 570 | * |
||
| 571 | * @param integer $nItem |
||
| 572 | * @param string $chCTe |
||
| 573 | * @param string $segCodBarra |
||
| 574 | * |
||
| 575 | * @return DOMElement |
||
| 576 | */ |
||
| 577 | View Code Duplication | public function tagInfCTe( |
|
| 600 | |||
| 601 | /** |
||
| 602 | * tagInfNFe |
||
| 603 | * tag MDFe/infMDFe/infDoc/infMunDescarga/infNFe |
||
| 604 | * |
||
| 605 | * @param integer $nItem |
||
| 606 | * @param string $chNFe |
||
| 607 | * @param string $segCodBarra |
||
| 608 | * |
||
| 609 | * @return DOMElement |
||
| 610 | */ |
||
| 611 | View Code Duplication | public function tagInfNFe( |
|
| 634 | |||
| 635 | /** |
||
| 636 | * tagInfMDFeTransp |
||
| 637 | * tag MDFe/infMDFeTransp/infDoc/infMunDescarga/infMDFeTranspTransp |
||
| 638 | * |
||
| 639 | * @param integer $nItem |
||
| 640 | * @param string $chMDFe |
||
| 641 | * |
||
| 642 | * @return DOMElement |
||
| 643 | */ |
||
| 644 | public function tagInfMDFeTransp( |
||
| 659 | |||
| 660 | /** |
||
| 661 | * tagTot |
||
| 662 | * tag MDFe/infMDFe/tot |
||
| 663 | * |
||
| 664 | * @param string $qCTe |
||
| 665 | * @param string $qNFe |
||
| 666 | * @param string $qMDFe |
||
| 667 | * @param string $vCarga |
||
| 668 | * @param string $cUnid |
||
| 669 | * @param string $qCarga |
||
| 670 | * |
||
| 671 | * @return DOMElement |
||
| 672 | */ |
||
| 673 | public function tagTot( |
||
| 727 | |||
| 728 | /** |
||
| 729 | * tagLacres |
||
| 730 | * tag MDFe/infMDFe/lacres |
||
| 731 | * |
||
| 732 | * @param string $nLacre |
||
| 733 | * |
||
| 734 | * @return DOMElement |
||
| 735 | */ |
||
| 736 | public function tagLacres( |
||
| 750 | |||
| 751 | /** |
||
| 752 | * taginfAdic |
||
| 753 | * Grupo de Informações Adicionais Z01 pai A01 |
||
| 754 | * tag MDFe/infMDFe/infAdic (opcional) |
||
| 755 | * |
||
| 756 | * @param string $infAdFisco |
||
| 757 | * @param string $infCpl |
||
| 758 | * |
||
| 759 | * @return DOMElement |
||
| 760 | */ |
||
| 761 | public function taginfAdic( |
||
| 783 | |||
| 784 | /** |
||
| 785 | * tagLacres |
||
| 786 | * tag MDFe/infMDFe/autXML |
||
| 787 | * |
||
| 788 | * Autorizados para download do XML do MDF-e |
||
| 789 | * |
||
| 790 | * @param string $cnpj |
||
| 791 | * @param string $cpf |
||
| 792 | * |
||
| 793 | * @return DOMElement |
||
| 794 | */ |
||
| 795 | public function tagautXML($cnpj = '', $cpf = '') |
||
| 815 | |||
| 816 | /** |
||
| 817 | * tagInfModal |
||
| 818 | * tag MDFe/infMDFe/infModal |
||
| 819 | * |
||
| 820 | * @param string $versaoModal |
||
| 821 | * |
||
| 822 | * @return DOMElement |
||
| 823 | */ |
||
| 824 | public function tagInfModal($versaoModal = '') |
||
| 825 | { |
||
| 826 | $infModal = $this->dom->createElement("infModal"); |
||
| 827 | $infModal->setAttribute("versaoModal", $versaoModal); |
||
| 828 | $this->infModal = $infModal; |
||
| 829 | return $infModal; |
||
| 830 | } |
||
| 831 | |||
| 832 | /** |
||
| 833 | * tagAereo |
||
| 834 | * tag MDFe/infMDFe/infModal/aereo |
||
| 835 | * |
||
| 836 | * @param string $nac |
||
| 837 | * @param string $matr |
||
| 838 | * @param string $nVoo |
||
| 839 | * @param string $cAerEmb |
||
| 840 | * @param string $cAerDes |
||
| 841 | * @param string $dVoo |
||
| 842 | * |
||
| 843 | * @return DOMElement |
||
| 844 | */ |
||
| 845 | public function tagAereo( |
||
| 899 | |||
| 900 | /** |
||
| 901 | * tagTrem |
||
| 902 | * tag MDFe/infMDFe/infModal/ferrov/trem |
||
| 903 | * |
||
| 904 | * @param string $xPref |
||
| 905 | * @param string $dhTrem |
||
| 906 | * @param string $xOri |
||
| 907 | * @param string $xDest |
||
| 908 | * @param string $qVag |
||
| 909 | * |
||
| 910 | * @return DOMElement |
||
| 911 | */ |
||
| 912 | public function tagTrem( |
||
| 958 | |||
| 959 | /** |
||
| 960 | * tagVag |
||
| 961 | * tag MDFe/infMDFe/infModal/ferrov/trem/vag |
||
| 962 | * |
||
| 963 | * @param string $serie |
||
| 964 | * @param string $nVag |
||
| 965 | * @param string $nSeq |
||
| 966 | * @param string $tonUtil |
||
| 967 | * |
||
| 968 | * @return DOMElement |
||
| 969 | */ |
||
| 970 | public function tagVag( |
||
| 1008 | |||
| 1009 | /** |
||
| 1010 | * tagAqua |
||
| 1011 | * tag MDFe/infMDFe/infModal/Aqua |
||
| 1012 | * |
||
| 1013 | * @param string $cnpjAgeNav |
||
| 1014 | * @param string $tpEmb |
||
| 1015 | * @param string $cEmbar |
||
| 1016 | * @param string $nViagem |
||
| 1017 | * @param string $cPrtEmb |
||
| 1018 | * @param string $cPrtDest |
||
| 1019 | * |
||
| 1020 | * @return DOMElement |
||
| 1021 | */ |
||
| 1022 | public function tagAqua( |
||
| 1076 | |||
| 1077 | /** |
||
| 1078 | * tagInfTermCarreg |
||
| 1079 | * tag MDFe/infMDFe/infModal/Aqua/infTermCarreg |
||
| 1080 | * |
||
| 1081 | * @param string $cTermCarreg |
||
| 1082 | * |
||
| 1083 | * @return DOMElement |
||
| 1084 | */ |
||
| 1085 | public function tagInfTermCarreg( |
||
| 1099 | |||
| 1100 | /** |
||
| 1101 | * tagInfTermDescarreg |
||
| 1102 | * tag MDFe/infMDFe/infModal/Aqua/infTermDescarreg |
||
| 1103 | * |
||
| 1104 | * @param string $cTermDescarreg |
||
| 1105 | * |
||
| 1106 | * @return DOMElement |
||
| 1107 | */ |
||
| 1108 | public function tagInfTermDescarreg( |
||
| 1122 | |||
| 1123 | /** |
||
| 1124 | * tagInfEmbComb |
||
| 1125 | * tag MDFe/infMDFe/infModal/Aqua/infEmbComb |
||
| 1126 | * |
||
| 1127 | * @param string $cEmbComb |
||
| 1128 | * |
||
| 1129 | * @return DOMElement |
||
| 1130 | */ |
||
| 1131 | public function tagInfEmbComb( |
||
| 1145 | |||
| 1146 | /** |
||
| 1147 | * tagRodo |
||
| 1148 | * tag MDFe/infMDFe/infModal/rodo |
||
| 1149 | * |
||
| 1150 | * @param string $rntrc |
||
| 1151 | * @param string $ciot |
||
| 1152 | * |
||
| 1153 | * @return DOMElement |
||
| 1154 | */ |
||
| 1155 | public function tagRodo( |
||
| 1177 | |||
| 1178 | /** |
||
| 1179 | * tagVeicTracao |
||
| 1180 | * tag MDFe/infMDFe/infModal/rodo/veicTracao |
||
| 1181 | * |
||
| 1182 | * @param string $cInt |
||
| 1183 | * @param string $placa |
||
| 1184 | * @param string $tara |
||
| 1185 | * @param string $capKG |
||
| 1186 | * @param string $capM3 |
||
| 1187 | * @param string $tpRod |
||
| 1188 | * @param string $tpCar |
||
| 1189 | * @param string $UF |
||
| 1190 | * @param string $propRNTRC |
||
| 1191 | * @param string $propCPF |
||
| 1192 | * @param string $propCNPJ |
||
| 1193 | * @param string $propXNome |
||
| 1194 | * @param string $propIE |
||
| 1195 | * @param string $propUF |
||
| 1196 | * @param string $propTpProp |
||
| 1197 | * |
||
| 1198 | * @return DOMElement |
||
| 1199 | */ |
||
| 1200 | View Code Duplication | public function tagVeicTracao( |
|
| 1239 | |||
| 1240 | /** |
||
| 1241 | * tagCondutor |
||
| 1242 | * tag MDFe/infMDFe/infModal/rodo/veicTracao/condutor |
||
| 1243 | * |
||
| 1244 | * @param string $xNome |
||
| 1245 | * @param string $cpf |
||
| 1246 | * |
||
| 1247 | * @return DOMElement |
||
| 1248 | */ |
||
| 1249 | public function tagCondutor( |
||
| 1271 | |||
| 1272 | /** |
||
| 1273 | * tagVeicReboque |
||
| 1274 | * tag MDFe/infMDFe/infModal/rodo/reboque |
||
| 1275 | * |
||
| 1276 | * @param string $cInt |
||
| 1277 | * @param string $placa |
||
| 1278 | * @param string $tara |
||
| 1279 | * @param string $capKG |
||
| 1280 | * @param string $capM3 |
||
| 1281 | * @param string $propRNTRC |
||
| 1282 | * @param string $propCPF |
||
| 1283 | * @param string $propCNPJ |
||
| 1284 | * @param string $propXNome |
||
| 1285 | * @param string $propIE |
||
| 1286 | * @param string $propUF |
||
| 1287 | * @param string $propTpProp |
||
| 1288 | * @param string $tpCar |
||
| 1289 | * @param string $UF |
||
| 1290 | * |
||
| 1291 | * @return DOMElement |
||
| 1292 | */ |
||
| 1293 | View Code Duplication | public function tagVeicReboque( |
|
| 1333 | |||
| 1334 | /** |
||
| 1335 | * tagValePed |
||
| 1336 | * tag MDFe/infMDFe/infModal/rodo/valePed |
||
| 1337 | * |
||
| 1338 | * @param string $cnpjForn |
||
| 1339 | * @param string $cnpjPg |
||
| 1340 | * @param string $nCompra |
||
| 1341 | * |
||
| 1342 | * @return DOMElement |
||
| 1343 | */ |
||
| 1344 | public function tagValePed( |
||
| 1374 | |||
| 1375 | /** |
||
| 1376 | * zTagVeiculo |
||
| 1377 | * |
||
| 1378 | * @param string $tag |
||
| 1379 | * @param string $cInt |
||
| 1380 | * @param string $placa |
||
| 1381 | * @param string $tara |
||
| 1382 | * @param array $condutores |
||
| 1383 | * @param string $capKG |
||
| 1384 | * @param string $capM3 |
||
| 1385 | * @param string $tpRod |
||
| 1386 | * @param string $tpCar |
||
| 1387 | * @param string $UF |
||
| 1388 | * @param string $propRNTRC |
||
| 1389 | * @param string $propCPF |
||
| 1390 | * @param string $propCNPJ |
||
| 1391 | * @param string $propXNome |
||
| 1392 | * @param string $propIE |
||
| 1393 | * @param string $propUF |
||
| 1394 | * @param string $propTpProp |
||
| 1395 | * |
||
| 1396 | * @return DOMElement |
||
| 1397 | */ |
||
| 1398 | protected function zTagVeiculo( |
||
| 1503 | |||
| 1504 | /** |
||
| 1505 | * @param string $tag |
||
| 1506 | * @param string $CPF |
||
| 1507 | * @param string $CNPJ |
||
| 1508 | * @param string $RNTRC |
||
| 1509 | * @param string $xNome |
||
| 1510 | * @param string $IE |
||
| 1511 | * @param string $UF |
||
| 1512 | * @param string $tpProp |
||
| 1513 | * |
||
| 1514 | * @return DOMElement |
||
| 1515 | */ |
||
| 1516 | protected function zTagPropVeiculo( |
||
| 1588 | |||
| 1589 | /** |
||
| 1590 | * zTagMDFe |
||
| 1591 | * Tag raiz da MDFe |
||
| 1592 | * tag MDFe DOMNode |
||
| 1593 | * Função chamada pelo método [ monta ] |
||
| 1594 | * |
||
| 1595 | * @return DOMElement |
||
| 1596 | */ |
||
| 1597 | protected function zTagMDFe() |
||
| 1605 | |||
| 1606 | /** |
||
| 1607 | * Adiciona as tags |
||
| 1608 | * infMunCarrega e infPercurso |
||
| 1609 | * a tag ide |
||
| 1610 | */ |
||
| 1611 | protected function zTagIde() |
||
| 1616 | |||
| 1617 | /** |
||
| 1618 | * Processa lacres |
||
| 1619 | */ |
||
| 1620 | protected function zTagLacres() |
||
| 1624 | |||
| 1625 | /** |
||
| 1626 | * Proecessa documentos fiscais |
||
| 1627 | */ |
||
| 1628 | protected function zTagInfDoc() |
||
| 1661 | |||
| 1662 | /** |
||
| 1663 | * Processa modal rodoviario |
||
| 1664 | */ |
||
| 1665 | protected function zTagRodo() |
||
| 1680 | |||
| 1681 | /** |
||
| 1682 | * Proecessa modal ferroviario |
||
| 1683 | */ |
||
| 1684 | protected function zTagFerrov() |
||
| 1693 | |||
| 1694 | /** |
||
| 1695 | * Processa modal aereo |
||
| 1696 | */ |
||
| 1697 | protected function zTagAereo() |
||
| 1703 | |||
| 1704 | /** |
||
| 1705 | * Processa modal aquaviário |
||
| 1706 | */ |
||
| 1707 | protected function zTagAqua() |
||
| 1716 | |||
| 1717 | /** |
||
| 1718 | * zTestaChaveXML |
||
| 1719 | * Remonta a chave da NFe de 44 digitos com base em seus dados |
||
| 1720 | * Isso é útil no caso da chave informada estar errada |
||
| 1721 | * se a chave estiver errada a mesma é substituida |
||
| 1722 | * |
||
| 1723 | * @param object $dom |
||
| 1724 | */ |
||
| 1725 | private function zTestaChaveXML($dom) |
||
| 1760 | } |
||
| 1761 |
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.