Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. PrettyPrinterAbstract.php

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:

Node $node Node:

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

... See full list

File

vendor/nikic/php-parser/lib/PhpParser/PrettyPrinterAbstract.php, line 412

Class

PrettyPrinterAbstract

Namespace

PhpParser

Code

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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal