phpDocInfoFactory = $phpDocInfoFactory; $this->phpDocTypeChanger = $phpDocTypeChanger; $this->betterNodeFinder = $betterNodeFinder; } public function decorateNodeWithInlineVarType(Node $node, TypeWithClassName $typeWithClassName, string $variableName) : void { $phpDocInfo = $this->resolvePhpDocInfo($node); // already done if ($phpDocInfo->getVarTagValueNode() !== null) { return; } $fullyQualifiedIdentifierTypeNode = new FullyQualifiedIdentifierTypeNode($typeWithClassName->getClassName()); $varTagValueNode = new VarTagValueNode($fullyQualifiedIdentifierTypeNode, '$' . $variableName, ''); $phpDocInfo->addTagValueNode($varTagValueNode); $phpDocInfo->makeSingleLined(); } /** * @api */ public function decorateNodeWithType(Node $node, Type $staticType) : void { if ($staticType instanceof MixedType) { return; } $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node); $this->phpDocTypeChanger->changeVarType($phpDocInfo, $staticType); } private function resolvePhpDocInfo(Node $node) : PhpDocInfo { $currentStmt = $this->betterNodeFinder->resolveCurrentStatement($node); if ($currentStmt instanceof Expression) { $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($currentStmt); } else { $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node); } $phpDocInfo->makeSingleLined(); return $phpDocInfo; } }