| Conditions | 10 |
| Paths | 64 |
| Total Lines | 45 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 110 |
| Changes | 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 |
||
| 19 | public static function isValid($var) |
||
| 20 | { |
||
| 21 | $paddedInsc = str_pad($var, 12, "0", STR_PAD_LEFT); |
||
| 22 | |||
| 23 | $dig1 = 0; |
||
|
|
|||
| 24 | $dig2 = 0; |
||
| 25 | $tam = strlen($paddedInsc); |
||
| 26 | $digitos = substr($paddedInsc, $tam - 2, 2); |
||
| 27 | $estado = substr($paddedInsc, $tam - 4, 2); |
||
| 28 | $titulo = substr($paddedInsc, 0, $tam - 2); |
||
| 29 | $exce = ($estado == '01') || ($estado == '02'); |
||
| 30 | $dig1 = (ord($titulo[0]) - 48) * 9 + (ord($titulo[1]) - 48) * 8 + (ord($titulo[2]) - 48) * 7 + (ord($titulo[3]) - 48) * 6 + (ord($titulo[4]) - 48) * 5 + (ord($titulo[5]) - 48) * 4 + (ord($titulo[6]) - 48) * 3 + (ord($titulo[7]) - 48) * 2; |
||
| 31 | $resto = ($dig1 % 11); |
||
| 32 | if ($resto == 0) { |
||
| 33 | if ($exce) { |
||
| 34 | $dig1 = 1; |
||
| 35 | } else { |
||
| 36 | $dig1 = 0; |
||
| 37 | } |
||
| 38 | } else { |
||
| 39 | if ($resto == 1) { |
||
| 40 | $dig1 = 0; |
||
| 41 | } else { |
||
| 42 | $dig1 = 11 - $resto; |
||
| 43 | } |
||
| 44 | } |
||
| 45 | $dig2 = (ord($titulo[8]) - 48) * 4 + (ord($titulo[9]) - 48) * 3 + $dig1 * 2; |
||
| 46 | $resto = ($dig2 % 11); |
||
| 47 | if ($resto == 0) { |
||
| 48 | if ($exce) { |
||
| 49 | $dig2 = 1; |
||
| 50 | } else { |
||
| 51 | $dig2 = 0; |
||
| 52 | } |
||
| 53 | } else { |
||
| 54 | if ($resto == 1) { |
||
| 55 | $dig2 = 0; |
||
| 56 | } else { |
||
| 57 | $dig2 = 11 - $resto; |
||
| 58 | } |
||
| 59 | } |
||
| 60 | if ((ord($digitos[0]) - 48 == $dig1) && (ord($digitos[1]) - 48 == $dig2)) { |
||
| 61 | return true; |
||
| 62 | } else { |
||
| 63 | return false; |
||
| 64 | } |
||
| 77 |