AbstractTransport::__construct()   A
last analyzed

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 1
dl 0
loc 3
rs 10
ccs 0
cts 0
cp 0
crap 2
1
<?php
2
declare(strict_types=1);
3
4
/*
5
 * This file is part of the php-gelf package.
6
 *
7
 * (c) Benjamin Zikarsky <http://benjamin-zikarsky.de>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace Gelf\Transport;
14
15
use Gelf\Encoder\EncoderInterface;
16
use Gelf\Encoder\JsonEncoder;
17
use Gelf\MessageInterface;
18
use Gelf\PublisherInterface;
19
20
/**
21
 * The CompressedJsonEncoder allows the encoding of GELF messages as described
22
 * in http://www.graylog2.org/resources/documentation/sending/gelfhttp
23
 *
24
 * @author Benjamin Zikarsky <[email protected]>
25
 */
26
abstract class AbstractTransport implements TransportInterface
27
{
28
    protected EncoderInterface $messageEncoder;
29
30
    public function __construct(?EncoderInterface $messageEncoder = null)
31
    {
32
        $this->messageEncoder = $messageEncoder ?? new JsonEncoder();
33
    }
34
35
    /**
36
     * Sets a message encoder
37
     */
38
    public function setMessageEncoder(EncoderInterface $encoder): static
39 29
    {
40
        $this->messageEncoder = $encoder;
41 29
42
        return $this;
43 29
    }
44
45
    /**
46
     * Returns the current message encoder
47
     */
48
    public function getMessageEncoder(): EncoderInterface
49
    {
50
        return $this->messageEncoder;
51 17
    }
52
}
53