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