JsonEncoder   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A encode() 0 3 1
A jsonEncode() 0 3 1
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\Encoder;
14
15
use Gelf\MessageInterface;
16
17
/**
18
 * The JsonEncoder allows the encoding of GELF messages as described
19
 * in http://www.graylog2.org/resources/documentation/sending/gelfhttp
20
 *
21
 * @author Benjamin Zikarsky <[email protected]>
22
 */
23
class JsonEncoder implements NoNullByteEncoderInterface
24
{
25
    /**
26
     * @inheritDoc
27
     */
28
    public function encode(MessageInterface $message): string
29
    {
30
        return $this->jsonEncode($message->toArray());
31 3
    }
32
33 3
    private function jsonEncode(mixed $data): string
34
    {
35
        return json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR);
36
    }
37
}
38