-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathPropertyAccessNode.php
More file actions
78 lines (64 loc) · 1.65 KB
/
PropertyAccessNode.php
File metadata and controls
78 lines (64 loc) · 1.65 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
<?php declare(strict_types = 1);
namespace PHPStan\PhpDocParser\Ast\Type;
use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\NodeAttributes;
use function array_map;
use function implode;
/**
* Represents a property access expression in conditional types.
*/
class PropertyAccessNode implements Node
{
use NodeAttributes;
public const HOLDER_SELF = 'self';
public const HOLDER_PARENT = 'parent';
public const HOLDER_STATIC = 'static';
public bool $isStatic;
/**
* For static access: 'self', 'parent', or 'static'
* For instance access: null (holder is implicitly $this)
*
* @var self::HOLDER_*|null
*/
public ?string $holder;
/** @var list<PropertyAccessPathItem> */
public array $path;
/**
* @param self::HOLDER_*|null $holder
* @param list<PropertyAccessPathItem> $path
*/
public function __construct(bool $isStatic, ?string $holder, array $path)
{
$this->isStatic = $isStatic;
$this->holder = $holder;
$this->path = $path;
}
public function __toString(): string
{
if ($this->isStatic) {
return $this->holder . '::$' . $this->path[0]->name;
}
$pathString = implode('->', array_map(
static fn (PropertyAccessPathItem $item): string => $item->name,
$this->path,
));
return '$this->' . $pathString;
}
/**
* @param array<string, mixed> $properties
*/
public static function __set_state(array $properties): self
{
$instance = new self(
$properties['isStatic'],
$properties['holder'],
$properties['path'],
);
if (isset($properties['attributes'])) {
foreach ($properties['attributes'] as $key => $value) {
$instance->setAttribute($key, $value);
}
}
return $instance;
}
}