| 1: | <?php declare(strict_types = 1); |
| 2: | |
| 3: | namespace PHPStan\PhpDocParser\Ast\ConstExpr; |
| 4: | |
| 5: | use PHPStan\PhpDocParser\Ast\NodeAttributes; |
| 6: | use function sprintf; |
| 7: | use function str_replace; |
| 8: | use function strlen; |
| 9: | use function substr; |
| 10: | |
| 11: | class DoctrineConstExprStringNode extends ConstExprStringNode |
| 12: | { |
| 13: | |
| 14: | use NodeAttributes; |
| 15: | |
| 16: | public string $value; |
| 17: | |
| 18: | public function __construct(string $value) |
| 19: | { |
| 20: | parent::__construct($value, self::DOUBLE_QUOTED); |
| 21: | $this->value = $value; |
| 22: | } |
| 23: | |
| 24: | public function __toString(): string |
| 25: | { |
| 26: | return self::escape($this->value); |
| 27: | } |
| 28: | |
| 29: | public static function unescape(string $value): string |
| 30: | { |
| 31: | |
| 32: | return str_replace('""', '"', substr($value, 1, strlen($value) - 2)); |
| 33: | } |
| 34: | |
| 35: | private static function escape(string $value): string |
| 36: | { |
| 37: | |
| 38: | return sprintf('"%s"', str_replace('"', '""', $value)); |
| 39: | } |
| 40: | |
| 41: | } |
| 42: | |