Repository navigation
Expand file tree
/
Copy pathUsedAsStringNode.php
More file actions
66 lines (58 loc) · 2.06 KB
/
Copy pathUsedAsStringNode.php
File metadata and controls
66 lines (58 loc) · 2.06 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
<?php declare(strict_types = 1);
namespace PHPStan\Node;
use Override;
use PhpParser\Node\Expr;
use PhpParser\NodeAbstract;
/**
* Fired for every node whose value is used as a string. This covers both
* values coerced to string and values stored into a string slot:
*
* - echo and print arguments, the operand of a (string) cast,
* - string concatenation (`.` and `.=`), string interpolation/heredoc,
* - inline HTML,
* - the dynamic name of a property/method/constant access or a variable
* variable (`$foo->{$s}`, `$$s`, etc.),
* - the value assigned to a variable when that value is a string,
* - the value assigned to a native property whose type allows a string (a plain
* `string` or a union containing `string`, e.g. `string|int`) when the assigned
* value can be coerced to a string in the current typing mode (so a
* non-`Stringable` object assigned to such a slot does not fire, while a
* `Stringable` assigned to it in weak mode does), and the default of a native
* `string`-typed property,
* - an argument passed to a native parameter whose type allows a string (a plain
* `string` or a union containing `string`, e.g. `string|int`), including
* closures and arrow functions, and the default of a native `string`-typed
* parameter.
*
* Concatenations and interpolated strings are reported once for the whole
* expression instead of once per nested operand, so a rule can interpret the
* built string as a single unit. When the assigned value already produces its
* own node (a concatenation, interpolation or `(string)` cast), the enclosing
* assignment does not report it a second time.
*
* @api
*/
final class UsedAsStringNode extends NodeAbstract implements VirtualNode
{
public function __construct(private Expr $expr)
{
parent::__construct($expr->getAttributes());
}
public function getExpr(): Expr
{
return $this->expr;
}
#[Override]
public function getType(): string
{
return 'PHPStan_Node_UsedAsStringNode';
}
/**
* @return string[]
*/
#[Override]
public function getSubNodeNames(): array
{
return [];
}
}