LogAfterRequest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 5
c 2
b 0
f 1
lcom 0
cbo 0
dl 0
loc 34
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 4 1
A terminate() 0 18 3
A shouldLogRequest() 0 4 1
1
<?php
2
3
namespace LaravelRequest\Middleware;
4
5
use Closure;
6
use Illuminate\Support\Facades\Lang;
7
8
class LogAfterRequest
9
{
10
    public function handle($request, Closure $next)
11
    {
12
        return $next($request);
13
    }
14
15
    public function terminate($request, $response)
16
    {
17
        if ($this->shouldLogRequest($request, $response)) {
18
            $request_model_name = config('laravel-request.model');
19
            $request_model = new $request_model_name();
20
            $request_model->response = $response->getStatusCode();
21
            $request_model->method = $request->getMethod();
22
            $request_model->path = $request->getUri();
23
            $request_model->is_secure = $request->isSecure();
24
            $request_model->is_ajax = $request->ajax();
25
            $request_model->ip = $request->getClientIp();
26
            $request_model->user_id = $request->user() ? $request->user()->id : null;
27
            $request_model->referer = $request->server('HTTP_REFERER');
28
            $request_model->user_agent = $request->server('HTTP_USER_AGENT');
29
            $request_model->language = Lang::getLocale();
30
            $request_model->save();
31
        }
32
    }
33
34
    /**
35
     * @return bool
36
     */
37
    protected function shouldLogRequest($request, $response)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $response is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
38
    {
39
        return true;
40
    }
41
}
42