| Conditions | 14 |
| Paths | 115 |
| Total Lines | 39 |
| 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 |
||
| 85 | public function isFollowPattern2(string $tin) |
||
| 86 | { |
||
| 87 | if (!StringUtil::isFollowPattern($tin, self::PATTERN_2)) { |
||
| 88 | return false; |
||
| 89 | } |
||
| 90 | $tab = []; |
||
| 91 | $pos = []; |
||
| 92 | for ($i = 0; $i < 10; $i++) { |
||
| 93 | $tab[$i] = StringUtil::digitAt($tin, $i); |
||
| 94 | $pos[$i] = 0; |
||
| 95 | } |
||
| 96 | for ($i = 0; $i < 8; $i++) { |
||
| 97 | if ($tab[$i] == $tab[$i + 1] && $tab[$i + 1] == $tab[$i + 2]) { |
||
| 98 | return false; |
||
| 99 | } |
||
| 100 | } |
||
| 101 | for ($j = 0; $j < 10; $j++) { |
||
| 102 | $pos[$tab[$j]]++; |
||
| 103 | } |
||
| 104 | $isEncounteredTwice2 = false; |
||
| 105 | $isEncounteredThrice3 = false; |
||
| 106 | for ($k = 0; $k < 10; $k++) { |
||
| 107 | if ($pos[$k] > 3) { |
||
| 108 | return false; |
||
| 109 | } |
||
| 110 | if ($pos[$k] == 3) { |
||
| 111 | if ($isEncounteredThrice3) { |
||
| 112 | return false; |
||
| 113 | } |
||
| 114 | $isEncounteredThrice3 = true; |
||
| 115 | } |
||
| 116 | if ($pos[$k] == 2) { |
||
| 117 | if ($isEncounteredTwice2) { |
||
| 118 | return false; |
||
| 119 | } |
||
| 120 | $isEncounteredTwice2 = true; |
||
| 121 | } |
||
| 122 | } |
||
| 123 | return $isEncounteredThrice3 || $isEncounteredTwice2; |
||
| 124 | } |
||
| 188 |