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 |
||
| 35 | 33 | public function validate($input): bool |
|
| 36 | { |
||
| 37 | 33 | if (!is_scalar($input)) { |
|
| 38 | return false; |
||
| 39 | } |
||
| 40 | |||
| 41 | // Code ported from jsfromhell.com |
||
| 42 | 33 | $cleanInput = preg_replace('/\D/', '', $input); |
|
| 43 | 33 | $b = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]; |
|
| 44 | |||
| 45 | 33 | if ($cleanInput < 1) { |
|
| 46 | 2 | return false; |
|
| 47 | } |
||
| 48 | |||
| 49 | 32 | if (14 != mb_strlen($cleanInput)) { |
|
| 50 | 5 | return false; |
|
| 51 | } |
||
| 52 | |||
| 53 | 27 | $n = 0; |
|
| 54 | 27 | for ($i = 0; $i < 12; ++$i) { |
|
| 55 | 27 | $n += $cleanInput[$i] * $b[$i+1]; |
|
| 56 | } |
||
| 57 | |||
| 58 | 27 | if ($cleanInput[12] != ((($n %= 11) < 2) ? 0 : 11 - $n)) { |
|
| 59 | 14 | return false; |
|
| 60 | } |
||
| 61 | |||
| 62 | 13 | $n = 0; |
|
| 63 | 13 | for ($i = 0; $i <= 12; ++$i) { |
|
| 64 | 13 | $n += $cleanInput[$i] * $b[$i]; |
|
| 65 | } |
||
| 66 | |||
| 67 | 13 | if ($cleanInput[13] != ((($n %= 11) < 2) ? 0 : 11 - $n)) { |
|
| 68 | 1 | return false; |
|
| 69 | } |
||
| 70 | |||
| 71 | 12 | return true; |
|
| 72 | } |
||
| 74 |