Complex classes like Common 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 Common, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 5 | class Common |
||
| 6 | { |
||
| 7 | |||
| 8 | /** |
||
| 9 | * Extrai o valor do node DOM |
||
| 10 | * @param object $theObj Instancia de DOMDocument ou DOMElement |
||
| 11 | * @param string $keyName identificador da TAG do xml |
||
| 12 | * @param string $extraTextBefore prefixo do retorno |
||
| 13 | * @param string extraTextAfter sufixo do retorno |
||
| 14 | * @param number itemNum numero do item a ser retornado |
||
| 15 | * @return string |
||
| 16 | */ |
||
| 17 | protected function getTagValue($theObj, $keyName, $extraTextBefore = '', $extraTextAfter = '', $itemNum = 0) |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Recupera e reformata a data do padrão da NFe para dd/mm/aaaa |
||
| 36 | * @author Marcos Diez |
||
| 37 | * @param DOM $theObj |
||
| 38 | * @param string $keyName identificador da TAG do xml |
||
| 39 | * @param string $extraText prefixo do retorno |
||
| 40 | * @return string |
||
| 41 | */ |
||
| 42 | protected function getTagDate($theObj, $keyName, $extraText = '') |
||
| 43 | { |
||
| 44 | if (!isset($theObj) || !is_object($theObj)) { |
||
| 45 | return ''; |
||
| 46 | } |
||
| 47 | $vct = $theObj->getElementsByTagName($keyName)->item(0); |
||
| 48 | if (isset($vct)) { |
||
| 49 | $theDate = explode("-", $vct->nodeValue); |
||
| 50 | return $extraText . $theDate[2] . "/" . $theDate[1] . "/" . $theDate[0]; |
||
| 51 | } |
||
| 52 | return ''; |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * camcula digito de controle modulo 11 |
||
| 57 | * @param string $numero |
||
| 58 | * @return integer modulo11 do numero passado |
||
| 59 | */ |
||
| 60 | protected function modulo11($numero = '') |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Converte datas no formato YMD (ex. 2009-11-02) para o formato brasileiro 02/11/2009) |
||
| 84 | * @param string $data Parâmetro extraido da NFe |
||
| 85 | * @return string Formatada para apresentação da data no padrão brasileiro |
||
| 86 | */ |
||
| 87 | protected function ymdTodmy($data = '') |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Converte data da NFe YYYY-mm-ddThh:mm:ss-03:00 para timestamp unix |
||
| 102 | * |
||
| 103 | * @param string $input |
||
| 104 | * |
||
| 105 | * @return integer |
||
| 106 | */ |
||
| 107 | public function toTimestamp($input) |
||
| 120 | |||
| 121 | /** |
||
| 122 | * Converte data da NFe YYYY-mm-ddThh:mm:ss-03:00 para \DateTime |
||
| 123 | * |
||
| 124 | * @param string $input |
||
| 125 | * |
||
| 126 | * @return \DateTime |
||
| 127 | */ |
||
| 128 | public function toDateTime($input) |
||
| 136 | |||
| 137 | /** |
||
| 138 | * Função de formatação de strings onde o cerquilha # é um coringa |
||
| 139 | * que será substituido por digitos contidos em campo. |
||
| 140 | * @param string $campo String a ser formatada |
||
| 141 | * @param string $mascara Regra de formatção da string (ex. ##.###.###/####-##) |
||
| 142 | * @return string Retorna o campo formatado |
||
| 143 | */ |
||
| 144 | protected function formatField($campo = '', $mascara = '') |
||
| 224 | |||
| 225 | protected function tipoPag($tPag) |
||
| 285 | } |
||
| 286 |