| Total Complexity | 7 |
| Total Lines | 46 |
| Duplicated Lines | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 10 | class Dumper |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * The connection. |
||
| 14 | * |
||
| 15 | * @var \Symfony\Component\VarDumper\Server\Connection|null |
||
| 16 | */ |
||
| 17 | private $connection; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Dumper constructor. |
||
| 21 | * |
||
| 22 | * @param \Symfony\Component\VarDumper\Server\Connection|null $connection |
||
| 23 | * @return void |
||
| 24 | */ |
||
| 25 | public function __construct(Connection $connection = null) |
||
| 26 | { |
||
| 27 | $this->connection = $connection; |
||
| 28 | } |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Dump a value with elegance. |
||
| 32 | * |
||
| 33 | * @param mixed $value |
||
| 34 | * @return void |
||
| 35 | */ |
||
| 36 | public function dump($value) |
||
| 37 | { |
||
| 38 | if (class_exists(CliDumper::class)) { |
||
| 39 | $data = $this->createVarCloner()->cloneVar($value); |
||
| 40 | |||
| 41 | if ($this->connection === null || $this->connection->write($data) === false) { |
||
| 42 | $dumper = in_array(PHP_SAPI, ['cli', 'phpdbg']) ? new CliDumper : new HtmlDumper; |
||
| 43 | $dumper->dump($data); |
||
| 44 | } |
||
| 45 | } else { |
||
| 46 | var_dump($value); |
||
|
|
|||
| 47 | } |
||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @return VarCloner |
||
| 52 | */ |
||
| 53 | protected function createVarCloner(): VarCloner |
||
| 56 | } |
||
| 57 | } |
||
| 58 |