Completed
Push — master ( 6428d8...2f66fb )
by Greg
03:32
created

TsvFormatter::writeOneLine()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 3
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 writeOneLine(OutputInterface $output, $data, $options)
21
    {
22
        $output->writeln($this->tsvEscape($data));
23
    }
24
25
    protected function tsvEscape($data)
26
    {
27
        return implode("\t", array_map(
28
            function ($item) {
29
                return str_replace(["\t", "\n"], ['\t', '\n'], $item);
30
            },
31
            $data
32
        ));
33
    }
34
}
35