about summary refs log tree commit diff stats
path: root/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/DoctrineConstExprStringNode.php
diff options
context:
space:
mode:
authorAndrew Dolgov <fox@fakecake.org>2026-05-25 14:12:01 +0300
committerAndrew Dolgov <fox@fakecake.org>2026-05-25 14:12:01 +0300
commit9600be1703ba3083c38386930fa940938394f53e (patch)
treea8fcbc476914881915eab236ee99f88459dfb09b /vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/DoctrineConstExprStringNode.php
parentcae514dddfc59f533a93a47afc283371d5949843 (diff)
downloadthe-epube-9600be1703ba3083c38386930fa940938394f53e.tar.gz
the-epube-9600be1703ba3083c38386930fa940938394f53e.tar.xz
add phpunit
Diffstat (limited to 'vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/DoctrineConstExprStringNode.php')
-rw-r--r--vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/DoctrineConstExprStringNode.php55
1 files changed, 55 insertions, 0 deletions
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;
+	}
+
+}