| Conditions | 14 |
| Paths | 11 |
| Total Lines | 45 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 8 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 32 | public static function getRetorno($fileName) |
||
| 33 | { |
||
| 34 | if (!$fileName) { |
||
| 35 | throw new InvalidArgumentException("Informe o nome do arquivo de retorno."); |
||
| 36 | } |
||
| 37 | |||
| 38 | $arq = fopen($fileName, "r"); |
||
| 39 | if (!$arq) { |
||
| 40 | throw new FileNotFoundException("Não foi possível abrir o arquivo \"$fileName\"."); |
||
| 41 | } |
||
| 42 | |||
| 43 | //Lê o header do arquivo |
||
| 44 | $linha = fgets($arq, 500); |
||
| 45 | if (!$linha) { |
||
| 46 | fclose($arq); |
||
| 47 | throw new HeaderSectionNotFoundException("Tipo de arquivo de retorno não identificado. Não foi possível ler o header do arquivo."); |
||
| 48 | } |
||
| 49 | |||
| 50 | $len = strlen($linha); |
||
| 51 | if ($len >= 150 && $len <= 152) { |
||
| 52 | return new CNAB150Processor($fileName); |
||
| 53 | } elseif ($len >= 240 && $len <= 242) { |
||
| 54 | return new CNAB240Processor($fileName); |
||
| 55 | } elseif ($len >= 400 && $len <= 402) { |
||
| 56 | if (strstr($linha, "BRADESCO")) { |
||
| 57 | throw new ReturnFileNotSupportedException('Arquivo de retorno Bradesco não suportado.'); |
||
| 58 | } |
||
| 59 | |||
| 60 | //Lê o primeiro registro detalhe |
||
| 61 | $linha = fgets($arq, 500); |
||
| 62 | if (!$linha) { |
||
| 63 | throw new DetailSectionNotFoundException("Tipo de arquivo de retorno não identificado. Não foi possível ler um registro detalhe."); |
||
| 64 | } |
||
| 65 | switch ($linha[0]) { |
||
| 66 | case CNAB400Conv6Processor::DETALHE: |
||
| 67 | return new CNAB400Conv6Processor($fileName); |
||
| 68 | case CNAB400Conv7Processor::DETALHE: |
||
| 69 | return new CNAB400Conv7Processor($fileName); |
||
| 70 | default: |
||
| 71 | throw new Exception("Tipo de registro detalhe desconhecido: " . $linha[0]); |
||
| 72 | } |
||
| 73 | } else { |
||
| 74 | throw new InvalidHeaderException("Tipo de arquivo de retorno não identificado. Total de colunas do header: $len"); |
||
| 75 | } |
||
| 76 | } |
||
| 77 | } |
||
| 78 |