Encoder::emit()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
namespace Networkteam\JsonSeq;
3
4
class Encoder
5
{
6
7
    const RS = "\x1E";
8
    const LF = "\x0A";
9
10
    /**
11
     * @var WriterInterface
12
     */
13
    private $writer;
14
15
    /**
16
     * @var int
17
     */
18
    private $jsonEncodeOptions;
19
20
    /**
21
     * @var int
22
     */
23
    private $jsonEncodeDepth;
24
25 2
    public function __construct(WriterInterface $writer, int $options = 0, int $depth = 512)
26
    {
27 2
        $this->writer = $writer;
28 2
        $this->jsonEncodeOptions = $options;
29 2
        $this->jsonEncodeDepth = $depth;
30 2
    }
31
32 1
    public function emit($data): void
33
    {
34 1
        $jsonText = json_encode($data, $this->jsonEncodeOptions, $this->jsonEncodeDepth);
35 1
        $this->writer->write(self::RS . $jsonText . self::LF);
36
    }
37
}