Skip to content

Commit

Permalink
PhpWriter: removed short ternary deprecation notice
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Dec 23, 2019
1 parent b23225b commit ff5abcd
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions src/Latte/Compiler/PhpWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,33 +253,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 braces around array: ' . $tokens->joinAll(), E_USER_DEPRECATED);
}
return $res;
}

Expand Down

0 comments on commit ff5abcd

Please sign in to comment.