-
Notifications
You must be signed in to change notification settings - Fork 568
Expand file tree
/
Copy pathDeprecatedInterpolatedStringVisitor.php
More file actions
56 lines (46 loc) · 1.23 KB
/
DeprecatedInterpolatedStringVisitor.php
File metadata and controls
56 lines (46 loc) · 1.23 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
<?php declare(strict_types = 1);
namespace PHPStan\Parser;
use Override;
use PhpParser\Node;
use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Scalar\InterpolatedString;
use PhpParser\NodeVisitorAbstract;
use PhpParser\Token;
use PHPStan\DependencyInjection\AutowiredService;
#[AutowiredService]
final class DeprecatedInterpolatedStringVisitor extends NodeVisitorAbstract implements TokenAwareVisitor
{
public const ATTRIBUTE_NAME = 'isDeprecatedInterpolatedString';
/**
* @var Token[]
*/
protected array $tokens = [];
#[Override]
public function setTokens(array $tokens): void
{
$this->tokens = $tokens;
}
#[Override]
public function enterNode(Node $node): ?Node
{
if (!$node instanceof InterpolatedString) {
return null;
}
foreach ($node->parts as $part) {
if (!$part instanceof Variable && !($part instanceof ArrayDimFetch && $part->var instanceof Variable)) {
continue;
}
$startTokenPos = $part->getStartTokenPos();
if (!isset($this->tokens[$startTokenPos])) {
continue;
}
$startToken = (string) $this->tokens[$startTokenPos];
if ($startToken !== '${') {
continue;
}
$node->setAttribute(self::ATTRIBUTE_NAME, true);
}
return null;
}
}