Skip to content

Commit

Permalink
Replace use of deprecated NameExpression with ContextVariable
Browse files Browse the repository at this point in the history
  • Loading branch information
drjayvee committed Nov 21, 2024
1 parent b7dad24 commit fc61537
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"name": "Jeroen Versteeg"
}
],
"version": "1.0.3",
"version": "1.0.4",
"autoload": {
"psr-4": {
"AlisQI\\TwigQI\\": "src/"
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions src/Inspection/BadArgumentCountInMacroCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use AlisQI\TwigQI\Helper\NodeLocation;
use Twig\Environment;
use Twig\Node\Expression\MacroReferenceExpression;
use Twig\Node\Expression\NameExpression;
use Twig\Node\Expression\Variable\ContextVariable;
use Twig\Node\MacroNode;
use Twig\Node\Node;
use Twig\NodeVisitor\NodeVisitorInterface;
Expand Down Expand Up @@ -47,8 +47,8 @@ public function enterNode(Node $node, Environment $env): Node
];
}

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

Expand Down Expand Up @@ -114,16 +114,16 @@ public function getPriority(): int
return 0;
}

private function hasVarArgsNameExpressionDescendant(Node $node): bool {
private function hasVarArgsContextVariableDescendant(Node $node): bool {
if (
$node instanceof NameExpression &&
$node instanceof ContextVariable &&
$node->getAttribute('name') === MacroNode::VARARGS_NAME
) {
return true;
}

foreach ($node as $childNode) {
if ($this->hasVarArgsNameExpressionDescendant($childNode)) {
if ($this->hasVarArgsContextVariableDescendant($childNode)) {
return true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Inspection/InvalidConstant.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Twig\Environment;
use Twig\Node\Expression\ConstantExpression;
use Twig\Node\Expression\FunctionExpression;
use Twig\Node\Expression\NameExpression;
use Twig\Node\Expression\Variable\ContextVariable;
use Twig\Node\Node;
use Twig\NodeVisitor\NodeVisitorInterface;

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

if (!$name instanceof NameExpression) {
if (!$name instanceof ContextVariable) {
return 'second argument must be a variable name';
}

Expand Down
6 changes: 3 additions & 3 deletions src/Inspection/InvalidDotOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Twig\Environment;
use Twig\Node\Expression\ArrowFunctionExpression;
use Twig\Node\Expression\GetAttrExpression;
use Twig\Node\Expression\NameExpression;
use Twig\Node\Expression\Variable\ContextVariable;
use Twig\Node\ForNode;
use Twig\Node\MacroNode;
use Twig\Node\ModuleNode;
Expand Down Expand Up @@ -73,7 +73,7 @@ public function enterNode(Node $node, Environment $env): Node
if (
$node instanceof GetAttrExpression &&
$node->getAttribute('type') !== Template::ARRAY_CALL &&
($nameNode = $node->getNode('node')) instanceof NameExpression
($nameNode = $node->getNode('node')) instanceof ContextVariable
) {
$location = new NodeLocation($node);
$name = $nameNode->getAttribute('name');
Expand Down Expand Up @@ -188,7 +188,7 @@ private function extractScopedVariableTypes(ArrowFunctionExpression|ForNode|SetN

$keyType = $valueType = 'mixed';

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

if ((null !== $seqType = $this->getCurrentVariableTypeCollector()->getDeclaredType($seqName))) {
Expand Down
2 changes: 0 additions & 2 deletions src/Inspection/RequiredMacroArgumentAfterOptional.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

use AlisQI\TwigQI\Helper\NodeLocation;
use Twig\Environment;
use Twig\Node\Expression\MethodCallExpression;
use Twig\Node\Expression\NameExpression;
use Twig\Node\MacroNode;
use Twig\Node\Node;
use Twig\NodeVisitor\NodeVisitorInterface;
Expand Down
6 changes: 3 additions & 3 deletions src/Inspection/UndeclaredVariableInMacro.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Twig\Environment;
use Twig\Node\Expression\ArrowFunctionExpression;
use Twig\Node\Expression\NameExpression;
use Twig\Node\Expression\Variable\ContextVariable;
use Twig\Node\ForNode;
use Twig\Node\MacroNode;
use Twig\Node\Node;
Expand Down Expand Up @@ -44,7 +44,7 @@ public function enterNode(Node $node, Environment $env): Node

if (
$this->currentMacro &&
$node instanceof NameExpression
$node instanceof ContextVariable
) {
$this->checkVariableIsDeclared($node);
}
Expand Down Expand Up @@ -102,7 +102,7 @@ private function getDeclaredVariablesFor(Node $node): array
return $variables;
}

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

Expand Down

0 comments on commit fc61537

Please sign in to comment.