function PrettyPrinterAbstract::pFixup
Print node with fixups.
Fixups here refer to the addition of extra parentheses, braces or other characters, that are required to preserve program semantics in a certain context (e.g. to maintain precedence or because only certain expressions are allowed in certain places).
Parameters
int $fixup Fixup type:
Node $subNode Subnode to print:
string|null $parentClass Class of parent node:
int $subStartPos Original start pos of subnode:
int $subEndPos Original end pos of subnode:
Return value
string Result of fixed-up print of subnode
2 calls to PrettyPrinterAbstract::pFixup()
- PrettyPrinterAbstract::p in vendor/
nikic/ php-parser/ lib/ PhpParser/ PrettyPrinterAbstract.php - Pretty prints a node.
- PrettyPrinterAbstract::pArray in vendor/
nikic/ php-parser/ lib/ PhpParser/ PrettyPrinterAbstract.php - Perform a format-preserving pretty print of an array.
File
-
vendor/
nikic/ php-parser/ lib/ PhpParser/ PrettyPrinterAbstract.php, line 1041
Class
Namespace
PhpParserCode
protected function pFixup(int $fixup, Node $subNode, ?string $parentClass, int $subStartPos, int $subEndPos) : string {
switch ($fixup) {
case self::FIXUP_PREC_LEFT:
// We use a conservative approximation where lhsPrecedence == precedence.
if (!$this->origTokens
->haveParens($subStartPos, $subEndPos)) {
$precedence = $this->precedenceMap[$parentClass][1];
return $this->p($subNode, $precedence, $precedence);
}
break;
case self::FIXUP_PREC_RIGHT:
if (!$this->origTokens
->haveParens($subStartPos, $subEndPos)) {
$precedence = $this->precedenceMap[$parentClass][2];
return $this->p($subNode, $precedence, $precedence);
}
break;
case self::FIXUP_PREC_UNARY:
if (!$this->origTokens
->haveParens($subStartPos, $subEndPos)) {
$precedence = $this->precedenceMap[$parentClass][0];
return $this->p($subNode, $precedence, $precedence);
}
break;
case self::FIXUP_CALL_LHS:
if ($this->callLhsRequiresParens($subNode) && !$this->origTokens
->haveParens($subStartPos, $subEndPos)) {
return '(' . $this->p($subNode) . ')';
}
break;
case self::FIXUP_DEREF_LHS:
if ($this->dereferenceLhsRequiresParens($subNode) && !$this->origTokens
->haveParens($subStartPos, $subEndPos)) {
return '(' . $this->p($subNode) . ')';
}
break;
case self::FIXUP_STATIC_DEREF_LHS:
if ($this->staticDereferenceLhsRequiresParens($subNode) && !$this->origTokens
->haveParens($subStartPos, $subEndPos)) {
return '(' . $this->p($subNode) . ')';
}
break;
case self::FIXUP_NEW:
if ($this->newOperandRequiresParens($subNode) && !$this->origTokens
->haveParens($subStartPos, $subEndPos)) {
return '(' . $this->p($subNode) . ')';
}
break;
case self::FIXUP_BRACED_NAME:
case self::FIXUP_VAR_BRACED_NAME:
if ($subNode instanceof Expr && !$this->origTokens
->haveBraces($subStartPos, $subEndPos)) {
return ($fixup === self::FIXUP_VAR_BRACED_NAME ? '$' : '') . '{' . $this->p($subNode) . '}';
}
break;
case self::FIXUP_ENCAPSED:
if (!$subNode instanceof Node\InterpolatedStringPart && !$this->origTokens
->haveBraces($subStartPos, $subEndPos)) {
return '{' . $this->p($subNode) . '}';
}
break;
default:
throw new \Exception('Cannot happen');
}
// Nothing special to do
return $this->p($subNode);
}