1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\Node\Printer;
4:
5: use PhpParser\Node\Expr;
6:
7: /**
8: * @api
9: */
10: final class ExprPrinter
11: {
12:
13: public function __construct(private Printer $printer)
14: {
15: }
16:
17: public function printExpr(Expr $expr): string
18: {
19: /** @var string|null $exprString */
20: $exprString = $expr->getAttribute('phpstan_cache_printer');
21: if ($exprString === null) {
22: $exprString = $this->printer->prettyPrintExpr($expr);
23: $expr->setAttribute('phpstan_cache_printer', $exprString);
24: }
25:
26: return $exprString;
27: }
28:
29: }
30: