Completed
Push — master ( 3c952e...cb21a4 )
by Greg
11s
created

StringFormatter::write()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
cc 2
eloc 3
nc 2
nop 3
crap 2
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 Symfony\Component\Console\Output\OutputInterface;
8
9
/**
10
 * String formatter
11
 *
12
 * This formatter is used as the default action when no
13
 * particular formatter is requested.  It will print the
14
 * provided data only if it is a string; if any other
15
 * type is given, then nothing is printed.
16
 */
17
class StringFormatter implements FormatterInterface, ValidationInterface
18
{
19
    /**
20 1
     * @inheritdoc
21
     */
22 1
    public function write(OutputInterface $output, $data, FormatterOptions $options)
23 1
    {
24 1
        if (is_string($data)) {
25 1
            $output->writeln($data);
26
        }
27
    }
28
29
    /**
30
     * Do not return any valid data types -- this formatter will never show up
31
     * in a list of valid formats.
32
     */
33
    public function validDataTypes()
34
    {
35
        return [];
36
    }
37
38
    /**
39
     * Always validate any data, though. This format will never
40
     * cause an error if it is selected for an incompatible data type; at
41
     * worse, it simply does not print any data.
42
     */
43
    public function validate($structuredData)
44
    {
45
        return $structuredData;
46
    }
47
}
48