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 | 37 |
Code Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Tests | 19 |
CRAP Score | 10.0125 |
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 |
||
37 | 33 | public function validate($input): bool |
|
38 | { |
||
39 | 33 | if (!is_scalar($input)) { |
|
40 | return false; |
||
41 | } |
||
42 | |||
43 | // Code ported from jsfromhell.com |
||
44 | 33 | $bases = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]; |
|
45 | 33 | $digits = $this->getDigits((string) $input); |
|
46 | |||
47 | 33 | if (array_sum($digits) < 1) { |
|
48 | 2 | return false; |
|
49 | } |
||
50 | |||
51 | 32 | if (14 !== count($digits)) { |
|
52 | 5 | return false; |
|
53 | } |
||
54 | |||
55 | 27 | $n = 0; |
|
56 | 27 | for ($i = 0; $i < 12; ++$i) { |
|
57 | 27 | $n += $digits[$i] * $bases[$i+1]; |
|
58 | } |
||
59 | |||
60 | 27 | if ($digits[12] != ((($n %= 11) < 2) ? 0 : 11 - $n)) { |
|
61 | 14 | return false; |
|
62 | } |
||
63 | |||
64 | 13 | $n = 0; |
|
65 | 13 | for ($i = 0; $i <= 12; ++$i) { |
|
66 | 13 | $n += $digits[$i] * $bases[$i]; |
|
67 | } |
||
68 | |||
69 | 13 | if ($digits[13] != ((($n %= 11) < 2) ? 0 : 11 - $n)) { |
|
70 | 1 | return false; |
|
71 | } |
||
72 | |||
73 | 12 | return true; |
|
74 | } |
||
89 |