JsonWriter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 37
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A openWriter() 0 4 1
A addRowToWriter() 0 6 2
A closeWriter() 0 4 1
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