Passed
Push — master ( 2ae7fe...46729e )
by Benjamin
07:20 queued 05:43
created

IgnoreErrorTransportWrapper::getLastError()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
3
namespace Gelf\Transport;
4
5
use Gelf\MessageInterface as Message;
6
7
/**
8
 * A wrapper for any AbstractTransport to ignore any kind of errors
9
 * @package Gelf\Transport
10
 */
11
class IgnoreErrorTransportWrapper extends AbstractTransport
12
{
13
14
    /**
15
     * @var AbstractTransport
16
     */
17
    private $transport;
18
19
    /**
20
     * @var \Exception|null
21
     */
22
    private $lastError = null;
23
24
    /**
25
     * IgnoreErrorTransportWrapper constructor.
26
     *
27
     * @param AbstractTransport $transport
28
     */
29
    public function __construct(AbstractTransport $transport)
30
    {
31
        $this->transport = $transport;
32
    }
33
34
    /**
35
     * Sends a Message over this transport.
36
     *
37
     * @param Message $message
38
     *
39
     * @return int the number of bytes sent
40
     */
41
    public function send(Message $message)
42
    {
43
        try {
44
            return $this->transport->send($message);
45
        } catch (\Exception $e) {
46
            $this->lastError = $e;
47
            return 0;
48
        }
49
    }
50
51
    /**
52
     * Returns the last error
53
     * @return \Exception|null
54
     */
55
    public function getLastError()
56
    {
57
        return $this->lastError;
58
    }
59
}
60