function PrettyPrinterAbstract::pPrefixOp
Pretty-print a prefix operation while taking precedence into account.
Parameters
string $class Node class of operator:
string $operatorString String representation of the operator:
int $precedence Precedence of parent operator:
int $lhsPrecedence Precedence for unary operator on LHS of binary operator:
Return value
string Pretty printed prefix operation
34 calls to PrettyPrinterAbstract::pPrefixOp()
- Standard::pExpr_ArrowFunction in vendor/
nikic/ php-parser/ lib/ PhpParser/ PrettyPrinter/ Standard.php - Standard::pExpr_Assign in vendor/
nikic/ php-parser/ lib/ PhpParser/ PrettyPrinter/ Standard.php - Standard::pExpr_AssignOp_BitwiseAnd in vendor/
nikic/ php-parser/ lib/ PhpParser/ PrettyPrinter/ Standard.php - Standard::pExpr_AssignOp_BitwiseOr in vendor/
nikic/ php-parser/ lib/ PhpParser/ PrettyPrinter/ Standard.php - Standard::pExpr_AssignOp_BitwiseXor in vendor/
nikic/ php-parser/ lib/ PhpParser/ PrettyPrinter/ Standard.php
File
-
vendor/
nikic/ php-parser/ lib/ PhpParser/ PrettyPrinterAbstract.php, line 412
Class
Namespace
PhpParserCode
protected function pPrefixOp(string $class, string $operatorString, Node $node, int $precedence, int $lhsPrecedence) : string {
$opPrecedence = $this->precedenceMap[$class][0];
$prefix = '';
$suffix = '';
if ($opPrecedence >= $lhsPrecedence) {
$prefix = '(';
$suffix = ')';
$lhsPrecedence = self::MAX_PRECEDENCE;
}
$printedArg = $this->p($node, $opPrecedence, $lhsPrecedence);
if ($operatorString === '+' && $printedArg[0] === '+' || $operatorString === '-' && $printedArg[0] === '-') {
// Avoid printing +(+$a) as ++$a and similar.
$printedArg = '(' . $printedArg . ')';
}
return $prefix . $operatorString . $printedArg . $suffix;
}