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