Skip to content
Permalink
Browse files

PhpWriter: removed short ternary deprecation notice

  • Loading branch information
dg committed Dec 21, 2019
1 parent ccc6942 commit 29efb77ae346798088b3f14762af2ad69749982a
Showing with 2 additions and 15 deletions.
  1. +2 −11 src/Latte/Compiler/PhpWriter.php
  2. +0 −4 tests/Latte/PhpWriter.formatArgs().phpt
@@ -251,33 +251,24 @@ public function replaceFunctionsPass(MacroTokens $tokens): MacroTokens
public function shortTernaryPass(MacroTokens $tokens): MacroTokens
{
$res = new MacroTokens;
$inTernary = $tmp = [];
$errors = 0;
$inTernary = [];
while ($tokens->nextToken()) {
if ($tokens->isCurrent('?') && $tokens->isNext() && !$tokens->isNext(',', ')', ']', '|')) {
if ($tokens->isCurrent('?') && $tokens->isNext() && !$tokens->isNext(',', ')', ']', '|', '[')) {
$inTernary[] = $tokens->depth;
$tmp[] = $tokens->isNext('[');

} elseif ($tokens->isCurrent(':')) {
array_pop($inTernary);
array_pop($tmp);

} elseif ($tokens->isCurrent(',', ')', ']', '|') && end($inTernary) === $tokens->depth + $tokens->isCurrent(')', ']')) {
$res->append(' : null');
array_pop($inTernary);
$errors += array_pop($tmp);
}
$res->append($tokens->currentToken());
}

if ($inTernary) {
$errors += array_pop($tmp);
$res->append(' : null');
}
if ($errors) {
$tokens->reset();
trigger_error('Short ternary operator requires parentheses around array in ' . $tokens->joinAll(), E_USER_DEPRECATED);
}
return $res;
}

@@ -66,10 +66,6 @@ test(function () { // short ternary operators
Assert::same('$c ?: ($a ?: $b)', formatArgs('$c ?: ($a ?: $b)'));
Assert::same('$c ? ($a ?: $b) : null', formatArgs('$c ? ($a ?: $b)'));
Assert::same('$a ?(1) : null', formatArgs('$a?(1)')); // with braces

Assert::error(function () {
Assert::same('$a ?[1] : null', formatArgs('$a?[1]')); // missing braces
}, E_USER_DEPRECATED, 'Short ternary operator requires parentheses around array in $a ?[1]');
});


0 comments on commit 29efb77

Please sign in to comment.
You can’t perform that action at this time.