1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\PhpDocParser\Ast\PhpDoc;
4:
5: use PHPStan\PhpDocParser\Ast\NodeAttributes;
6: use PHPStan\PhpDocParser\Parser\ParserException;
7: use function sprintf;
8: use function trigger_error;
9: use const E_USER_WARNING;
10:
11: /**
12: * @property ParserException $exception
13: */
14: class InvalidTagValueNode implements PhpDocTagValueNode
15: {
16:
17: use NodeAttributes;
18:
19: /** @var string (may be empty) */
20: public string $value;
21:
22: /** @var mixed[] */
23: private array $exceptionArgs;
24:
25: public function __construct(string $value, ParserException $exception)
26: {
27: $this->value = $value;
28: $this->exceptionArgs = [
29: $exception->getCurrentTokenValue(),
30: $exception->getCurrentTokenType(),
31: $exception->getCurrentOffset(),
32: $exception->getExpectedTokenType(),
33: $exception->getExpectedTokenValue(),
34: $exception->getCurrentTokenLine(),
35: ];
36: }
37:
38: public function __get(string $name): ?ParserException
39: {
40: if ($name !== 'exception') {
41: trigger_error(sprintf('Undefined property: %s::$%s', self::class, $name), E_USER_WARNING);
42: return null;
43: }
44:
45: return new ParserException(...$this->exceptionArgs);
46: }
47:
48: public function __toString(): string
49: {
50: return $this->value;
51: }
52:
53: }
54: