Completed
Push — master ( 7c1eaa...80d841 )
by Joachim
15:53
created

HttpTransaction   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 4
dl 0
loc 95
c 0
b 0
f 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getIp() 0 4 1
A setIp() 0 6 1
A getRequest() 0 4 1
A setRequest() 0 22 3
A getResponse() 0 4 1
A setResponse() 0 6 1
1
<?php
2
3
namespace Loevgaard\DandomainAltapayBundle\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
6
use Knp\DoctrineBehaviors\Model as ORMBehaviors;
7
use Symfony\Component\HttpFoundation\Request;
8
9
/**
10
 * @ORM\MappedSuperclass
11
 */
12
abstract class HttpTransaction implements HttpTransactionInterface
13
{
14
    use ORMBehaviors\Timestampable\Timestampable;
15
16
    /**
17
     * @var string
18
     *
19
     * @ORM\Column(type="string", nullable=true)
20
     */
21
    protected $ip;
22
23
    /**
24
     * @var string
25
     *
26
     * @ORM\Column(type="text")
27
     */
28
    protected $request;
29
30
    /**
31
     * @var string
32
     *
33
     * @ORM\Column(type="text", nullable=true)
34
     */
35
    protected $response;
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function getIp(): string
41
    {
42
        return $this->ip;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function setIp(string $ip): HttpTransactionInterface
49
    {
50
        $this->ip = $ip;
51
52
        return $this;
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function getRequest(): string
59
    {
60
        return $this->request;
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    public function setRequest($request): HttpTransactionInterface
67
    {
68
        if ($request instanceof Request) {
69
            $this->ip = $request->getClientIp();
70
71
            $post = '';
72
73
            foreach ($request->request->all() as $key => $val) {
74
                $post .= '&'.$key.'='.$val."\r\n";
75
            }
76
            $post = trim($post, '&');
77
78
            $request = sprintf('%s %s %s',
79
                    $request->getMethod(),
80
                    $request->getRequestUri(),
81
                    $request->server->get('SERVER_PROTOCOL'))."\r\n".$request->headers."\r\n".$post;
82
        }
83
84
        $this->request = $request;
85
86
        return $this;
87
    }
88
89
    /**
90
     * {@inheritdoc}
91
     */
92
    public function getResponse(): string
93
    {
94
        return $this->response;
95
    }
96
97
    /**
98
     * {@inheritdoc}
99
     */
100
    public function setResponse(string $response): HttpTransactionInterface
101
    {
102
        $this->response = $response;
103
104
        return $this;
105
    }
106
}
107