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: | |
17: | public $value; |
18: | |
19: | public function __construct(string $value) |
20: | { |
21: | parent::__construct($value); |
22: | $this->value = $value; |
23: | } |
24: | |
25: | public function __toString(): string |
26: | { |
27: | return self::escape($this->value); |
28: | } |
29: | |
30: | public static function unescape(string $value): string |
31: | { |
32: | |
33: | return str_replace('""', '"', substr($value, 1, strlen($value) - 2)); |
34: | } |
35: | |
36: | private static function escape(string $value): string |
37: | { |
38: | |
39: | return sprintf('"%s"', str_replace('"', '""', $value)); |
40: | } |
41: | |
42: | } |
43: | |