IgnoreErrorTransportWrapper::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
ccs 0
cts 0
cp 0
crap 2
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