TsvFormatter::getDefaultFormatterOptions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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