1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\Node\Printer;
4:
5: use PhpParser\PrettyPrinter\Standard;
6: use PHPStan\Node\Expr\AlwaysRememberedExpr;
7: use PHPStan\Node\Expr\ExistingArrayDimFetch;
8: use PHPStan\Node\Expr\GetIterableKeyTypeExpr;
9: use PHPStan\Node\Expr\GetIterableValueTypeExpr;
10: use PHPStan\Node\Expr\GetOffsetValueTypeExpr;
11: use PHPStan\Node\Expr\OriginalPropertyTypeExpr;
12: use PHPStan\Node\Expr\ParameterVariableOriginalValueExpr;
13: use PHPStan\Node\Expr\PropertyInitializationExpr;
14: use PHPStan\Node\Expr\SetExistingOffsetValueTypeExpr;
15: use PHPStan\Node\Expr\SetOffsetValueTypeExpr;
16: use PHPStan\Node\Expr\TypeExpr;
17: use PHPStan\Node\Expr\UnsetOffsetExpr;
18: use PHPStan\Node\IssetExpr;
19: use PHPStan\Type\VerbosityLevel;
20: use function sprintf;
21:
22: /**
23: * @api
24: */
25: final class Printer extends Standard
26: {
27:
28: public function __construct()
29: {
30: parent::__construct(['shortArraySyntax' => true]);
31: }
32:
33: protected function pPHPStan_Node_TypeExpr(TypeExpr $expr): string // phpcs:ignore
34: {
35: return sprintf('__phpstanType(%s)', $expr->getExprType()->describe(VerbosityLevel::precise()));
36: }
37:
38: protected function pPHPStan_Node_GetOffsetValueTypeExpr(GetOffsetValueTypeExpr $expr): string // phpcs:ignore
39: {
40: return sprintf('__phpstanGetOffsetValueType(%s, %s)', $this->p($expr->getVar()), $this->p($expr->getDim()));
41: }
42:
43: protected function pPHPStan_Node_UnsetOffsetExpr(UnsetOffsetExpr $expr): string // phpcs:ignore
44: {
45: return sprintf('__phpstanUnsetOffset(%s, %s)', $this->p($expr->getVar()), $this->p($expr->getDim()));
46: }
47:
48: protected function pPHPStan_Node_GetIterableValueTypeExpr(GetIterableValueTypeExpr $expr): string // phpcs:ignore
49: {
50: return sprintf('__phpstanGetIterableValueType(%s)', $this->p($expr->getExpr()));
51: }
52:
53: protected function pPHPStan_Node_GetIterableKeyTypeExpr(GetIterableKeyTypeExpr $expr): string // phpcs:ignore
54: {
55: return sprintf('__phpstanGetIterableKeyType(%s)', $this->p($expr->getExpr()));
56: }
57:
58: protected function pPHPStan_Node_ExistingArrayDimFetch(ExistingArrayDimFetch $expr): string // phpcs:ignore
59: {
60: return sprintf('__phpstanExistingArrayDimFetch(%s, %s)', $this->p($expr->getVar()), $this->p($expr->getDim()));
61: }
62:
63: protected function pPHPStan_Node_OriginalPropertyTypeExpr(OriginalPropertyTypeExpr $expr): string // phpcs:ignore
64: {
65: return sprintf('__phpstanOriginalPropertyType(%s)', $this->p($expr->getPropertyFetch()));
66: }
67:
68: protected function pPHPStan_Node_SetOffsetValueTypeExpr(SetOffsetValueTypeExpr $expr): string // phpcs:ignore
69: {
70: return sprintf('__phpstanSetOffsetValueType(%s, %s, %s)', $this->p($expr->getVar()), $expr->getDim() !== null ? $this->p($expr->getDim()) : 'null', $this->p($expr->getValue()));
71: }
72:
73: protected function pPHPStan_Node_SetExistingOffsetValueTypeExpr(SetExistingOffsetValueTypeExpr $expr): string // phpcs:ignore
74: {
75: return sprintf('__phpstanSetExistingOffsetValueType(%s, %s, %s)', $this->p($expr->getVar()), $this->p($expr->getDim()), $this->p($expr->getValue()));
76: }
77:
78: protected function pPHPStan_Node_AlwaysRememberedExpr(AlwaysRememberedExpr $expr): string // phpcs:ignore
79: {
80: return sprintf('__phpstanRembered(%s)', $this->p($expr->getExpr()));
81: }
82:
83: protected function pPHPStan_Node_PropertyInitializationExpr(PropertyInitializationExpr $expr): string // phpcs:ignore
84: {
85: return sprintf('__phpstanPropertyInitialization(%s)', $expr->getPropertyName());
86: }
87:
88: protected function pPHPStan_Node_ParameterVariableOriginalValueExpr(ParameterVariableOriginalValueExpr $expr): string // phpcs:ignore
89: {
90: return sprintf('__phpstanParameterVariableOriginalValue(%s)', $expr->getVariableName());
91: }
92:
93: protected function pPHPStan_Node_IssetExpr(IssetExpr $expr): string // phpcs:ignore
94: {
95: return sprintf('__phpstanIssetExpr(%s)', $this->p($expr->getExpr()));
96: }
97:
98: }
99: