From: Josh Watzman Date: Mon, 27 Jan 2014 23:59:47 +0000 (-0800) Subject: Minor pedantic variable definition fixes X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=83dd42e478e8930c89dd464c529d369fa9fa07ab;p=web%2Fkonrad%2Ftwig.git 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. --- diff --git a/lib/Twig/Compiler.php b/lib/Twig/Compiler.php index 7a87cf8..bb6b129 100644 --- a/lib/Twig/Compiler.php +++ b/lib/Twig/Compiler.php @@ -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() diff --git a/lib/Twig/ExpressionParser.php b/lib/Twig/ExpressionParser.php index bd8ee45..25f47a1 100644 --- a/lib/Twig/ExpressionParser.php +++ b/lib/Twig/ExpressionParser.php @@ -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 (:)'); diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index 9b4974a..922b5ea 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -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); } diff --git a/lib/Twig/Lexer.php b/lib/Twig/Lexer.php index 8955fca..ad3ec7d 100644 --- a/lib/Twig/Lexer.php +++ b/lib/Twig/Lexer.php @@ -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); } diff --git a/lib/Twig/Node/Expression/Call.php b/lib/Twig/Node/Expression/Call.php index dba9b0e..d019696 100644 --- a/lib/Twig/Node/Expression/Call.php +++ b/lib/Twig/Node/Expression/Call.php @@ -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; diff --git a/lib/Twig/Template.php b/lib/Twig/Template.php index b9210b0..b13df5d 100644 --- a/lib/Twig/Template.php +++ b/lib/Twig/Template.php @@ -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) { diff --git a/lib/Twig/Token.php b/lib/Twig/Token.php index f3e3501..4411d7b 100644 --- a/lib/Twig/Token.php +++ b/lib/Twig/Token.php @@ -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); } /** diff --git a/lib/Twig/TokenStream.php b/lib/Twig/TokenStream.php index f3c3cbb..22f0428 100644 --- a/lib/Twig/TokenStream.php +++ b/lib/Twig/TokenStream.php @@ -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 );