Skip to content

Commit fc61537

Browse files
committed
Replace use of deprecated NameExpression with ContextVariable
1 parent b7dad24 commit fc61537

File tree

7 files changed

+16
-18
lines changed

7 files changed

+16
-18
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"name": "Jeroen Versteeg"
99
}
1010
],
11-
"version": "1.0.3",
11+
"version": "1.0.4",
1212
"autoload": {
1313
"psr-4": {
1414
"AlisQI\\TwigQI\\": "src/"

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Inspection/BadArgumentCountInMacroCall.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use AlisQI\TwigQI\Helper\NodeLocation;
88
use Twig\Environment;
99
use Twig\Node\Expression\MacroReferenceExpression;
10-
use Twig\Node\Expression\NameExpression;
10+
use Twig\Node\Expression\Variable\ContextVariable;
1111
use Twig\Node\MacroNode;
1212
use Twig\Node\Node;
1313
use Twig\NodeVisitor\NodeVisitorInterface;
@@ -47,8 +47,8 @@ public function enterNode(Node $node, Environment $env): Node
4747
];
4848
}
4949

50-
// add 'varargs' to signature if it's used anywhere (i.e., there's a NameExpression that uses it)
51-
if ($this->hasVarArgsNameExpressionDescendant($node)) {
50+
// add 'varargs' to signature if it's used anywhere (i.e., there's a ContextVariable that uses it)
51+
if ($this->hasVarArgsContextVariableDescendant($node)) {
5252
$signature[] = ['name' => MacroNode::VARARGS_NAME, 'required' => false];
5353
}
5454

@@ -114,16 +114,16 @@ public function getPriority(): int
114114
return 0;
115115
}
116116

117-
private function hasVarArgsNameExpressionDescendant(Node $node): bool {
117+
private function hasVarArgsContextVariableDescendant(Node $node): bool {
118118
if (
119-
$node instanceof NameExpression &&
119+
$node instanceof ContextVariable &&
120120
$node->getAttribute('name') === MacroNode::VARARGS_NAME
121121
) {
122122
return true;
123123
}
124124

125125
foreach ($node as $childNode) {
126-
if ($this->hasVarArgsNameExpressionDescendant($childNode)) {
126+
if ($this->hasVarArgsContextVariableDescendant($childNode)) {
127127
return true;
128128
}
129129
}

src/Inspection/InvalidConstant.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Twig\Environment;
99
use Twig\Node\Expression\ConstantExpression;
1010
use Twig\Node\Expression\FunctionExpression;
11-
use Twig\Node\Expression\NameExpression;
11+
use Twig\Node\Expression\Variable\ContextVariable;
1212
use Twig\Node\Node;
1313
use Twig\NodeVisitor\NodeVisitorInterface;
1414

@@ -75,7 +75,7 @@ private function checkConstantAndObject(Node $constant, Node $name): ?string
7575
return 'first argument must be string';
7676
}
7777

78-
if (!$name instanceof NameExpression) {
78+
if (!$name instanceof ContextVariable) {
7979
return 'second argument must be a variable name';
8080
}
8181

src/Inspection/InvalidDotOperation.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Twig\Environment;
1212
use Twig\Node\Expression\ArrowFunctionExpression;
1313
use Twig\Node\Expression\GetAttrExpression;
14-
use Twig\Node\Expression\NameExpression;
14+
use Twig\Node\Expression\Variable\ContextVariable;
1515
use Twig\Node\ForNode;
1616
use Twig\Node\MacroNode;
1717
use Twig\Node\ModuleNode;
@@ -73,7 +73,7 @@ public function enterNode(Node $node, Environment $env): Node
7373
if (
7474
$node instanceof GetAttrExpression &&
7575
$node->getAttribute('type') !== Template::ARRAY_CALL &&
76-
($nameNode = $node->getNode('node')) instanceof NameExpression
76+
($nameNode = $node->getNode('node')) instanceof ContextVariable
7777
) {
7878
$location = new NodeLocation($node);
7979
$name = $nameNode->getAttribute('name');
@@ -188,7 +188,7 @@ private function extractScopedVariableTypes(ArrowFunctionExpression|ForNode|SetN
188188

189189
$keyType = $valueType = 'mixed';
190190

191-
if (($seqNode = $node->getNode('seq')) instanceof NameExpression) {
191+
if (($seqNode = $node->getNode('seq')) instanceof ContextVariable) {
192192
$seqName = $seqNode->getAttribute('name');
193193

194194
if ((null !== $seqType = $this->getCurrentVariableTypeCollector()->getDeclaredType($seqName))) {

src/Inspection/RequiredMacroArgumentAfterOptional.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
use AlisQI\TwigQI\Helper\NodeLocation;
88
use Twig\Environment;
9-
use Twig\Node\Expression\MethodCallExpression;
10-
use Twig\Node\Expression\NameExpression;
119
use Twig\Node\MacroNode;
1210
use Twig\Node\Node;
1311
use Twig\NodeVisitor\NodeVisitorInterface;

src/Inspection/UndeclaredVariableInMacro.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use Twig\Environment;
88
use Twig\Node\Expression\ArrowFunctionExpression;
9-
use Twig\Node\Expression\NameExpression;
9+
use Twig\Node\Expression\Variable\ContextVariable;
1010
use Twig\Node\ForNode;
1111
use Twig\Node\MacroNode;
1212
use Twig\Node\Node;
@@ -44,7 +44,7 @@ public function enterNode(Node $node, Environment $env): Node
4444

4545
if (
4646
$this->currentMacro &&
47-
$node instanceof NameExpression
47+
$node instanceof ContextVariable
4848
) {
4949
$this->checkVariableIsDeclared($node);
5050
}
@@ -102,7 +102,7 @@ private function getDeclaredVariablesFor(Node $node): array
102102
return $variables;
103103
}
104104

105-
private function checkVariableIsDeclared(NameExpression $node): void
105+
private function checkVariableIsDeclared(ContextVariable $node): void
106106
{
107107
$variableName = $node->getAttribute('name');
108108

0 commit comments

Comments
 (0)