Conditions | 11 |
Paths | 10 |
Total Lines | 29 |
Code Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
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 |
||
21 | public function rule($attribute, $value, $parameters, $validator): bool |
||
22 | { |
||
23 | $ibanReplaceValues = []; |
||
24 | |||
25 | if (empty($value)) { |
||
26 | return false; |
||
27 | } |
||
28 | |||
29 | $value = preg_replace('/[\W_]+/', '', strtoupper($value)); |
||
30 | if ((4 > strlen($value) || strlen($value) > 34) || (is_numeric($value[0]) || is_numeric($value[1])) || (! is_numeric($value[2]) || ! is_numeric($value[3]))) { |
||
31 | return false; |
||
32 | } |
||
33 | $ibanReplaceChars = range('A', 'Z'); |
||
34 | foreach (range(10, 35) as $tempvalue) { |
||
35 | $ibanReplaceValues[] = strval($tempvalue); |
||
36 | } |
||
37 | $tmpIBAN = substr($value, 4).substr($value, 0, 4); |
||
38 | $tmpIBAN = str_replace($ibanReplaceChars, $ibanReplaceValues, $tmpIBAN); |
||
39 | $tmpValue = intval(substr($tmpIBAN, 0, 1)); |
||
40 | for ($i = 1; $i < strlen($tmpIBAN); $i++) { |
||
41 | $tmpValue *= 10; |
||
42 | $tmpValue += intval(substr($tmpIBAN, $i, 1)); |
||
43 | $tmpValue %= 97; |
||
44 | } |
||
45 | if ($tmpValue != 1) { |
||
46 | return false; |
||
47 | } |
||
48 | |||
49 | return true; |
||
50 | } |
||
52 |