Passed
Pull Request — master (#21)
by De Cramer
07:15
created

Json   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 28
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getResource() 0 3 1
A __construct() 0 3 1
A init() 0 4 2
A write() 0 4 1
1
<?php
2
3
namespace Oliverde8\Component\PhpEtl\Load\File;
4
5
class Json implements FileWriterInterface
6
{
7
    protected string $filePath;
8
9
    /** @var resource File pointer */
10
    protected $file = null;
11
12
    public function __construct(string $filePath)
13
    {
14
        $this->filePath = $filePath;
15
    }
16
17
    protected function init()
18
    {
19
        if (is_null($this->file)) {
0 ignored issues
show
introduced by
The condition is_null($this->file) is always false.
Loading history...
20
            $this->file = fopen($this->filePath, 'w');
21
        }
22
    }
23
24
    public function write($rowData)
25
    {
26
        $this->init();
27
        fputs($this->file, json_encode($rowData) . "\n");
28
    }
29
30
    public function getResource()
31
    {
32
        return $this->file;
33
    }
34
}
35