Completed
Pull Request — master (#31)
by Gerardo
01:09
created

HttpLogger::terminate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
namespace Spatie\HttpLogger\Middlewares;
4
5
use Closure;
6
use Illuminate\Http\Request;
7
use Spatie\HttpLogger\LogProfile;
8
use Spatie\HttpLogger\LogResponseProfile;
9
use Spatie\HttpLogger\LogResponseWriter;
10
use Spatie\HttpLogger\LogWriter;
11
use Symfony\Component\HttpFoundation\Response;
12
13
class HttpLogger
14
{
15
    protected $logProfile;
16
    protected $logWriter;
17
18
    public function __construct(LogProfile $logProfile, LogWriter $logWriter, logResponseProfile $logResponseProfile, logResponseWriter $logResponseWriter)
19
    {
20
        $this->logProfile = $logProfile;
21
        $this->logWriter = $logWriter;
22
        $this->logResponseProfile = $logResponseProfile;
0 ignored issues
show
Bug introduced by
The property logResponseProfile does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
23
        $this->logResponseWriter = $logResponseWriter;
0 ignored issues
show
Bug introduced by
The property logResponseWriter does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
24
    }
25
26
    public function handle(Request $request, Closure $next)
27
    {
28
        if ($this->logProfile->shouldLogRequest($request)) {
29
            $this->logWriter->logRequest($request);
30
        }
31
32
        return $next($request);
33
    }
34
35
    public function terminate(Request $request, Response $response)
36
    {
37
        if ($this->logResponseProfile->shouldLogResponse($request, $response)) {
38
            $this->logResponseWriter->logResponse($request, $response);
39
        }
40
    }
41
}
42