Passed
Pull Request — master (#128)
by Alexandre
06:02
created

KeepAliveRetryTransportWrapper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 46
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A send() 0 9 3
A getTransport() 0 3 1
1
<?php
2
3
namespace Gelf\Transport;
4
5
use Gelf\MessageInterface as Message;
6
7
class KeepAliveRetryTransportWrapper extends AbstractTransport
8
{
9
    /**
10
     * @const string
11
     */
12
    const NO_RESPONSE = "Graylog-Server didn't answer properly, expected 'HTTP/1.x 202 Accepted', response is ''";
13
14
    /**
15
     * @var HttpTransport
16
     */
17
    protected $transport;
18
19
    /**
20
     * KeepAliveRetryTransportWrapper constructor.
21
     *
22
     * @param HttpTransport $transport
23
     */
24
    public function __construct(HttpTransport $transport)
25
    {
26
        $this->transport = $transport;
27
    }
28
29
    /**
30
     * @return HttpTransport
31
     */
32
    public function getTransport()
33
    {
34
        return $this->transport;
35
    }
36
37
    /**
38
     * Sends a Message over this transport.
39
     *
40
     * @param Message $message
41
     *
42
     * @return int calls function to send message
43
     */
44
    public function send(Message $message)
45
    {
46
        try {
47
            return $this->transport->send($message);
48
        } catch (\RuntimeException $e) {
49
            if ($e->getMessage() !== self::NO_RESPONSE) {
50
                throw $e;
51
            }
52
            return $this->transport->send($message);
53
        }
54
    }
55
}
56