Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
38.89% covered (danger)
38.89%
7 / 18
CRAP
78.20% covered (warning)
78.20%
226 / 289
CliDumper
0.00% covered (danger)
0.00%
0 / 1
38.89% covered (danger)
38.89%
7 / 18
478.47
78.20% covered (warning)
78.20%
226 / 289
 __construct
0.00% covered (danger)
0.00%
0 / 1
5.93
66.67% covered (warning)
66.67%
4 / 6
 setColors
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 setMaxStringWidth
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 setStyles
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 setDisplayOptions
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 dumpScalar
100.00% covered (success)
100.00%
1 / 1
11
100.00% covered (success)
100.00%
32 / 32
 dumpString
0.00% covered (danger)
0.00%
0 / 1
26.44
86.79% covered (warning)
86.79%
46 / 53
 enterHash
0.00% covered (danger)
0.00%
0 / 1
21
95.24% covered (success)
95.24%
20 / 21
 leaveHash
100.00% covered (success)
100.00%
1 / 1
5
100.00% covered (success)
100.00%
5 / 5
 dumpEllipsis
100.00% covered (success)
100.00%
1 / 1
4
100.00% covered (success)
100.00%
7 / 7
 dumpKey
0.00% covered (danger)
0.00%
0 / 1
22
98.08% covered (success)
98.08%
51 / 52
 style
0.00% covered (danger)
0.00%
0 / 1
29.53
87.50% covered (warning)
87.50%
35 / 40
 supportsColors
0.00% covered (danger)
0.00%
0 / 1
239.60
8.33% covered (danger)
8.33%
2 / 24
 dumpLine
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
4 / 4
 endValue
100.00% covered (success)
100.00%
1 / 1
8
100.00% covered (success)
100.00%
9 / 9
 hasColorSupport
0.00% covered (danger)
0.00%
0 / 1
39.20
38.46% covered (danger)
38.46%
5 / 13
 isWindowsTrueColor
0.00% covered (danger)
0.00%
0 / 1
30
0.00% covered (danger)
0.00%
0 / 12
 getSourceLink
0.00% covered (danger)
0.00%
0 / 1
4.59
66.67% covered (warning)
66.67%
2 / 3
<?php
/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace Symfony\Component\VarDumper\Dumper;
use Symfony\Component\VarDumper\Cloner\Cursor;
use Symfony\Component\VarDumper\Cloner\Stub;
/**
 * CliDumper dumps variables for command line output.
 *
 * @author Nicolas Grekas <p@tchwork.com>
 */
class CliDumper extends AbstractDumper
{
    public static $defaultColors;
    public static $defaultOutput = 'php://stdout';
    protected $colors;
    protected $maxStringWidth = 0;
    protected $styles = [
        // See http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
        'default' => '0;38;5;208',
        'num' => '1;38;5;38',
        'const' => '1;38;5;208',
        'str' => '1;38;5;113',
        'note' => '38;5;38',
        'ref' => '38;5;247',
        'public' => '',
        'protected' => '',
        'private' => '',
        'meta' => '38;5;170',
        'key' => '38;5;113',
        'index' => '38;5;38',
    ];
    protected static $controlCharsRx = '/[\x00-\x1F\x7F]+/';
    protected static $controlCharsMap = [
        "\t" => '\t',
        "\n" => '\n',
        "\v" => '\v',
        "\f" => '\f',
        "\r" => '\r',
        "\033" => '\e',
    ];
    protected $collapseNextHash = false;
    protected $expandNextHash = false;
    private $displayOptions = [
        'fileLinkFormat' => null,
    ];
    private $handlesHrefGracefully;
    /**
     * {@inheritdoc}
     */
    public function __construct($output = null, string $charset = null, int $flags = 0)
    {
        parent::__construct($output, $charset, $flags);
        if ('\\' === \DIRECTORY_SEPARATOR && !$this->isWindowsTrueColor()) {
            // Use only the base 16 xterm colors when using ANSICON or standard Windows 10 CLI
            $this->setStyles([
                'default' => '31',
                'num' => '1;34',
                'const' => '1;31',
                'str' => '1;32',
                'note' => '34',
                'ref' => '1;30',
                'meta' => '35',
                'key' => '32',
                'index' => '34',
            ]);
        }
        $this->displayOptions['fileLinkFormat'] = ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format') ?: 'file://%f#L%l';
    }
    /**
     * Enables/disables colored output.
     */
    public function setColors(bool $colors)
    {
        $this->colors = $colors;
    }
    /**
     * Sets the maximum number of characters per line for dumped strings.
     */
    public function setMaxStringWidth(int $maxStringWidth)
    {
        $this->maxStringWidth = $maxStringWidth;
    }
    /**
     * Configures styles.
     *
     * @param array $styles A map of style names to style definitions
     */
    public function setStyles(array $styles)
    {
        $this->styles = $styles + $this->styles;
    }
    /**
     * Configures display options.
     *
     * @param array $displayOptions A map of display options to customize the behavior
     */
    public function setDisplayOptions(array $displayOptions)
    {
        $this->displayOptions = $displayOptions + $this->displayOptions;
    }
    /**
     * {@inheritdoc}
     */
    public function dumpScalar(Cursor $cursor, string $type, $value)
    {
        $this->dumpKey($cursor);
        $style = 'const';
        $attr = $cursor->attr;
        switch ($type) {
            case 'default':
                $style = 'default';
                break;
            case 'integer':
                $style = 'num';
                break;
            case 'double':
                $style = 'num';
                switch (true) {
                    case INF === $value:  $value = 'INF'; break;
                    case -INF === $value: $value = '-INF'; break;
                    case is_nan($value):  $value = 'NAN'; break;
                    default:
                        $value = (string) $value;
                        if (false === strpos($value, $this->decimalPoint)) {
                            $value .= $this->decimalPoint.'0';
                        }
                        break;
                }
                break;
            case 'NULL':
                $value = 'null';
                break;
            case 'boolean':
                $value = $value ? 'true' : 'false';
                break;
            default:
                $attr += ['value' => $this->utf8Encode($value)];
                $value = $this->utf8Encode($type);
                break;
        }
        $this->line .= $this->style($style, $value, $attr);