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