Encoder   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 34
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A emit() 0 5 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
}