JsonEncoder::jsonEncode()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

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