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