Completed
Push — master ( d1c093...e91f39 )
by Nick
05:04
created

LogAfterRequest::shouldLogRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 2
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