1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\Node\Variable;
4:
5: use PhpParser\Node;
6: use PHPStan\Turbo\ReferencedByTurboExtension;
7:
8: /**
9: * A write site of a local variable inside a function-like body.
10: *
11: * Immutable. Whether the written value was read afterwards is not a property
12: * of the write - it is answered by VariableWritesNode::isRead().
13: *
14: * @api
15: */
16: #[ReferencedByTurboExtension(key: 'variableWrite')]
17: final class VariableWrite
18: {
19:
20: public const KIND_ASSIGN = 1;
21: public const KIND_READ_MODIFY_WRITE = 2;
22: public const KIND_PRE_INC = 3;
23: public const KIND_POST_INC = 4;
24: public const KIND_PRE_DEC = 5;
25: public const KIND_POST_DEC = 6;
26: public const KIND_ARRAY_DIM_WRITE = 7;
27: public const KIND_LIST_ITEM = 8;
28: public const KIND_FOREACH_VALUE = 9;
29: public const KIND_FOREACH_KEY = 10;
30: public const KIND_CATCH = 11;
31: public const KIND_PARAMETER = 12;
32: public const KIND_CLOSURE_USE = 13;
33: public const KIND_ARRAY_LITERAL_ITEM = 14;
34: public const KIND_FOREACH_VALUE_WITH_KEY = 15;
35:
36: /**
37: * @param self::KIND_* $kind
38: * @param int|string|null $offset
39: */
40: public function __construct(
41: private string $variableName,
42: private Node $node,
43: private int $id,
44: private int $kind,
45: private bool $offsetWrite = false,
46: private $offset = null,
47: private ?int $parentId = null,
48: private bool $replacesOffset = true,
49: )
50: {
51: }
52:
53: public function getVariableName(): string
54: {
55: return $this->variableName;
56: }
57:
58: /**
59: * The target node of the write - the source of the reported line.
60: */
61: public function getNode(): Node
62: {
63: return $this->node;
64: }
65:
66: public function getId(): int
67: {
68: return $this->id;
69: }
70:
71: /**
72: * @return self::KIND_*
73: */
74: public function getKind(): int
75: {
76: return $this->kind;
77: }
78:
79: public function isOffsetWrite(): bool
80: {
81: return $this->offsetWrite;
82: }
83:
84: /** @return int|string|null */
85: public function getOffset()
86: {
87: return $this->offset;
88: }
89:
90: public function getParentId(): ?int
91: {
92: return $this->parentId;
93: }
94:
95: public function replacesOffset(): bool
96: {
97: return $this->replacesOffset;
98: }
99:
100: }
101: