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 $value;
21:
22: /** @var mixed[] */
23: private $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: ];
35: }
36:
37: public function __get(string $name)
38: {
39: if ($name !== 'exception') {
40: trigger_error(sprintf('Undefined property: %s::$%s', self::class, $name), E_USER_WARNING);
41: return null;
42: }
43:
44: return new ParserException(...$this->exceptionArgs);
45: }
46:
47: public function __toString(): string
48: {
49: return $this->value;
50: }
51:
52: }
53: