Completed
Push — master ( 66e423...45459e )
by Joel
08:39
created

LogCommand::hasResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace RedirectionIO\Client\Sdk\Command;
4
5
use RedirectionIO\Client\Sdk\HttpMessage\Request;
6
use RedirectionIO\Client\Sdk\HttpMessage\Response;
7
8
/**
9
 * Log a request and a response to be used in analysis on redirection io manager
10
 */
11
class LogCommand implements CommandInterface
12
{
13
    private $request;
14
15
    private $response;
16
17
    public function __construct(Request $request, Response $response)
18
    {
19
        $this->request = $request;
20
        $this->response = $response;
21
    }
22
23
    public function getName()
24
    {
25
        return 'LOG';
26
    }
27
28
    public function getRequest()
29
    {
30
        $data = [
31
            'status_code' => $this->response->getStatusCode(),
32
            'host' => $this->request->getHost(),
33
            'request_uri' => $this->request->getPath(),
34
            'user_agent' => $this->request->getUserAgent(),
35
            'referer' => $this->request->getReferer(),
36
            'scheme' => $this->request->getScheme(),
37
            'use_json' => true,
38
        ];
39
40
        if ($this->response->getLocation()) {
41
            $data['target'] = $this->response->getLocation();
42
        }
43
44
        if ($this->response->getRuleId()) {
45
            $data['rule_id'] = $this->response->getRuleId();
46
        }
47
48
        return json_encode($data);
49
    }
50
51
    public function hasResponse()
52
    {
53
        return false;
54
    }
55
56
    public function parseResponse($response)
57
    {
58
        return null;
59
    }
60
}
61