| Conditions | 1 | 
| Paths | 1 | 
| Total Lines | 55 | 
| Code Lines | 47 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 3 | ||
| 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  | 
            ||
| 94 | protected function processarDetalhe($linha)  | 
            ||
| 95 |     { | 
            ||
| 96 | $detail = $this->createDetail();  | 
            ||
| 97 | |||
| 98 | $bancoEmissor = new Banco();  | 
            ||
| 99 | $bancoEmissor  | 
            ||
| 100 | ->setAgencia(substr($linha, 22, 1))  | 
            ||
| 101 | ->setDvAgencia(substr($linha, 31, 1))  | 
            ||
| 102 | ->setConta(substr($linha, 23, 8))  | 
            ||
| 103 | ->setDvConta(substr($linha, 31, 1));  | 
            ||
| 104 | |||
| 105 | $bancoRecebedor = new Banco();  | 
            ||
| 106 | $bancoRecebedor  | 
            ||
| 107 | ->setCod(substr($linha, 166, 3))  | 
            ||
| 108 | ->setAgencia(substr($linha, 169, 4))  | 
            ||
| 109 | ->setDvAgencia(substr($linha, 173, 1));  | 
            ||
| 110 | |||
| 111 | $bancoEmpresa = new Banco();  | 
            ||
| 112 | $bancoEmpresa->setCod(substr($linha, 21, 17));  | 
            ||
| 113 | $empresa = new Empresa();  | 
            ||
| 114 | $empresa  | 
            ||
| 115 | ->setBanco($bancoEmpresa)  | 
            ||
| 116 | ->setTipoInscricao(substr($linha, 2, 2))  | 
            ||
| 117 | ->setNumInscricao(substr($linha, 4, 14))  | 
            ||
| 118 | ->addReservado(substr($linha, 38, 25));  | 
            ||
| 119 | |||
| 120 | $detail  | 
            ||
| 121 | ->setBancoEmissor($bancoEmissor)  | 
            ||
| 122 | ->setBancoRecebedor($bancoRecebedor)  | 
            ||
| 123 | ->setRegistro(substr($linha, 1, 1))  | 
            ||
| 124 | ->setNumOcorrencia(substr($linha, 117, 10))  | 
            ||
| 125 | ->setDataVencimento(substr($linha, 147, 6))  | 
            ||
| 126 | ->setValor($this->formataNumero(substr($linha, 153, 13)))  | 
            ||
| 127 | ->setDespCobranca(substr($linha, 176, 2))  | 
            ||
| 128 | ->setOutrasDespesas($this->formataNumero(substr($linha, 189, 13)))  | 
            ||
| 129 | ->setJurosAtraso($this->formataNumero(substr($linha, 202, 13)))  | 
            ||
| 130 | ->setTaxaIof($this->formataNumero(substr($linha, 215, 13)))  | 
            ||
| 131 | ->setDescontoConcedido($this->formataNumero(substr($linha, 241, 13)))  | 
            ||
| 132 | ->setValorRecebido($this->formataNumero(substr($linha, 254, 13)))  | 
            ||
| 133 | ->setJurosMora($this->formataNumero(substr($linha, 267, 13)))  | 
            ||
| 134 | ->setOutrosRecebimentos($this->formataNumero(substr($linha, 280, 13)))  | 
            ||
| 135 | ->setValorAbatimento($this->formataNumero(substr($linha, 228, 13)))  | 
            ||
| 136 | ->setValorLancamento($this->formataNumero(substr($linha, 306, 13)))  | 
            ||
| 137 | ->setIndicativoDc(substr($linha, 319, 1))  | 
            ||
| 138 | ->setIndicadorValor(substr($linha, 320, 1))  | 
            ||
| 139 | ->setValorAjuste($this->formataNumero(substr($linha, 321, 12)))  | 
            ||
| 140 | ->setSequencial(substr($linha, 395, 6))  | 
            ||
| 141 | ->setMotivoCodOcorrencia(substr($linha, 319, 10))  | 
            ||
| 142 | ->setNumCartorio(substr($linha, 369, 2))  | 
            ||
| 143 | ->setNumCartorio(substr($linha, 369, 2))  | 
            ||
| 144 | ->setNumCartorio(substr($linha, 369, 2))  | 
            ||
| 145 | ;  | 
            ||
| 146 | |||
| 147 | return $detail;  | 
            ||
| 148 | }  | 
            ||
| 149 | |||
| 155 | 
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: