about summary refs log tree commit diff stats
path: root/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr
diff options
context:
space:
mode:
authorfox <fox@fakecake.org>2026-05-26 06:45:47 +0300
committerfox <fox@fakecake.org>2026-05-26 06:45:47 +0300
commit4ce7212e8c26cd613db0cfc75ef8a5a0ba6eb7be (patch)
tree0ec2e37f6f86d59a904a2f1de2a15294ef1ae349 /vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr
parentcae514dddfc59f533a93a47afc283371d5949843 (diff)
parentdc60880d9cc4074a231fd21c9508d0f78beaf1f1 (diff)
downloadthe-epube-4ce7212e8c26cd613db0cfc75ef8a5a0ba6eb7be.tar.gz
the-epube-4ce7212e8c26cd613db0cfc75ef8a5a0ba6eb7be.tar.xz
Merge branch 'dev' into 'master'
Dev

See merge request git/the-epube!39
Diffstat (limited to 'vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr')
-rw-r--r--vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprArrayItemNode.php47
-rw-r--r--vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprArrayNode.php43
-rw-r--r--vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprFalseNode.php31
-rw-r--r--vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprFloatNode.php38
-rw-r--r--vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprIntegerNode.php38
-rw-r--r--vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprNode.php10
-rw-r--r--vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprNullNode.php31
-rw-r--r--vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprStringNode.php93
-rw-r--r--vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprTrueNode.php31
-rw-r--r--vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstFetchNode.php47
-rw-r--r--vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/DoctrineConstExprStringNode.php55
11 files changed, 464 insertions, 0 deletions
diff --git a/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprArrayItemNode.php b/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprArrayItemNode.php
new file mode 100644
index 0000000..b8e7c0a
--- /dev/null
+++ b/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprArrayItemNode.php
@@ -0,0 +1,47 @@
+<?php declare(strict_types = 1);
+
+namespace PHPStan\PhpDocParser\Ast\ConstExpr;
+
+use PHPStan\PhpDocParser\Ast\NodeAttributes;
+use function sprintf;
+
+class ConstExprArrayItemNode implements ConstExprNode
+{
+
+	use NodeAttributes;
+
+	public ?ConstExprNode $key = null;
+
+	public ConstExprNode $value;
+
+	public function __construct(?ConstExprNode $key, ConstExprNode $value)
+	{
+		$this->key = $key;
+		$this->value = $value;
+	}
+
+	public function __toString(): string
+	{
+		if ($this->key !== null) {
+			return sprintf('%s => %s', $this->key, $this->value);
+
+		}
+
+		return (string) $this->value;
+	}
+
+	/**
+	 * @param array<string, mixed> $properties
+	 */
+	public static function __set_state(array $properties): self
+	{
+		$instance = new self($properties['key'], $properties['value']);
+		if (isset($properties['attributes'])) {
+			foreach ($properties['attributes'] as $key => $value) {
+				$instance->setAttribute($key, $value);
+			}
+		}
+		return $instance;
+	}
+
+}
diff --git a/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprArrayNode.php b/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprArrayNode.php
new file mode 100644
index 0000000..ae83c39
--- /dev/null
+++ b/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprArrayNode.php
@@ -0,0 +1,43 @@
+<?php declare(strict_types = 1);
+
+namespace PHPStan\PhpDocParser\Ast\ConstExpr;
+
+use PHPStan\PhpDocParser\Ast\NodeAttributes;
+use function implode;
+
+class ConstExprArrayNode implements ConstExprNode
+{
+
+	use NodeAttributes;
+
+	/** @var ConstExprArrayItemNode[] */
+	public array $items;
+
+	/**
+	 * @param ConstExprArrayItemNode[] $items
+	 */
+	public function __construct(array $items)
+	{
+		$this->items = $items;
+	}
+
+	public function __toString(): string
+	{
+		return '[' . implode(', ', $this->items) . ']';
+	}
+
+	/**
+	 * @param array<string, mixed> $properties
+	 */
+	public static function __set_state(array $properties): self
+	{
+		$instance = new self($properties['items']);
+		if (isset($properties['attributes'])) {
+			foreach ($properties['attributes'] as $key => $value) {
+				$instance->setAttribute($key, $value);
+			}
+		}
+		return $instance;
+	}
+
+}
diff --git a/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprFalseNode.php b/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprFalseNode.php
new file mode 100644
index 0000000..310ff10
--- /dev/null
+++ b/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprFalseNode.php
@@ -0,0 +1,31 @@
+<?php declare(strict_types = 1);
+
+namespace PHPStan\PhpDocParser\Ast\ConstExpr;
+
+use PHPStan\PhpDocParser\Ast\NodeAttributes;
+
+class ConstExprFalseNode implements ConstExprNode
+{
+
+	use NodeAttributes;
+
+	public function __toString(): string
+	{
+		return 'false';
+	}
+
+	/**
+	 * @param array<string, mixed> $properties
+	 */
+	public static function __set_state(array $properties): self
+	{
+		$instance = new self();
+		if (isset($properties['attributes'])) {
+			foreach ($properties['attributes'] as $key => $value) {
+				$instance->setAttribute($key, $value);
+			}
+		}
+		return $instance;
+	}
+
+}
diff --git a/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprFloatNode.php b/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprFloatNode.php
new file mode 100644
index 0000000..badb1cf
--- /dev/null
+++ b/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprFloatNode.php
@@ -0,0 +1,38 @@
+<?php declare(strict_types = 1);
+
+namespace PHPStan\PhpDocParser\Ast\ConstExpr;
+
+use PHPStan\PhpDocParser\Ast\NodeAttributes;
+
+class ConstExprFloatNode implements ConstExprNode
+{
+
+	use NodeAttributes;
+
+	public string $value;
+
+	public function __construct(string $value)
+	{
+		$this->value = $value;
+	}
+
+	public function __toString(): string
+	{
+		return $this->value;
+	}
+
+	/**
+	 * @param array<string, mixed> $properties
+	 */
+	public static function __set_state(array $properties): self
+	{
+		$instance = new self($properties['value']);
+		if (isset($properties['attributes'])) {
+			foreach ($properties['attributes'] as $key => $value) {
+				$instance->setAttribute($key, $value);
+			}
+		}
+		return $instance;
+	}
+
+}
diff --git a/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprIntegerNode.php b/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprIntegerNode.php
new file mode 100644
index 0000000..5bed6ed
--- /dev/null
+++ b/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprIntegerNode.php
@@ -0,0 +1,38 @@
+<?php declare(strict_types = 1);
+
+namespace PHPStan\PhpDocParser\Ast\ConstExpr;
+
+use PHPStan\PhpDocParser\Ast\NodeAttributes;
+
+class ConstExprIntegerNode implements ConstExprNode
+{
+
+	use NodeAttributes;
+
+	public string $value;
+
+	public function __construct(string $value)
+	{
+		$this->value = $value;
+	}
+
+	public function __toString(): string
+	{
+		return $this->value;
+	}
+
+	/**
+	 * @param array<string, mixed> $properties
+	 */
+	public static function __set_state(array $properties): self
+	{
+		$instance = new self($properties['value']);
+		if (isset($properties['attributes'])) {
+			foreach ($properties['attributes'] as $key => $value) {
+				$instance->setAttribute($key, $value);
+			}
+		}
+		return $instance;
+	}
+
+}
diff --git a/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprNode.php b/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprNode.php
new file mode 100644
index 0000000..1859f03
--- /dev/null
+++ b/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprNode.php
@@ -0,0 +1,10 @@
+<?php declare(strict_types = 1);
+
+namespace PHPStan\PhpDocParser\Ast\ConstExpr;
+
+use PHPStan\PhpDocParser\Ast\Node;
+
+interface ConstExprNode extends Node
+{
+
+}
diff --git a/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprNullNode.php b/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprNullNode.php
new file mode 100644
index 0000000..b0f9165
--- /dev/null
+++ b/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprNullNode.php
@@ -0,0 +1,31 @@
+<?php declare(strict_types = 1);
+
+namespace PHPStan\PhpDocParser\Ast\ConstExpr;
+
+use PHPStan\PhpDocParser\Ast\NodeAttributes;
+
+class ConstExprNullNode implements ConstExprNode
+{
+
+	use NodeAttributes;
+
+	public function __toString(): string
+	{
+		return 'null';
+	}
+
+	/**
+	 * @param array<string, mixed> $properties
+	 */
+	public static function __set_state(array $properties): self
+	{
+		$instance = new self();
+		if (isset($properties['attributes'])) {
+			foreach ($properties['attributes'] as $key => $value) {
+				$instance->setAttribute($key, $value);
+			}
+		}
+		return $instance;
+	}
+
+}
diff --git a/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprStringNode.php b/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprStringNode.php
new file mode 100644
index 0000000..5ac662a
--- /dev/null
+++ b/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprStringNode.php
@@ -0,0 +1,93 @@
+<?php declare(strict_types = 1);
+
+namespace PHPStan\PhpDocParser\Ast\ConstExpr;
+
+use PHPStan\PhpDocParser\Ast\NodeAttributes;
+use function addcslashes;
+use function assert;
+use function dechex;
+use function ord;
+use function preg_replace_callback;
+use function sprintf;
+use function str_pad;
+use function strlen;
+use const STR_PAD_LEFT;
+
+class ConstExprStringNode implements ConstExprNode
+{
+
+	public const SINGLE_QUOTED = 1;
+	public const DOUBLE_QUOTED = 2;
+
+	use NodeAttributes;
+
+	public string $value;
+
+	/** @var self::SINGLE_QUOTED|self::DOUBLE_QUOTED */
+	public $quoteType;
+
+	/**
+	 * @param self::SINGLE_QUOTED|self::DOUBLE_QUOTED $quoteType
+	 */
+	public function __construct(string $value, int $quoteType)
+	{
+		$this->value = $value;
+		$this->quoteType = $quoteType;
+	}
+
+	public function __toString(): string
+	{
+		if ($this->quoteType === self::SINGLE_QUOTED) {
+			// from https://github.com/nikic/PHP-Parser/blob/0ffddce52d816f72d0efc4d9b02e276d3309ef01/lib/PhpParser/PrettyPrinter/Standard.php#L1007
+			return sprintf("'%s'", addcslashes($this->value, '\'\\'));
+		}
+
+		// from https://github.com/nikic/PHP-Parser/blob/0ffddce52d816f72d0efc4d9b02e276d3309ef01/lib/PhpParser/PrettyPrinter/Standard.php#L1010-L1040
+		return sprintf('"%s"', $this->escapeDoubleQuotedString());
+	}
+
+	private function escapeDoubleQuotedString(): string
+	{
+		$quote = '"';
+		$escaped = addcslashes($this->value, "\n\r\t\f\v$" . $quote . '\\');
+
+		// Escape control characters and non-UTF-8 characters.
+		// Regex based on https://stackoverflow.com/a/11709412/385378.
+		$regex = '/(
+              [\x00-\x08\x0E-\x1F] # Control characters
+            | [\xC0-\xC1] # Invalid UTF-8 Bytes
+            | [\xF5-\xFF] # Invalid UTF-8 Bytes
+            | \xE0(?=[\x80-\x9F]) # Overlong encoding of prior code point
+            | \xF0(?=[\x80-\x8F]) # Overlong encoding of prior code point
+            | [\xC2-\xDF](?![\x80-\xBF]) # Invalid UTF-8 Sequence Start
+            | [\xE0-\xEF](?![\x80-\xBF]{2}) # Invalid UTF-8 Sequence Start
+            | [\xF0-\xF4](?![\x80-\xBF]{3}) # Invalid UTF-8 Sequence Start
+            | (?<=[\x00-\x7F\xF5-\xFF])[\x80-\xBF] # Invalid UTF-8 Sequence Middle
+            | (?<![\xC2-\xDF]|[\xE0-\xEF]|[\xE0-\xEF][\x80-\xBF]|[\xF0-\xF4]|[\xF0-\xF4][\x80-\xBF]|[\xF0-\xF4][\x80-\xBF]{2})[\x80-\xBF] # Overlong Sequence
+            | (?<=[\xE0-\xEF])[\x80-\xBF](?![\x80-\xBF]) # Short 3 byte sequence
+            | (?<=[\xF0-\xF4])[\x80-\xBF](?![\x80-\xBF]{2}) # Short 4 byte sequence
+            | (?<=[\xF0-\xF4][\x80-\xBF])[\x80-\xBF](?![\x80-\xBF]) # Short 4 byte sequence (2)
+        )/x';
+		return preg_replace_callback($regex, static function ($matches) {
+			assert(strlen($matches[0]) === 1);
+			$hex = dechex(ord($matches[0]));
+
+			return '\\x' . str_pad($hex, 2, '0', STR_PAD_LEFT);
+		}, $escaped);
+	}
+
+	/**
+	 * @param array<string, mixed> $properties
+	 */
+	public static function __set_state(array $properties): self
+	{
+		$instance = new self($properties['value'], $properties['quoteType']);
+		if (isset($properties['attributes'])) {
+			foreach ($properties['attributes'] as $key => $value) {
+				$instance->setAttribute($key, $value);
+			}
+		}
+		return $instance;
+	}
+
+}
diff --git a/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprTrueNode.php b/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprTrueNode.php
new file mode 100644
index 0000000..a7e172b
--- /dev/null
+++ b/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprTrueNode.php
@@ -0,0 +1,31 @@
+<?php declare(strict_types = 1);
+
+namespace PHPStan\PhpDocParser\Ast\ConstExpr;
+
+use PHPStan\PhpDocParser\Ast\NodeAttributes;
+
+class ConstExprTrueNode implements ConstExprNode
+{
+
+	use NodeAttributes;
+
+	public function __toString(): string
+	{
+		return 'true';
+	}
+
+	/**
+	 * @param array<string, mixed> $properties
+	 */
+	public static function __set_state(array $properties): self
+	{
+		$instance = new self();
+		if (isset($properties['attributes'])) {
+			foreach ($properties['attributes'] as $key => $value) {
+				$instance->setAttribute($key, $value);
+			}
+		}
+		return $instance;
+	}
+
+}
diff --git a/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstFetchNode.php b/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstFetchNode.php
new file mode 100644
index 0000000..65ba489
--- /dev/null
+++ b/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstFetchNode.php
@@ -0,0 +1,47 @@
+<?php declare(strict_types = 1);
+
+namespace PHPStan\PhpDocParser\Ast\ConstExpr;
+
+use PHPStan\PhpDocParser\Ast\NodeAttributes;
+
+class ConstFetchNode implements ConstExprNode
+{
+
+	use NodeAttributes;
+
+	/** @var string class name for class constants or empty string for non-class constants */
+	public string $className;
+
+	public string $name;
+
+	public function __construct(string $className, string $name)
+	{
+		$this->className = $className;
+		$this->name = $name;
+	}
+
+	public function __toString(): string
+	{
+		if ($this->className === '') {
+			return $this->name;
+
+		}
+
+		return "{$this->className}::{$this->name}";
+	}
+
+	/**
+	 * @param array<string, mixed> $properties
+	 */
+	public static function __set_state(array $properties): self
+	{
+		$instance = new self($properties['className'], $properties['name']);
+		if (isset($properties['attributes'])) {
+			foreach ($properties['attributes'] as $key => $value) {
+				$instance->setAttribute($key, $value);
+			}
+		}
+		return $instance;
+	}
+
+}
diff --git a/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/DoctrineConstExprStringNode.php b/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/DoctrineConstExprStringNode.php
new file mode 100644
index 0000000..5cfb071
--- /dev/null
+++ b/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/DoctrineConstExprStringNode.php
@@ -0,0 +1,55 @@
+<?php declare(strict_types = 1);
+
+namespace PHPStan\PhpDocParser\Ast\ConstExpr;
+
+use PHPStan\PhpDocParser\Ast\NodeAttributes;
+use function sprintf;
+use function str_replace;
+use function strlen;
+use function substr;
+
+class DoctrineConstExprStringNode extends ConstExprStringNode
+{
+
+	use NodeAttributes;
+
+	public string $value;
+
+	public function __construct(string $value)
+	{
+		parent::__construct($value, self::DOUBLE_QUOTED);
+		$this->value = $value;
+	}
+
+	public function __toString(): string
+	{
+		return self::escape($this->value);
+	}
+
+	public static function unescape(string $value): string
+	{
+		// from https://github.com/doctrine/annotations/blob/a9ec7af212302a75d1f92fa65d3abfbd16245a2a/lib/Doctrine/Common/Annotations/DocLexer.php#L103-L107
+		return str_replace('""', '"', substr($value, 1, strlen($value) - 2));
+	}
+
+	private static function escape(string $value): string
+	{
+		// from https://github.com/phpstan/phpdoc-parser/issues/205#issuecomment-1662323656
+		return sprintf('"%s"', str_replace('"', '""', $value));
+	}
+
+	/**
+	 * @param array<string, mixed> $properties
+	 */
+	public static function __set_state(array $properties): self
+	{
+		$instance = new self($properties['value']);
+		if (isset($properties['attributes'])) {
+			foreach ($properties['attributes'] as $key => $value) {
+				$instance->setAttribute($key, $value);
+			}
+		}
+		return $instance;
+	}
+
+}