Passed
Push — master ( 976aad...1511ac )
by Aleksandr
01:47
created

RequestLoggerMiddleware   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 43
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 3 1
A saveLog() 0 4 1
A terminate() 0 4 1
A stopBenchmark() 0 5 1
1
<?php
2
3
namespace San4io\RequestLogger\Middleware;
4
5
use Closure;
6
use San4io\RequestLogger\Jobs\LoggingJob;
7
use San4io\RequestLogger\Services\BenchmarkService;
8
use Symfony\Component\HttpFoundation\Request;
9
use Symfony\Component\HttpFoundation\Response;
10
use Symfony\Component\HttpKernel\TerminableInterface;
11
12
class RequestLoggerMiddleware implements TerminableInterface
13
{
14
    /**
15
     * Run the request filter.
16
     *
17
     * @param \Illuminate\Http\Request $request
18
     * @param \Closure                 $next
19
     *
20
     * @return mixed
21
     */
22
    public function handle($request, Closure $next)
23
    {
24
        return $next($request);
25
    }
26
27
    /**
28
     * @param \Illuminate\Http\Request $request
29
     * @param \Illuminate\Http\Response $response
30
     */
31
    public function terminate(Request $request, Response $response)
32
    {
33
        $this->stopBenchmark();
34
        $this->saveLog($request, $response);
35
    }
36
37
    /**
38
     *
39
     */
40
    protected function stopBenchmark()
41
    {
42
        /** @var BenchmarkService $application */
43
        $application = app('app.services.benchmark.application');
0 ignored issues
show
Bug introduced by
The function app was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

43
        $application = /** @scrutinizer ignore-call */ app('app.services.benchmark.application');
Loading history...
44
        $application->stop();
45
    }
46
47
    /**
48
     * @param Request $request
49
     * @param Response $response
50
     */
51
    protected function saveLog(Request $request, Response $response): void
52
    {
53
        $job = new LoggingJob($request, $response);
54
        $job->handle();
55
    }
56
}
57