mirror of
https://github.com/getgrav/grav.git
synced 2026-03-18 02:21:11 +01:00
Code style fix on Twig tags
This commit is contained in:
@@ -12,7 +12,7 @@ class TwigNodeMarkdown extends \Twig_Node implements \Twig_NodeOutputInterface
|
||||
{
|
||||
public function __construct(\Twig_Node $body, $lineno, $tag = 'markdown')
|
||||
{
|
||||
parent::__construct(array('body' => $body), array(), $lineno, $tag);
|
||||
parent::__construct(['body' => $body], [], $lineno, $tag);
|
||||
}
|
||||
/**
|
||||
* Compiles the node to PHP.
|
||||
|
||||
@@ -24,20 +24,17 @@ class TwigNodeSwitch extends \Twig_Node implements \Twig_NodeOutputInterface
|
||||
{
|
||||
$compiler
|
||||
->addDebugInfo($this)
|
||||
->write("switch (")
|
||||
->write('switch (')
|
||||
->subcompile($this->getNode('value'))
|
||||
->raw(") {\n")
|
||||
->indent();
|
||||
|
||||
foreach ($this->getNode('cases') as $case)
|
||||
{
|
||||
if (!$case->hasNode('body'))
|
||||
{
|
||||
foreach ($this->getNode('cases') as $case) {
|
||||
if (!$case->hasNode('body')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($case->getNode('values') as $value)
|
||||
{
|
||||
foreach ($case->getNode('values') as $value) {
|
||||
$compiler
|
||||
->write('case ')
|
||||
->subcompile($value)
|
||||
@@ -53,8 +50,7 @@ class TwigNodeSwitch extends \Twig_Node implements \Twig_NodeOutputInterface
|
||||
->write("}\n");
|
||||
}
|
||||
|
||||
if ($this->hasNode('default') && $this->getNode('default') !== null)
|
||||
{
|
||||
if ($this->hasNode('default') && $this->getNode('default') !== null) {
|
||||
$compiler
|
||||
->write("default:\n")
|
||||
->write("{\n")
|
||||
|
||||
@@ -37,8 +37,7 @@ class TwigTokenParserSwitch extends \Twig_TokenParser
|
||||
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
|
||||
|
||||
// There can be some whitespace between the {% switch %} and first {% case %} tag.
|
||||
while ($stream->getCurrent()->getType() == \Twig_Token::TEXT_TYPE && trim($stream->getCurrent()->getValue()) == '')
|
||||
{
|
||||
while ($stream->getCurrent()->getType() === \Twig_Token::TEXT_TYPE && trim($stream->getCurrent()->getValue()) === '') {
|
||||
$stream->next();
|
||||
}
|
||||
|
||||
@@ -47,56 +46,45 @@ class TwigTokenParserSwitch extends \Twig_TokenParser
|
||||
$expressionParser = $this->parser->getExpressionParser();
|
||||
|
||||
$default = null;
|
||||
$cases = array();
|
||||
$cases = [];
|
||||
$end = false;
|
||||
|
||||
while (!$end)
|
||||
{
|
||||
while (!$end) {
|
||||
$next = $stream->next();
|
||||
|
||||
switch ($next->getValue())
|
||||
{
|
||||
switch ($next->getValue()) {
|
||||
case 'case':
|
||||
{
|
||||
$values = array();
|
||||
$values = [];
|
||||
|
||||
while (true)
|
||||
{
|
||||
$values[] = $expressionParser->parsePrimaryExpression();
|
||||
// Multiple allowed values?
|
||||
if ($stream->test(\Twig_Token::OPERATOR_TYPE, 'or'))
|
||||
{
|
||||
$stream->next();
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
while (true) {
|
||||
$values[] = $expressionParser->parsePrimaryExpression();
|
||||
// Multiple allowed values?
|
||||
if ($stream->test(\Twig_Token::OPERATOR_TYPE, 'or')) {
|
||||
$stream->next();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
|
||||
$body = $this->parser->subparse(array($this, 'decideIfFork'));
|
||||
$cases[] = new \Twig_Node([
|
||||
'values' => new \Twig_Node($values),
|
||||
'body' => $body
|
||||
]);
|
||||
break;
|
||||
|
||||
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
|
||||
$body = $this->parser->subparse(array($this, 'decideIfFork'));
|
||||
$cases[] = new \Twig_Node(array(
|
||||
'values' => new \Twig_Node($values),
|
||||
'body' => $body
|
||||
));
|
||||
break;
|
||||
}
|
||||
case 'default':
|
||||
{
|
||||
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
|
||||
$default = $this->parser->subparse(array($this, 'decideIfEnd'));
|
||||
break;
|
||||
}
|
||||
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
|
||||
$default = $this->parser->subparse(array($this, 'decideIfEnd'));
|
||||
break;
|
||||
|
||||
case 'endswitch':
|
||||
{
|
||||
$end = true;
|
||||
break;
|
||||
}
|
||||
$end = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
throw new \Twig_Error_Syntax(sprintf('Unexpected end of template. Twig was looking for the following tags "case", "default", or "endswitch" to close the "switch" block started at line %d)', $lineno), -1);
|
||||
}
|
||||
throw new \Twig_Error_Syntax(sprintf('Unexpected end of template. Twig was looking for the following tags "case", "default", or "endswitch" to close the "switch" block started at line %d)', $lineno), -1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +115,6 @@ class TwigTokenParserSwitch extends \Twig_TokenParser
|
||||
return $token->test(array('endswitch'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user