clean ups

This commit is contained in:
Possum
2015-04-24 16:57:11 +02:00
parent 7d5fe0fbd4
commit 2030482e4d
20 changed files with 70 additions and 47 deletions
+5 -6
View File
@@ -351,8 +351,7 @@ class Twig_Environment
*
* This method should not be used as a generic way to load templates.
*
* @param string $name The template name
* @param int $index The index if it is an embedded template
* @param string $template The template name
*
* @return Twig_Template A template instance representing the given template name
*
@@ -483,7 +482,7 @@ class Twig_Environment
/**
* Sets the Lexer instance.
*
* @param Twig_LexerInterface A Twig_LexerInterface instance
* @param Twig_LexerInterface $lexer A Twig_LexerInterface instance
*/
public function setLexer(Twig_LexerInterface $lexer)
{
@@ -522,7 +521,7 @@ class Twig_Environment
/**
* Sets the Parser instance.
*
* @param Twig_ParserInterface A Twig_ParserInterface instance
* @param Twig_ParserInterface $parser A Twig_ParserInterface instance
*/
public function setParser(Twig_ParserInterface $parser)
{
@@ -1271,11 +1270,11 @@ class Twig_Environment
if (false === @mkdir($dir, 0777, true)) {
clearstatcache(false, $dir);
if (!is_dir($dir)) {
throw new RuntimeException(sprintf("Unable to create the cache directory (%s).", $dir));
throw new RuntimeException(sprintf('Unable to create the cache directory (%s).', $dir));
}
}
} elseif (!is_writable($dir)) {
throw new RuntimeException(sprintf("Unable to write in the cache directory (%s).", $dir));
throw new RuntimeException(sprintf('Unable to write in the cache directory (%s).', $dir));
}
$tmpFile = tempnam($dir, basename($file));
+5 -1
View File
@@ -315,7 +315,7 @@ class Twig_ExpressionParser
{
switch ($name) {
case 'parent':
$args = $this->parseArguments();
$this->parseArguments();
if (!count($this->parser->getBlockStack())) {
throw new Twig_Error_Syntax('Calling "parent" outside a block is forbidden', $line, $this->parser->getFilename());
}
@@ -468,6 +468,10 @@ class Twig_ExpressionParser
*
* @param bool $namedArguments Whether to allow named arguments or not
* @param bool $definition Whether we are parsing arguments for a function definition
*
* @return Twig_Node
*
* @throws Twig_Error_Syntax
*/
public function parseArguments($namedArguments = false, $definition = false)
{
+13 -7
View File
@@ -921,7 +921,9 @@ function twig_reverse_filter(Twig_Environment $env, $item, $preserveKeys = false
/**
* Sorts an array.
*
* @param array $array An array
* @param array $array
*
* @return array
*/
function twig_sort_filter($array)
{
@@ -952,6 +954,8 @@ function twig_in_filter($value, $compare)
* @param string $strategy The escaping strategy
* @param string $charset The charset
* @param bool $autoescape Whether the function is called by the auto-escaping feature (true) or by the developer (false)
*
* @return string
*/
function twig_escape_filter(Twig_Environment $env, $string, $strategy = 'html', $charset = null, $autoescape = false)
{
@@ -1398,15 +1402,17 @@ function twig_test_iterable($value)
/**
* Renders a template.
*
* @param string|array $template The template to render or an array of templates to try consecutively
* @param array $variables The variables to pass to the template
* @param bool $with_context Whether to pass the current context variables or not
* @param bool $ignore_missing Whether to ignore missing templates or not
* @param bool $sandboxed Whether to sandbox the template or not
* @param Twig_Environment $env
* @param array $context
* @param string|array $template The template to render or an array of templates to try consecutively
* @param array $variables The variables to pass to the template
* @param bool $withContext
* @param bool $ignoreMissing Whether to ignore missing templates or not
* @param bool $sandboxed Whether to sandbox the template or not
*
* @return string The rendered template
*/
function twig_include(Twig_Environment $env, $context, $template, $variables = array(), $withContext = true, $ignoreMissing = false, $sandboxed = false)
function twig_include(Twig_Environment $env, array $context, $template, $variables = array(), $withContext = true, $ignoreMissing = false, $sandboxed = false)
{
$alreadySandboxed = false;
$sandbox = null;
+2
View File
@@ -104,6 +104,8 @@ class Twig_Extension_Escaper extends Twig_Extension
* Marks a variable as being safe.
*
* @param string $string A PHP variable
*
* @return string
*/
function twig_raw_filter($string)
{
+2 -1
View File
@@ -42,7 +42,8 @@ interface Twig_LoaderInterface
* Returns true if the template is still fresh.
*
* @param string $name The template name
* @param timestamp $time The last modification time of the cached template
* @param int $time Timestamp of the last modification time of the
* cached template
*
* @return bool true if the template is fresh, false otherwise
*
+17 -17
View File
@@ -122,7 +122,7 @@ class Twig_Node implements Twig_NodeInterface
/**
* Returns true if the attribute is defined.
*
* @param string The attribute name
* @param string $name The attribute name
*
* @return bool true if the attribute is defined, false otherwise
*/
@@ -132,11 +132,11 @@ class Twig_Node implements Twig_NodeInterface
}
/**
* Gets an attribute.
* Gets an attribute value by name.
*
* @param string The attribute name
* @param string $name
*
* @return mixed The attribute value
* @return mixed
*/
public function getAttribute($name)
{
@@ -148,10 +148,10 @@ class Twig_Node implements Twig_NodeInterface
}
/**
* Sets an attribute.
* Sets an attribute by name to a value.
*
* @param string The attribute name
* @param mixed The attribute value
* @param string $name
* @param mixed $value
*/
public function setAttribute($name, $value)
{
@@ -159,9 +159,9 @@ class Twig_Node implements Twig_NodeInterface
}
/**
* Removes an attribute.
* Removes an attribute by name.
*
* @param string The attribute name
* @param string $name
*/
public function removeAttribute($name)
{
@@ -169,11 +169,11 @@ class Twig_Node implements Twig_NodeInterface
}
/**
* Returns true if the node with the given identifier exists.
* Returns true if the node with the given name exists.
*
* @param string The node name
* @param string $name
*
* @return bool true if the node with the given name exists, false otherwise
* @return bool
*/
public function hasNode($name)
{
@@ -183,9 +183,9 @@ class Twig_Node implements Twig_NodeInterface
/**
* Gets a node by name.
*
* @param string The node name
* @param string $name
*
* @return Twig_Node A Twig_Node instance
* @return Twig_Node
*/
public function getNode($name)
{
@@ -199,8 +199,8 @@ class Twig_Node implements Twig_NodeInterface
/**
* Sets a node.
*
* @param string The node name
* @param Twig_Node A Twig_Node instance
* @param string $name
* @param Twig_Node $node
*/
public function setNode($name, $node = null)
{
@@ -210,7 +210,7 @@ class Twig_Node implements Twig_NodeInterface
/**
* Removes a node by name.
*
* @param string The node name
* @param string $name
*/
public function removeNode($name)
{
+2
View File
@@ -47,6 +47,8 @@ class Twig_Node_SandboxedPrint extends Twig_Node_Print
* This is mostly needed when another visitor adds filters (like the escaper one).
*
* @param Twig_Node $node A Node
*
* @return Twig_Node
*/
protected function removeNodeFilter($node)
{
+2
View File
@@ -54,6 +54,8 @@ class Twig_NodeTraverser
* Traverses a node and calls the registered visitors.
*
* @param Twig_NodeInterface $node A Twig_NodeInterface instance
*
* @return Twig_NodeInterface
*/
public function traverse(Twig_NodeInterface $node)
{
+4
View File
@@ -129,6 +129,8 @@ class Twig_NodeVisitor_Optimizer implements Twig_NodeVisitorInterface
*
* @param Twig_NodeInterface $node A Node
* @param Twig_Environment $env The current Twig environment
*
* @return Twig_NodeInterface
*/
protected function optimizePrintNode(Twig_NodeInterface $node, Twig_Environment $env)
{
@@ -153,6 +155,8 @@ class Twig_NodeVisitor_Optimizer implements Twig_NodeVisitorInterface
*
* @param Twig_NodeInterface $node A Node
* @param Twig_Environment $env The current Twig environment
*
* @return Twig_NodeInterface
*/
protected function optimizeRawFilter(Twig_NodeInterface $node, Twig_Environment $env)
{
+3 -1
View File
@@ -58,6 +58,8 @@ abstract class Twig_Template implements Twig_TemplateInterface
* This method is for internal use only and should never be called
* directly.
*
* @param array $context
*
* @return Twig_TemplateInterface|false The parent template or false if there is no parent
*/
public function getParent(array $context)
@@ -352,7 +354,7 @@ abstract class Twig_Template implements Twig_TemplateInterface
* @param string $item The variable to return from the context
* @param bool $ignoreStrictCheck Whether to ignore the strict variable check or not
*
* @return The content of the context variable
* @return mixed The content of the context variable
*
* @throws Twig_Error_Runtime if the variable does not exist and Twig is running in strict mode
*/
+1 -1
View File
@@ -24,7 +24,7 @@ abstract class Twig_TokenParser implements Twig_TokenParserInterface
/**
* Sets the parser associated with this token parser
*
* @param $parser A Twig_Parser instance
* @param Twig_Parser $parser A Twig_Parser instance
*/
public function setParser(Twig_Parser $parser)
{
+1 -1
View File
@@ -47,7 +47,7 @@ class Twig_TokenParser_Block extends Twig_TokenParser
$value = $token->getValue();
if ($value != $name) {
throw new Twig_Error_Syntax(sprintf("Expected endblock for block '$name' (but %s given)", $value), $stream->getCurrent()->getLine(), $stream->getFilename());
throw new Twig_Error_Syntax(sprintf('Expected endblock for block "%s" (but "%s" given)', $name, $value), $stream->getCurrent()->getLine(), $stream->getFilename());
}
}
} else {
+1 -1
View File
@@ -42,7 +42,7 @@ class Twig_TokenParser_Macro extends Twig_TokenParser
$value = $token->getValue();
if ($value != $name) {
throw new Twig_Error_Syntax(sprintf("Expected endmacro for macro '$name' (but %s given)", $value), $stream->getCurrent()->getLine(), $stream->getFilename());
throw new Twig_Error_Syntax(sprintf('Expected endmacro for macro "%s" (but "%s" given)', $name, $value), $stream->getCurrent()->getLine(), $stream->getFilename());
}
}
$this->parser->popLocalScope();
+2 -2
View File
@@ -48,13 +48,13 @@ class Twig_TokenParser_Set extends Twig_TokenParser
$stream->expect(Twig_Token::BLOCK_END_TYPE);
if (count($names) !== count($values)) {
throw new Twig_Error_Syntax("When using set, you must have the same number of variables and assignments.", $stream->getCurrent()->getLine(), $stream->getFilename());
throw new Twig_Error_Syntax('When using set, you must have the same number of variables and assignments.', $stream->getCurrent()->getLine(), $stream->getFilename());
}
} else {
$capture = true;
if (count($names) > 1) {
throw new Twig_Error_Syntax("When using set with a block, you cannot have a multi-target.", $stream->getCurrent()->getLine(), $stream->getFilename());
throw new Twig_Error_Syntax('When using set with a block, you cannot have a multi-target.', $stream->getCurrent()->getLine(), $stream->getFilename());
}
$stream->expect(Twig_Token::BLOCK_END_TYPE);
+1 -1
View File
@@ -19,7 +19,7 @@ interface Twig_TokenParserInterface
/**
* Sets the parser associated with this token parser
*
* @param $parser A Twig_Parser instance
* @param Twig_Parser $parser A Twig_Parser instance
*/
public function setParser(Twig_Parser $parser);
+4 -4
View File
@@ -56,7 +56,7 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
// globals can be modified after runtime init
$twig = new Twig_Environment($this->getMock('Twig_LoaderInterface'));
$twig->addGlobal('foo', 'foo');
$globals = $twig->getGlobals();
$twig->getGlobals();
$twig->initRuntime();
$twig->addGlobal('foo', 'bar');
$globals = $twig->getGlobals();
@@ -91,7 +91,7 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
// globals cannot be added after runtime init
$twig = new Twig_Environment($this->getMock('Twig_LoaderInterface'));
$twig->addGlobal('foo', 'foo');
$globals = $twig->getGlobals();
$twig->getGlobals();
$twig->initRuntime();
try {
$twig->addGlobal('bar', 'bar');
@@ -103,7 +103,7 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
// globals cannot be added after extensions init
$twig = new Twig_Environment($this->getMock('Twig_LoaderInterface'));
$twig->addGlobal('foo', 'foo');
$globals = $twig->getGlobals();
$twig->getGlobals();
$twig->getFunctions();
try {
$twig->addGlobal('bar', 'bar');
@@ -115,7 +115,7 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
// globals cannot be added after extensions and runtime init
$twig = new Twig_Environment($this->getMock('Twig_LoaderInterface'));
$twig->addGlobal('foo', 'foo');
$globals = $twig->getGlobals();
$twig->getGlobals();
$twig->getFunctions();
$twig->initRuntime();
try {
+1 -1
View File
@@ -144,7 +144,7 @@ class Twig_Tests_LexerTest extends PHPUnit_Framework_TestCase
$lexer = new Twig_Lexer(new Twig_Environment());
$stream = $lexer->tokenize($template);
$node = $stream->next();
$stream->next();
$node = $stream->next();
$this->assertEquals("922337203685477580700", $node->getValue());
}
+1 -1
View File
@@ -130,7 +130,7 @@ class __TwigTemplate_e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b785
EOF
, $twig);
$set = new Twig_Node_Set(false, new Twig_Node(array(new Twig_Node_Expression_AssignName('foo', 4))), new Twig_Node(array(new Twig_Node_Expression_Constant("foo", 4))), 4);
$set = new Twig_Node_Set(false, new Twig_Node(array(new Twig_Node_Expression_AssignName('foo', 4))), new Twig_Node(array(new Twig_Node_Expression_Constant('foo', 4))), 4);
$body = new Twig_Node(array($set));
$extends = new Twig_Node_Expression_Conditional(
new Twig_Node_Expression_Constant(true, 2),
+1 -1
View File
@@ -509,7 +509,7 @@ class Twig_TemplateMagicPropertyObjectWithException
{
public function __isset($key)
{
throw new Exception("Hey! Don't try to isset me!");
throw new Exception('Hey! Don\'t try to isset me!');
}
}
+2 -1
View File
@@ -226,7 +226,8 @@ class Twig_Test_EscapingTest extends PHPUnit_Framework_TestCase
/**
* Convert a Unicode Codepoint to a literal UTF-8 character.
*
* @param int $codepoint Unicode codepoint in hex notation
* @param int $codepoint Unicode codepoint in hex notation
*
* @return string UTF-8 literal string
*/
protected function codepointToUtf8($codepoint)