Skip to content

Commit

Permalink
clean ups
Browse files Browse the repository at this point in the history
  • Loading branch information
SpacePossum committed Apr 24, 2015
1 parent 7d5fe0f commit 2030482
Show file tree
Hide file tree
Showing 20 changed files with 70 additions and 47 deletions.
11 changes: 5 additions & 6 deletions lib/Twig/Environment.php
Expand Up @@ -351,8 +351,7 @@ public function loadTemplate($name, $index = null)
*
* 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
*
Expand Down Expand Up @@ -483,7 +482,7 @@ public function getLexer()
/**
* 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)
{
Expand Down Expand Up @@ -522,7 +521,7 @@ public function getParser()
/**
* 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)
{
Expand Down Expand Up @@ -1271,11 +1270,11 @@ protected function writeCacheFile($file, $content)
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));
Expand Down
6 changes: 5 additions & 1 deletion lib/Twig/ExpressionParser.php
Expand Up @@ -315,7 +315,7 @@ public function getFunctionNode($name, $line)
{
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());
}
Expand Down Expand Up @@ -468,6 +468,10 @@ public function parseFilterExpressionRaw($node, $tag = null)
*
* @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)
{
Expand Down
20 changes: 13 additions & 7 deletions lib/Twig/Extension/Core.php
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions lib/Twig/Extension/Escaper.php
Expand Up @@ -104,6 +104,8 @@ public function getName()
* Marks a variable as being safe.
*
* @param string $string A PHP variable
*
* @return string
*/
function twig_raw_filter($string)
{
Expand Down
3 changes: 2 additions & 1 deletion lib/Twig/LoaderInterface.php
Expand Up @@ -42,7 +42,8 @@ public function getCacheKey($name);
* 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
*
Expand Down
34 changes: 17 additions & 17 deletions lib/Twig/Node.php
Expand Up @@ -122,7 +122,7 @@ public function getNodeTag()
/**
* 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
*/
Expand All @@ -132,11 +132,11 @@ public function hasAttribute($name)
}

/**
* 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)
{
Expand All @@ -148,32 +148,32 @@ public function getAttribute($name)
}

/**
* 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)
{
$this->attributes[$name] = $value;
}

/**
* Removes an attribute.
* Removes an attribute by name.
*
* @param string The attribute name
* @param string $name
*/
public function removeAttribute($name)
{
unset($this->attributes[$name]);
}

/**
* 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)
{
Expand All @@ -183,9 +183,9 @@ public function hasNode($name)
/**
* 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)
{
Expand All @@ -199,8 +199,8 @@ public function getNode($name)
/**
* 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)
{
Expand All @@ -210,7 +210,7 @@ public function setNode($name, $node = null)
/**
* Removes a node by name.
*
* @param string The node name
* @param string $name
*/
public function removeNode($name)
{
Expand Down
2 changes: 2 additions & 0 deletions lib/Twig/Node/SandboxedPrint.php
Expand Up @@ -47,6 +47,8 @@ public function compile(Twig_Compiler $compiler)
* 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)
{
Expand Down
2 changes: 2 additions & 0 deletions lib/Twig/NodeTraverser.php
Expand Up @@ -54,6 +54,8 @@ public function addVisitor(Twig_NodeVisitorInterface $visitor)
* 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)
{
Expand Down
4 changes: 4 additions & 0 deletions lib/Twig/NodeVisitor/Optimizer.php
Expand Up @@ -129,6 +129,8 @@ protected function optimizeVariables(Twig_NodeInterface $node, Twig_Environment
*
* @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)
{
Expand All @@ -153,6 +155,8 @@ protected function optimizePrintNode(Twig_NodeInterface $node, Twig_Environment
*
* @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)
{
Expand Down
4 changes: 3 additions & 1 deletion lib/Twig/Template.php
Expand Up @@ -58,6 +58,8 @@ public function getEnvironment()
* 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)
Expand Down Expand Up @@ -352,7 +354,7 @@ abstract protected function doDisplay(array $context, array $blocks = array());
* @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
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/Twig/TokenParser.php
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Twig/TokenParser/Block.php
Expand Up @@ -47,7 +47,7 @@ public function parse(Twig_Token $token)
$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 {
Expand Down
2 changes: 1 addition & 1 deletion lib/Twig/TokenParser/Macro.php
Expand Up @@ -42,7 +42,7 @@ public function parse(Twig_Token $token)
$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();
Expand Down
4 changes: 2 additions & 2 deletions lib/Twig/TokenParser/Set.php
Expand Up @@ -48,13 +48,13 @@ public function parse(Twig_Token $token)
$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);
Expand Down
2 changes: 1 addition & 1 deletion lib/Twig/TokenParserInterface.php
Expand Up @@ -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);

Expand Down
8 changes: 4 additions & 4 deletions test/Twig/Tests/EnvironmentTest.php
Expand Up @@ -56,7 +56,7 @@ public function testGlobals()
// 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();
Expand Down Expand Up @@ -91,7 +91,7 @@ public function testGlobals()
// 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');
Expand All @@ -103,7 +103,7 @@ public function testGlobals()
// 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');
Expand All @@ -115,7 +115,7 @@ public function testGlobals()
// 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 {
Expand Down
2 changes: 1 addition & 1 deletion test/Twig/Tests/LexerTest.php
Expand Up @@ -144,7 +144,7 @@ public function testBigNumbers()

$lexer = new Twig_Lexer(new Twig_Environment());
$stream = $lexer->tokenize($template);
$node = $stream->next();
$stream->next();
$node = $stream->next();
$this->assertEquals("922337203685477580700", $node->getValue());
}
Expand Down
2 changes: 1 addition & 1 deletion test/Twig/Tests/Node/ModuleTest.php
Expand Up @@ -130,7 +130,7 @@ public function getDebugInfo()
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),
Expand Down
2 changes: 1 addition & 1 deletion test/Twig/Tests/TemplateTest.php
Expand Up @@ -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!');
}
}

Expand Down

0 comments on commit 2030482

Please sign in to comment.