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: use PHPStan\Turbo\ReferencedByTurboExtension;
12:
13: /**
14: * @api
15: */
16: #[ReferencedByTurboExtension(key: 'propertyWrite')]
17: final class PropertyWrite
18: {
19:
20: public function __construct(
21: private PropertyFetch|StaticPropertyFetch $fetch,
22: private Scope $scope,
23: private bool $promotedPropertyWrite,
24: private ClassPropertyNode|PropertyAssignNode|AssignRef|null $originalNode = null,
25: )
26: {
27: }
28:
29: /**
30: * @return PropertyFetch|StaticPropertyFetch
31: */
32: public function getFetch()
33: {
34: return $this->fetch;
35: }
36:
37: public function getScope(): Scope
38: {
39: return $this->scope;
40: }
41:
42: public function isPromotedPropertyWrite(): bool
43: {
44: return $this->promotedPropertyWrite;
45: }
46:
47: /**
48: * Whether the write happens through offset access ($this->prop[...] = ...)
49: * on an ArrayAccess object, which goes through offsetSet() rather than
50: * reassigning the property itself.
51: */
52: public function isViaOffsetAccess(): bool
53: {
54: if (!$this->originalNode instanceof PropertyAssignNode) {
55: return false;
56: }
57:
58: return $this->originalNode->isArrayAccessOffsetWrite($this->scope);
59: }
60:
61: }
62: