Test Failed
Push — master ( dd9cb8...6d15c1 )
by Emmanuel
04:44
created

CSVWriter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 69.23%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 23
ccs 9
cts 13
cp 0.6923
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A write() 0 15 2
1
<?php
2
/**
3
 * neuralyzer : Data Anonymization Library and CLI Tool
4
 *
5
 * PHP Version 7.1
6
 *
7
 * @author Emmanuel Dyan
8
 * @author Rémi Sauvat
9
 * @copyright 2018 Emmanuel Dyan
10
 *
11
 * @package edyan/neuralyzer
12
 *
13
 * @license GNU General Public License v2.0
14
 *
15
 * @link https://github.com/edyan/neuralyzer
16
 */
17
18
namespace Edyan\Neuralyzer\Utils;
19
20
use Doctrine\DBAL\Connection;
21
use Edyan\Neuralyzer\Exception\NeuralizerException;
22
23
/**
24
 * A few generic methods to help interacting with DB
25
 */
26
class CSVWriter extends \SplFileObject
27
{
28 1
    public function __construct()
29
    {
30 1
        parent::__construct(tempnam(sys_get_temp_dir(), 'neuralyzer'), 'w');
31 1
    }
32
33 1
    public function write(array $fields)
34
    {
35 1
        $options = $this->getCsvControl();
36 1
        $delimiter = $options[0];
37 1
        $enclosure = $options[1];
38 1
        if (!empty($enclosure)) {
39 1
            return $this->fputcsv($fields, $delimiter, $enclosure);
40
        }
41
42
        $fields = array_map(function ($field) use ($delimiter, $enclosure) {
43
            return str_replace([$delimiter, PHP_EOL, chr(10)], ['', '', ''], $field);
44
        }, $fields);
45
46
        return $this->fwrite(implode($delimiter, $fields) . chr(10));
47
    }
48
}
49