| Conditions | 10 | 
| Paths | 5 | 
| Total Lines | 34 | 
| Code Lines | 26 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 1 | ||
| 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 | ||
| 77 | public function isFollowDenmarkRule(string $tin) | ||
| 78 |     { | ||
| 79 | $serialNumber = intval(StringUtil::substring($tin, 6, 10)); | ||
| 80 | $dayOfBirth = intval(StringUtil::substring($tin, 0, 2)); | ||
| 81 | $monthOfBirth = intval(StringUtil::substring($tin, 2, 4)); | ||
| 82 | $yearOfBirth = intval(StringUtil::substring($tin, 4, 6)); | ||
| 83 |         if ($yearOfBirth >= 37 && $yearOfBirth <= 57 && $serialNumber >= 5000 && $serialNumber <= 8999) { | ||
| 84 | return false; | ||
| 85 | } | ||
| 86 | |||
| 87 | $excludedYears = [60, 64, 65, 66, 69, 70, 74, 80, 82, 84, 85, 86, 87, 88, 89, 90, 91, 92]; | ||
| 88 |         if ($dayOfBirth == 1 && $monthOfBirth == 1 && in_array($yearOfBirth, $excludedYears)) { | ||
| 89 | return true; | ||
| 90 | } | ||
| 91 | |||
| 92 | $c1 = StringUtil::digitAt($tin, 0); | ||
| 93 | $c2 = StringUtil::digitAt($tin, 1); | ||
| 94 | $c3 = StringUtil::digitAt($tin, 2); | ||
| 95 | $c4 = StringUtil::digitAt($tin, 3); | ||
| 96 | $c5 = StringUtil::digitAt($tin, 4); | ||
| 97 | $c6 = StringUtil::digitAt($tin, 5); | ||
| 98 | $c7 = StringUtil::digitAt($tin, 6); | ||
| 99 | $c8 = StringUtil::digitAt($tin, 7); | ||
| 100 | $c9 = StringUtil::digitAt($tin, 8); | ||
| 101 | $c10 = StringUtil::digitAt($tin, 9); | ||
| 102 | $sum = $c1 * 4 + $c2 * 3 + $c3 * 2 + $c4 * 7 + $c5 * 6 + $c6 * 5 + $c7 * 4 + $c8 * 3 + $c9 * 2; | ||
| 103 | $remainderBy11 = $sum % 11; | ||
| 104 |         if ($remainderBy11 == 1) { | ||
| 105 | return false; | ||
| 106 | } | ||
| 107 |         if ($remainderBy11 == 0) { | ||
| 108 | return $c10 == 0; | ||
| 109 | } | ||
| 110 | return $c10 == 11 - $remainderBy11; | ||
| 111 | } | ||
| 121 |