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

Breadcrumb

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

function Standard::pScalar_Int

File

vendor/nikic/php-parser/lib/PhpParser/PrettyPrinter/Standard.php, line 199

Class

Standard

Namespace

PhpParser\PrettyPrinter

Code

protected function pScalar_Int(Scalar\Int_ $node) : string {
    if ($node->value === -\PHP_INT_MAX - 1) {
        // PHP_INT_MIN cannot be represented as a literal,
        // because the sign is not part of the literal
        return '(-' . \PHP_INT_MAX . '-1)';
    }
    $kind = $node->getAttribute('kind', Scalar\Int_::KIND_DEC);
    if (Scalar\Int_::KIND_DEC === $kind) {
        return (string) $node->value;
    }
    if ($node->value < 0) {
        $sign = '-';
        $str = (string) -$node->value;
    }
    else {
        $sign = '';
        $str = (string) $node->value;
    }
    switch ($kind) {
        case Scalar\Int_::KIND_BIN:
            return $sign . '0b' . base_convert($str, 10, 2);
        case Scalar\Int_::KIND_OCT:
            return $sign . '0' . base_convert($str, 10, 8);
        case Scalar\Int_::KIND_HEX:
            return $sign . '0x' . base_convert($str, 10, 16);
    }
    throw new \Exception('Invalid number kind');
}

API Navigation

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