Completed
Push — wip-platform ( 1036f7...1dee5f )
by
unknown
06:03
created

BaseWriter   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 38
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 9 2
A open() 0 4 1
A close() 0 4 1
A _write() 0 5 2
1
<?php
2
3
/*
4
 * This file is part of the Blast Project package.
5
 *
6
 * Copyright (C) 2015-2017 Libre Informatique
7
 *
8
 * This file is licenced under the GNU LGPL v3.
9
 * For the full copyright and license information, please view the LICENSE.md
10
 * file that was distributed with this source code.
11
 */
12
13
namespace Blast\Bundle\CoreBundle\Admin;
14
15
use Exporter\Writer\WriterInterface;
16
17
abstract class BaseWriter implements WriterInterface
18
{
19
    protected $filename;
20
    protected $file;
21
    protected $position;
22
23
    public function configure($filename)
24
    {
25
        $this->filename = $filename;
26
        $this->position = 0;
27
28
        if (is_file($filename)) {
29
            throw new \RuntimeException(sprintf('The file %s already exist', $filename));
30
        }
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function open()
37
    {
38
        $this->file = fopen($this->filename, 'w', false);
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function close()
45
    {
46
        fclose($this->file);
47
    }
48
49
    protected function _write($data, $separator = "\n")
50
    {
51
        fwrite($this->file, ($this->position > 0 ? $separator : '') . $data);
52
        ++$this->position;
53
    }
54
}
55