IgnoreErrorTransportWrapper   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A send() 0 7 2
A getLastError() 0 3 1
A __construct() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Gelf\Transport;
5
6
use Gelf\MessageInterface as Message;
7
use Throwable;
8
9
/**
10
 * A wrapper for any AbstractTransport to ignore any kind of errors
11
 * @package Gelf\Transport
12
 */
13
class IgnoreErrorTransportWrapper implements TransportInterface
14
{
15
    private ?Throwable $lastError = null;
16
17
    public function __construct(
18
        private TransportInterface $transport
19
    ) {
20
    }
21
22
    /**
23
     * @inheritDoc
24
     */
25
    public function send(Message $message): int
26
    {
27
        try {
28
            return $this->transport->send($message);
29 1
        } catch (Throwable $e) {
30
            $this->lastError = $e;
31 1
            return 0;
32 1
        }
33
    }
34
35
    /**
36
     * Returns the last error
37
     */
38
    public function getLastError(): ?Throwable
39
    {
40
        return $this->lastError;
41 1
    }
42
}
43