Passed
Push — master ( 8dceab...2d1996 )
by Benjamin
12:28
created

JsonEncoder::detectAndCleanUtf8()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

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