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

HttpLogger   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 2
cbo 2
dl 0
loc 29
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A handle() 0 8 2
A terminate() 0 6 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