We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 10 |
Paths | 13 |
Total Lines | 32 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Tests | 15 |
CRAP Score | 10.0244 |
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 |
||
16 | 32 | public function validate($input) |
|
17 | { |
||
18 | 32 | if (!is_scalar($input)) { |
|
19 | return false; |
||
20 | } |
||
21 | |||
22 | // Code ported from jsfromhell.com |
||
23 | 32 | $cleanInput = preg_replace('/\D/', '', $input); |
|
24 | 32 | $b = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]; |
|
25 | |||
26 | 32 | if ($cleanInput < 1) { |
|
27 | 1 | return false; |
|
28 | } |
||
29 | |||
30 | 31 | if (mb_strlen($cleanInput) != 14) { |
|
31 | 5 | return false; |
|
32 | } |
||
33 | |||
34 | 26 | for ($i = 0, $n = 0; $i < 12; $n += $cleanInput[$i] * $b[++$i]); |
|
35 | |||
36 | 26 | if ($cleanInput[12] != ((($n %= 11) < 2) ? 0 : 11 - $n)) { |
|
37 | 14 | return false; |
|
38 | } |
||
39 | |||
40 | 12 | for ($i = 0, $n = 0; $i <= 12; $n += $cleanInput[$i] * $b[$i++]); |
|
41 | |||
42 | 12 | if ($cleanInput[13] != ((($n %= 11) < 2) ? 0 : 11 - $n)) { |
|
43 | 1 | return false; |
|
44 | } |
||
45 | |||
46 | 11 | return true; |
|
47 | } |
||
48 | } |
||
49 |