Completed
Push — master ( e93f60...2f787f )
by Mahmoud
08:56 queued 02:41
created

RequestsMonitorMiddleware::handle()   B

Complexity

Conditions 7
Paths 9

Size

Total Lines 52
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 52
rs 7.2396
cc 7
eloc 26
nc 9
nop 2

How to fix   Long Method   

Long Method

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:

1
<?php
2
3
namespace App\Containers\Debugger\Middlewares;
4
5
use App;
6
use Closure;
7
use Config;
8
use Illuminate\Http\Request;
9
use Log;
10
11
/**
12
 * Class RequestsMonitorMiddleware
13
 *
14
 * @author  Mahmoud Zalt  <[email protected]>
15
 */
16
class RequestsMonitorMiddleware
17
{
18
19
    /**
20
     * @param \Illuminate\Http\Request $request
21
     * @param \Closure                 $next
22
     *
23
     * @return  mixed
24
     */
25
    public function handle(Request $request, Closure $next)
26
    {
27
28
        $response = $next($request);
29
30
        if (App::environment() != 'testing' && Config::get('app.debug') === true) {
31
32
            Log::debug('');
33
            Log::debug('');
34
            Log::debug('REQUEST START------------------------------------------------------');
35
36
            // Endpoint URL:
37
            Log::debug('URL: ' . $request->getMethod() . ' ' . $request->fullUrl());
38
39
            // Request Device IP:
40
            Log::debug('IP: ' . $request->ip());
41
42
            // Request Headers:
43
            Log::debug('App Headers: ');
44
            Log::debug('   Authorization = ' . substr($request->header('Authorization'), 0, 80) . '...');
45
            Log::debug('   Visitor-Id = ' . $request->header('Visitor-Id'));
46
47
            // Request Data:
48
            if ($request->all()) {
49
                $data = http_build_query($request->all(), '', ' ; ');
50
            } else {
51
                $data = 'N/A';
52
            }
53
            Log::debug('Request Data: ' . $data);
54
55
            // Authenticated User:
56
            if ($request->user()) {
57
                $user = 'ID: ' . $request->user()->id;
58
            } else {
59
                $user = 'N/A';
60
            }
61
            Log::debug('Authenticated User: ' . $user);
62
63
            // Response Content:
64
            if ($response && method_exists($response, 'content')) {
65
                Log::debug('Response: ' . substr($response->content(), 0, 700) . '...');
66
            }
67
68
            Log::debug('');
69
            Log::debug('');
70
71
        }
72
73
        // Perform action
74
75
        return $response;
76
    }
77
}
78