Completed
Push — master ( cd9a78...bc1175 )
by Benjamin
02:08
created

IgnoreErrorTransportWrapper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
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 1
    public function __construct(AbstractTransport $transport)
30
    {
31 1
        $this->transport = $transport;
32 1
    }
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 1
    public function send(Message $message)
42
    {
43
        try {
44 1
            return $this->transport->send($message);
45 1
        } catch (\Exception $e) {
46 1
            $this->lastError = $e;
47 1
            return 0;
48
        }
49
    }
50
51
    /**
52
     * Returns the last error
53
     * @return \Exception|null
54
     */
55 1
    public function getLastError()
56
    {
57 1
        return $this->lastError;
58
    }
59
}
60