JsonWriter::closeWriter()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
/*
4
 * This file is part of the 2amigos/yii2-exportable-widget project.
5
 * (c) 2amigOS! <http://2amigos.us/>
6
 * For the full copyright and license information, please view
7
 * the LICENSE file that was distributed with this source code.
8
 */
9
10
namespace dosamigos\exportable\writers;
11
12
use Box\Spout\Writer\AbstractWriter;
13
14
class JsonWriter extends AbstractWriter
15
{
16
    /**
17
     * @var int current position
18
     */
19
    protected $position;
20
    /**
21
     * @var string Content-Type value for the header
22
     */
23
    protected static $headerContentType = 'application/json';
24
25
    /**
26
     * @inheritdoc
27
     */
28
    protected function openWriter()
29
    {
30
        fwrite($this->filePointer, '[');
31
    }
32
33
    /**
34
     * @inheritdoc
35
     */
36
    protected function addRowToWriter(array $dataRow, $style)
37
    {
38
        fwrite($this->filePointer, ($this->position > 0 ? ',' : '') . json_encode($dataRow));
39
40
        ++$this->position;
41
    }
42
43
    /**
44
     * @inheritdoc
45
     */
46
    protected function closeWriter()
47
    {
48
        fwrite($this->filePointer, ']');
49
    }
50
}
51