Passed
Push — master ( 3581f7...005bcc )
by De Cramer
05:10 queued 03:31
created

Json::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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