Completed
Pull Request — master (#65)
by
unknown
05:26
created

VarDumpFormatter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 4
dl 0
loc 20
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A write() 0 14 2
1
<?php
2
3
namespace Consolidation\OutputFormatters\Formatters;
4
5
use Consolidation\OutputFormatters\Options\FormatterOptions;
6
use Symfony\Component\Console\Output\OutputInterface;
7
use Symfony\Component\Console\Output\StreamOutput;
8
use Symfony\Component\VarDumper\Cloner\VarCloner;
9
use Symfony\Component\VarDumper\Dumper\CliDumper;
10
11
/**
12
 * Var_dump formatter
13
 *
14
 * Run provided data through Symfony VarDumper component.
15
 */
16
class VarDumpFormatter implements FormatterInterface
17
{
18
    /**
19
     * @inheritdoc
20
     */
21
    public function write(OutputInterface $output, $data, FormatterOptions $options)
22
    {
23
        $dumper = new CliDumper();
24
        $cloned_data = (new VarCloner())->cloneVar($data);
25
26
        if ($output instanceof StreamOutput) {
27
            // When stream output is used the dumper is smart enough to
28
            // determine whether or not to apply colors to the dump.
29
            // @see Symfony\Component\VarDumper\Dumper\CliDumper::supportsColors
30
            $dumper->dump($cloned_data, $output->getStream());
31
        } else {
32
            $output->writeln($dumper->dump($cloned_data, true));
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a callable|resource|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
33
        }
34
    }
35
}
36