Passed
Push — master ( 46729e...9da378 )
by Benjamin
03:05 queued 01:09
created

IgnoreErrorTransportWrapper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 47
ccs 10
cts 10
cp 1
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getLastError() 0 3 1
A send() 0 7 2
A __construct() 0 3 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