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