Conditions | 11 |
Paths | 18 |
Total Lines | 48 |
Lines | 0 |
Ratio | 0 % |
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 |
||
22 | public function handle(Request $request, Closure $next): Response |
||
23 | { |
||
24 | if (! config('honeypot.enabled')) { |
||
25 | return $next($request); |
||
26 | } |
||
27 | |||
28 | if (! $request->isMethod('POST')) { |
||
29 | return $next($request); |
||
30 | } |
||
31 | |||
32 | $nameFieldName = config('honeypot.name_field_name'); |
||
33 | |||
34 | if (config('honeypot.randomize_name_field_name')) { |
||
35 | $nameFieldName = $this->getRandomizedNameFieldName($nameFieldName, $request->all()); |
||
36 | } |
||
37 | |||
38 | if (! $this->shouldCheckHoneypot($request, $nameFieldName)) { |
||
39 | return $next($request); |
||
40 | } |
||
41 | |||
42 | if (! $request->has($nameFieldName)) { |
||
43 | return $this->respondToSpam($request, $next); |
||
44 | } |
||
45 | |||
46 | $honeypotValue = $request->get($nameFieldName); |
||
47 | |||
48 | if (! empty($honeypotValue)) { |
||
49 | return $this->respondToSpam($request, $next); |
||
50 | } |
||
51 | |||
52 | $validFrom = $request->get(config('honeypot.valid_from_field_name')); |
||
53 | |||
54 | if (! $validFrom) { |
||
55 | return $this->respondToSpam($request, $next); |
||
56 | } |
||
57 | |||
58 | try { |
||
59 | $time = new EncryptedTime($validFrom); |
||
60 | } catch (Exception $decryptException) { |
||
61 | $time = null; |
||
62 | } |
||
63 | |||
64 | if (! $time || $time->isFuture()) { |
||
65 | return $this->respondToSpam($request, $next); |
||
66 | } |
||
67 | |||
68 | return $next($request); |
||
69 | } |
||
70 | |||
94 |