Skip to content

Commit c479818

Browse files
committed
Extract symfony dumper
1 parent f23f146 commit c479818

File tree

2 files changed

+35
-16
lines changed

2 files changed

+35
-16
lines changed

src/Exception/Value/SymfonyValuePrinter.php

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
use Symfony\Component\VarDumper\Caster\ReflectionCaster;
88
use Symfony\Component\VarDumper\Cloner\ClonerInterface;
9-
use Symfony\Component\VarDumper\Cloner\Data;
109
use Symfony\Component\VarDumper\Cloner\VarCloner;
1110
use Symfony\Component\VarDumper\Dumper\AbstractDumper;
1211
use Symfony\Component\VarDumper\Dumper\CliDumper;
1312
use Symfony\Component\VarDumper\Dumper\DataDumperInterface;
1413
use TypeLang\Mapper\Exception\Environment\ComposerPackageRequiredException;
14+
use TypeLang\Mapper\Exception\Value\SymfonyValuePrinter\SimplifiedCliDumper;
1515

1616
final class SymfonyValuePrinter implements ValuePrinterInterface
1717
{
@@ -31,21 +31,7 @@ public function __construct(
3131

3232
private function createDefaultDataDumper(): CliDumper
3333
{
34-
$dumper = new class extends CliDumper {
35-
public function dump(Data $data, $output = null): ?string
36-
{
37-
$result = parent::dump($data, $output);
38-
39-
if ($result !== null) {
40-
return \rtrim($result, "\n");
41-
}
42-
43-
return null;
44-
}
45-
};
46-
$dumper->setColors(false);
47-
48-
return $dumper;
34+
return new SimplifiedCliDumper();
4935
}
5036

5137
private function createDefaultVarCloner(): VarCloner
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypeLang\Mapper\Exception\Value\SymfonyValuePrinter;
6+
7+
use Symfony\Component\VarDumper\Cloner\Data;
8+
use Symfony\Component\VarDumper\Dumper\CliDumper;
9+
10+
/**
11+
* @internal this is an internal library class, please do not use it in your code
12+
* @psalm-internal TypeLang\Mapper\Exception\Value
13+
*/
14+
final class SimplifiedCliDumper extends CliDumper
15+
{
16+
public function __construct($output = null, ?string $charset = null, int $flags = 0)
17+
{
18+
parent::__construct($output, $charset, $flags);
19+
20+
$this->setColors(false);
21+
}
22+
23+
public function dump(Data $data, $output = null): ?string
24+
{
25+
$result = parent::dump($data, $output);
26+
27+
if ($result !== null) {
28+
return \rtrim($result, "\n");
29+
}
30+
31+
return null;
32+
}
33+
}

0 commit comments

Comments
 (0)