Completed
Push — master ( 2f66fb...4eb816 )
by Greg
02:33
created

TsvFormatter::getDefaultFormatterOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
namespace Consolidation\OutputFormatters\Formatters;
3
4
use Consolidation\OutputFormatters\FormatterInterface;
5
use Consolidation\OutputFormatters\ValidationInterface;
6
use Consolidation\OutputFormatters\FormatterOptions;
7
use Consolidation\OutputFormatters\Transformations\TableTransformation;
8
use Consolidation\OutputFormatters\Exception\IncompatibleDataException;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
/**
12
 * Tab-separated value formatters
13
 *
14
 * Display the provided structured data in a tab-separated list.  Output
15
 * escaping is much lighter, since there is no allowance for altering
16
 * the delimiter.
17
 */
18
class TsvFormatter extends CsvFormatter
19
{
20
    protected function getDefaultFormatterOptions()
21
    {
22
        return [
23
            FormatterOptions::INCLUDE_FIELD_LABELS => false,
24
        ];
25
    }
26
27
    protected function writeOneLine(OutputInterface $output, $data, $options)
28
    {
29
        $output->writeln($this->tsvEscape($data));
30
    }
31
32
    protected function tsvEscape($data)
33
    {
34
        return implode("\t", array_map(
35
            function ($item) {
36
                return str_replace(["\t", "\n"], ['\t', '\n'], $item);
37
            },
38
            $data
39
        ));
40
    }
41
}
42