PhpParser\PrettyPrinterAbstract::pPrec PHP Method

pPrec() protected method

Prints an expression node with the least amount of parentheses necessary to preserve the meaning.
protected pPrec ( phpparser\Node $node, integer $parentPrecedence, integer $parentAssociativity, integer $childPosition ) : string
$node phpparser\Node Node to pretty print
$parentPrecedence integer Precedence of the parent operator
$parentAssociativity integer Associativity of parent operator (-1 is left, 0 is nonassoc, 1 is right)
$childPosition integer Position of the node relative to the operator (-1 is left, 1 is right)
return string The pretty printed node
    protected function pPrec(Node $node, $parentPrecedence, $parentAssociativity, $childPosition)
    {
        $type = $node->getType();
        if (isset($this->precedenceMap[$type])) {
            $childPrecedence = $this->precedenceMap[$type][0];
            if ($childPrecedence > $parentPrecedence || $parentPrecedence == $childPrecedence && $parentAssociativity != $childPosition) {
                return '(' . $this->{'p' . $type}($node) . ')';
            }
        }
        return $this->{'p' . $type}($node);
    }