mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-15 03:46:39 +00:00
Minor pedantic variable definition fixes
Fixes a couple pedantic issues with variables not always being defined and passing a couple unused variables to error handling functions.
This commit is contained in:
@@ -208,7 +208,7 @@ class Twig_Compiler implements Twig_CompilerInterface
|
||||
public function addDebugInfo(Twig_NodeInterface $node)
|
||||
{
|
||||
if ($node->getLine() != $this->lastLine) {
|
||||
$this->write("// line {$node->getLine()}\n");
|
||||
$this->write(sprintf("// line %d\n", $node->getLine()));
|
||||
|
||||
// when mbstring.func_overload is set to 2
|
||||
// mb_substr_count() replaces substr_count()
|
||||
|
||||
@@ -172,7 +172,7 @@ class Twig_ExpressionParser
|
||||
} elseif ($token->test(Twig_Token::PUNCTUATION_TYPE, '{')) {
|
||||
$node = $this->parseHashExpression();
|
||||
} else {
|
||||
throw new Twig_Error_Syntax(sprintf('Unexpected token "%s" of value "%s"', Twig_Token::typeToEnglish($token->getType(), $token->getLine()), $token->getValue()), $token->getLine(), $this->parser->getFilename());
|
||||
throw new Twig_Error_Syntax(sprintf('Unexpected token "%s" of value "%s"', Twig_Token::typeToEnglish($token->getType()), $token->getValue()), $token->getLine(), $this->parser->getFilename());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,7 +263,7 @@ class Twig_ExpressionParser
|
||||
} else {
|
||||
$current = $stream->getCurrent();
|
||||
|
||||
throw new Twig_Error_Syntax(sprintf('A hash key must be a quoted string, a number, a name, or an expression enclosed in parentheses (unexpected token "%s" of value "%s"', Twig_Token::typeToEnglish($current->getType(), $current->getLine()), $current->getValue()), $current->getLine(), $this->parser->getFilename());
|
||||
throw new Twig_Error_Syntax(sprintf('A hash key must be a quoted string, a number, a name, or an expression enclosed in parentheses (unexpected token "%s" of value "%s"', Twig_Token::typeToEnglish($current->getType()), $current->getValue()), $current->getLine(), $this->parser->getFilename());
|
||||
}
|
||||
|
||||
$stream->expect(Twig_Token::PUNCTUATION_TYPE, ':', 'A hash key must be followed by a colon (:)');
|
||||
|
||||
@@ -1375,6 +1375,8 @@ function twig_test_iterable($value)
|
||||
*/
|
||||
function twig_include(Twig_Environment $env, $context, $template, $variables = array(), $withContext = true, $ignoreMissing = false, $sandboxed = false)
|
||||
{
|
||||
$alreadySandboxed = false;
|
||||
$sandbox = null;
|
||||
if ($withContext) {
|
||||
$variables = array_merge($context, $variables);
|
||||
}
|
||||
|
||||
+3
-1
@@ -80,6 +80,8 @@ class Twig_Lexer implements Twig_LexerInterface
|
||||
if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) {
|
||||
$mbEncoding = mb_internal_encoding();
|
||||
mb_internal_encoding('ASCII');
|
||||
} else {
|
||||
$mbEncoding = null;
|
||||
}
|
||||
|
||||
$this->code = str_replace(array("\r\n", "\r"), "\n", $code);
|
||||
@@ -130,7 +132,7 @@ class Twig_Lexer implements Twig_LexerInterface
|
||||
throw new Twig_Error_Syntax(sprintf('Unclosed "%s"', $expect), $lineno, $this->filename);
|
||||
}
|
||||
|
||||
if (isset($mbEncoding)) {
|
||||
if ($mbEncoding) {
|
||||
mb_internal_encoding($mbEncoding);
|
||||
}
|
||||
|
||||
|
||||
@@ -165,7 +165,7 @@ abstract class Twig_Node_Expression_Call extends Twig_Node_Expression
|
||||
}
|
||||
|
||||
if (!empty($parameters)) {
|
||||
throw new Twig_Error_Syntax(sprintf('Unknown argument%s "%s" for %s "%s".', count($parameters) > 1 ? 's' : '' , implode('", "', array_keys($parameters)), $this->getAttribute('type'), $this->getAttribute('name')));
|
||||
throw new Twig_Error_Syntax(sprintf('Unknown argument%s "%s" for %s "%s".', count($parameters) > 1 ? 's' : '', implode('", "', array_keys($parameters)), $this->getAttribute('type'), $this->getAttribute('name')));
|
||||
}
|
||||
|
||||
return $arguments;
|
||||
|
||||
@@ -127,7 +127,6 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
{
|
||||
$name = (string) $name;
|
||||
|
||||
$template = null;
|
||||
if (isset($blocks[$name])) {
|
||||
$template = $blocks[$name][0];
|
||||
$block = $blocks[$name][1];
|
||||
@@ -135,6 +134,9 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
} elseif (isset($this->blocks[$name])) {
|
||||
$template = $this->blocks[$name][0];
|
||||
$block = $this->blocks[$name][1];
|
||||
} else {
|
||||
$template = null;
|
||||
$block = null;
|
||||
}
|
||||
|
||||
if (null !== $template) {
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ class Twig_Token
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return sprintf('%s(%s)', self::typeToString($this->type, true, $this->lineno), $this->value);
|
||||
return sprintf('%s(%s)', self::typeToString($this->type, true), $this->value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -87,8 +87,8 @@ class Twig_TokenStream
|
||||
$line = $token->getLine();
|
||||
throw new Twig_Error_Syntax(sprintf('%sUnexpected token "%s" of value "%s" ("%s" expected%s)',
|
||||
$message ? $message.'. ' : '',
|
||||
Twig_Token::typeToEnglish($token->getType(), $line), $token->getValue(),
|
||||
Twig_Token::typeToEnglish($type, $line), $value ? sprintf(' with value "%s"', $value) : ''),
|
||||
Twig_Token::typeToEnglish($token->getType()), $token->getValue(),
|
||||
Twig_Token::typeToEnglish($type), $value ? sprintf(' with value "%s"', $value) : ''),
|
||||
$line,
|
||||
$this->filename
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user