-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathVariableParser.php
43 lines (34 loc) · 1.03 KB
/
VariableParser.php
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
<?php
namespace App\Parsers;
use App\Contexts\AbstractContext;
use App\Contexts\Variable as VariableContext;
use App\Parser\Settings;
use Microsoft\PhpParser\Node\Expression\Variable;
use Microsoft\PhpParser\PositionUtilities;
class VariableParser extends AbstractParser
{
/**
* @var VariableContext
*/
protected AbstractContext $context;
public function parse(Variable $node)
{
$this->context->name = $node->getName();
if (Settings::$capturePosition) {
$range = PositionUtilities::getRangeFromPosition(
$node->getStartPosition(),
mb_strlen($node->getText()),
$node->getRoot()->getFullText(),
);
if (Settings::$calculatePosition !== null) {
$range = Settings::adjustPosition($range);
}
$this->context->setPosition($range);
}
return $this->context;
}
public function initNewContext(): ?AbstractContext
{
return new VariableContext;
}
}