Conditions | 10 |
Paths | 11 |
Total Lines | 38 |
Code Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
125 | function valid_cnp($cnp) |
||
126 | { |
||
127 | $const = '279146358279'; |
||
128 | $cnp = trim($cnp); |
||
129 | |||
130 | preg_match("|^([1256])(\d{2})(\d{2})(\d{2})(\d{6})$|ims", $cnp, $results); |
||
131 | if (count($results) < 1) { |
||
132 | return false; |
||
133 | } |
||
134 | |||
135 | $mf = $results[1] + 0; |
||
136 | if (5 == $mf || 6 == $mf) { |
||
137 | $year_add = 2000; |
||
138 | } else { |
||
139 | $year_add = 1900; |
||
140 | } |
||
141 | $year = $year_add + $results[2]; |
||
142 | $month = $results[3] + 0; |
||
143 | $day = $results[4] + 0; |
||
144 | |||
145 | if (!checkdate($month, $day, $year)) { |
||
146 | return false; |
||
147 | } |
||
148 | |||
149 | $suma = 0; |
||
150 | for ($i = 0; $i < 12; ++$i) { |
||
151 | $suma += $const[$i] * $cnp[$i]; |
||
152 | } |
||
153 | |||
154 | $rest = $suma % 11; |
||
155 | |||
156 | $c13 = $cnp[12] + 0; |
||
157 | |||
158 | if (!(($rest < 10 && $rest == $c13) || (10 == $rest && 1 == $c13))) { |
||
159 | return false; |
||
160 | } |
||
161 | |||
162 | return true; |
||
163 | } |
||
164 |