Repository navigation
Expand file tree
/
Copy pathPropertyWrite.php
More file actions
82 lines (68 loc) · 1.87 KB
/
Copy pathPropertyWrite.php
File metadata and controls
82 lines (68 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php declare(strict_types = 1);
namespace PHPStan\Node\Property;
use PhpParser\Node\Expr\AssignRef;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\StaticPropertyFetch;
use PhpParser\Node\Param;
use PHPStan\Analyser\Scope;
use PHPStan\Node\ClassPropertyNode;
use PHPStan\Node\PropertyAssignNode;
use PHPStan\Turbo\ReferencedByTurboExtension;
/**
* @api
*/
#[ReferencedByTurboExtension(key: 'propertyWrite')]
final class PropertyWrite
{
public function __construct(
private PropertyFetch|StaticPropertyFetch $fetch,
private Scope $scope,
private bool $promotedPropertyWrite,
private ClassPropertyNode|PropertyAssignNode|AssignRef|null $originalNode = null,
)
{
}
/**
* @return PropertyFetch|StaticPropertyFetch
*/
public function getFetch()
{
return $this->fetch;
}
public function getScope(): Scope
{
return $this->scope;
}
public function isPromotedPropertyWrite(): bool
{
return $this->promotedPropertyWrite;
}
/**
* Whether the write binds the property to a reference ($this->prop = &$var,
* $var = &$this->prop, a by-ref promoted parameter), so what is later
* written to the property can be read through the other side.
*/
public function isByReference(): bool
{
if ($this->originalNode instanceof AssignRef) {
return true;
}
if (!$this->originalNode instanceof ClassPropertyNode) {
return false;
}
$propertyNode = $this->originalNode->getOriginalNode();
return $propertyNode instanceof Param && $propertyNode->byRef;
}
/**
* Whether the write happens through offset access ($this->prop[...] = ...)
* on an ArrayAccess object, which goes through offsetSet() rather than
* reassigning the property itself.
*/
public function isViaOffsetAccess(): bool
{
if (!$this->originalNode instanceof PropertyAssignNode) {
return false;
}
return $this->originalNode->isArrayAccessOffsetWrite($this->scope);
}
}