Skip to content

Commit eca86f1

Browse files
committed
Remove obsolete code
1 parent 5da4b58 commit eca86f1

File tree

1 file changed

+11
-67
lines changed

1 file changed

+11
-67
lines changed

src/ExpressionParser.php

Lines changed: 11 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -641,20 +641,6 @@ public function parseFilterExpressionRaw($node)
641641
*/
642642
public function parseArguments()
643643
{
644-
$namedArguments = false;
645-
$definition = false;
646-
if (func_num_args() > 2) {
647-
trigger_deprecation('twig/twig', '3.15', 'Passing a third argument ($allowArrow) to "%s()" is deprecated.', __METHOD__);
648-
}
649-
if (func_num_args() > 1) {
650-
trigger_deprecation('twig/twig', '3.15', 'Passing a second argument ($definition) to "%s()" is deprecated.', __METHOD__);
651-
$definition = func_get_arg(1);
652-
}
653-
if (func_num_args() > 0) {
654-
trigger_deprecation('twig/twig', '3.15', 'Passing a first argument ($namedArguments) to "%s()" is deprecated.', __METHOD__);
655-
$namedArguments = func_get_arg(0);
656-
}
657-
658644
$args = [];
659645
$stream = $this->parser->getStream();
660646

@@ -670,51 +656,28 @@ public function parseArguments()
670656
}
671657
}
672658

673-
if ($definition) {
674-
$token = $stream->expect(Token::NAME_TYPE, null, 'An argument must be a name');
675-
$value = new NameExpression($token->getValue(), $this->parser->getCurrentToken()->getLine());
659+
if ($stream->nextIf(Token::SPREAD_TYPE)) {
660+
$hasSpread = true;
661+
$value = new SpreadUnary($this->parseExpression(), $stream->getCurrent()->getLine());
662+
} elseif ($hasSpread) {
663+
throw new SyntaxError('Normal arguments must be placed before argument unpacking.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
676664
} else {
677-
if ($stream->nextIf(Token::SPREAD_TYPE)) {
678-
$hasSpread = true;
679-
$value = new SpreadUnary($this->parseExpression(), $stream->getCurrent()->getLine());
680-
} elseif ($hasSpread) {
681-
throw new SyntaxError('Normal arguments must be placed before argument unpacking.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
682-
} else {
683-
$value = $this->parseExpression();
684-
}
665+
$value = $this->parseExpression();
685666
}
686667

687668
$name = null;
688-
if (($token = $stream->nextIf(Token::OPERATOR_TYPE, '=')) || (!$definition && $token = $stream->nextIf(Token::PUNCTUATION_TYPE, ':'))) {
669+
if (($token = $stream->nextIf(Token::OPERATOR_TYPE, '=')) || ($token = $stream->nextIf(Token::PUNCTUATION_TYPE, ':'))) {
689670
if (!$value instanceof NameExpression) {
690671
throw new SyntaxError(\sprintf('A parameter name must be a string, "%s" given.', $value::class), $token->getLine(), $stream->getSourceContext());
691672
}
692673
$name = $value->getAttribute('name');
693-
694-
if ($definition) {
695-
$value = $this->getPrimary();
696-
697-
if (!$this->checkConstantExpression($value)) {
698-
throw new SyntaxError('A default value for an argument must be a constant (a boolean, a string, a number, a sequence, or a mapping).', $token->getLine(), $stream->getSourceContext());
699-
}
700-
} else {
701-
$value = $this->parseExpression();
702-
}
674+
$value = $this->parseExpression();
703675
}
704676

705-
if ($definition) {
706-
if (null === $name) {
707-
$name = $value->getAttribute('name');
708-
$value = new ConstantExpression(null, $this->parser->getCurrentToken()->getLine());
709-
$value->setAttribute('is_implicit', true);
710-
}
711-
$args[$name] = $value;
677+
if (null === $name) {
678+
$args[] = $value;
712679
} else {
713-
if (null === $name) {
714-
$args[] = $value;
715-
} else {
716-
$args[$name] = $value;
717-
}
680+
$args[$name] = $value;
718681
}
719682
}
720683
$stream->expect(Token::PUNCTUATION_TYPE, ')', 'A list of arguments must be closed by a parenthesis');
@@ -857,25 +820,6 @@ private function getFilter(string $name, int $line): TwigFilter
857820
return $filter;
858821
}
859822

860-
// checks that the node only contains "constant" elements
861-
// to be removed in 4.0
862-
private function checkConstantExpression(Node $node): bool
863-
{
864-
if (!($node instanceof ConstantExpression || $node instanceof ArrayExpression
865-
|| $node instanceof NegUnary || $node instanceof PosUnary
866-
)) {
867-
return false;
868-
}
869-
870-
foreach ($node as $n) {
871-
if (!$this->checkConstantExpression($n)) {
872-
return false;
873-
}
874-
}
875-
876-
return true;
877-
}
878-
879823
private function setDeprecationCheck(bool $deprecationCheck): bool
880824
{
881825
$current = $this->deprecationCheck;

0 commit comments

Comments
 (0)