PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 4.9.3
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v4.9.3
4.9.3 4.9.2 4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 3.4.2 3.5.0 All 201 releases
betterdocs / includes / Dependencies / PhpParser / Node / Scalar / LNumber.php

LNumber.php in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 4.9.3, at includes/Dependencies/PhpParser/Node/Scalar/LNumber.php

69 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // phpcs:ignoreFile -- Bundled third-party (Mozart) dependency; exempt from plugin coding standards.
3
4 namespace WPDeveloper\BetterDocs\Dependencies\PhpParser\Node\Scalar;
5
6 use WPDeveloper\BetterDocs\Dependencies\PhpParser\Error;
7 use WPDeveloper\BetterDocs\Dependencies\PhpParser\Node\Scalar;
8
9 class LNumber extends Scalar
10 {
11 /* For use in "kind" attribute */
12 const KIND_BIN = 2;
13 const KIND_OCT = 8;
14 const KIND_DEC = 10;
15 const KIND_HEX = 16;
16
17 /** @var int Number value */
18 public $value;
19
20 /**
21 * Constructs an integer number scalar node.
22 *
23 * @param int $value Value of the number
24 * @param array $attributes Additional attributes
25 */
26 public function __construct($value, array $attributes = array()) {
27 parent::__construct($attributes);
28 $this->value = $value;
29 }
30
31 public function getSubNodeNames() {
32 return array('value');
33 }
34
35 /**
36 * Constructs an LNumber node from a string number literal.
37 *
38 * @param string $str String number literal (decimal, octal, hex or binary)
39 * @param array $attributes Additional attributes
40 * @param bool $allowInvalidOctal Whether to allow invalid octal numbers (PHP 5)
41 *
42 * @return LNumber The constructed LNumber, including kind attribute
43 */
44 public static function fromString($str, array $attributes = array(), $allowInvalidOctal = false) {
45 if ('0' !== $str[0] || '0' === $str) {
46 $attributes['kind'] = LNumber::KIND_DEC;
47 return new LNumber((int) $str, $attributes);
48 }
49
50 if ('x' === $str[1] || 'X' === $str[1]) {
51 $attributes['kind'] = LNumber::KIND_HEX;
52 return new LNumber(hexdec($str), $attributes);
53 }
54
55 if ('b' === $str[1] || 'B' === $str[1]) {
56 $attributes['kind'] = LNumber::KIND_BIN;
57 return new LNumber(bindec($str), $attributes);
58 }
59
60 if (!$allowInvalidOctal && strpbrk($str, '89')) {
61 throw new Error('Invalid numeric literal', $attributes);
62 }
63
64 // use intval instead of octdec to get proper cutting behavior with malformed numbers
65 $attributes['kind'] = LNumber::KIND_OCT;
66 return new LNumber(intval($str, 8), $attributes);
67 }
68 }
69