1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\Node\Property;
4:
5: use PhpParser\Node\Expr\AssignRef;
6: use PhpParser\Node\Expr\PropertyFetch;
7: use PhpParser\Node\Expr\StaticPropertyFetch;
8: use PHPStan\Analyser\Scope;
9: use PHPStan\Node\ClassPropertyNode;
10: use PHPStan\Node\PropertyAssignNode;
11:
12: /**
13: * @api
14: */
15: final class PropertyWrite
16: {
17:
18: public function __construct(
19: private PropertyFetch|StaticPropertyFetch $fetch,
20: private Scope $scope,
21: private bool $promotedPropertyWrite,
22: private ClassPropertyNode|PropertyAssignNode|AssignRef|null $originalNode = null,
23: )
24: {
25: }
26:
27: /**
28: * @return PropertyFetch|StaticPropertyFetch
29: */
30: public function getFetch()
31: {
32: return $this->fetch;
33: }
34:
35: public function getScope(): Scope
36: {
37: return $this->scope;
38: }
39:
40: public function isPromotedPropertyWrite(): bool
41: {
42: return $this->promotedPropertyWrite;
43: }
44:
45: /**
46: * Whether the write happens through offset access ($this->prop[...] = ...)
47: * on an ArrayAccess object, which goes through offsetSet() rather than
48: * reassigning the property itself.
49: */
50: public function isViaOffsetAccess(): bool
51: {
52: if (!$this->originalNode instanceof PropertyAssignNode) {
53: return false;
54: }
55:
56: return $this->originalNode->isArrayAccessOffsetWrite($this->scope);
57: }
58:
59: }
60: