Completed
Pull Request — master (#20)
by Greg
02:41
created

StringFormatter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 0
cbo 1
dl 0
loc 31
ccs 5
cts 5
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A write() 0 6 2
A validDataTypes() 0 4 1
A validate() 0 4 1
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