From: nikic <+@ni-po.com> Date: Wed, 9 Feb 2011 17:06:57 +0000 (+0100) Subject: add some more DocComments / type hints X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=587063efbf934c39d418185976b8e42d344c06b2;p=konrad%2Ftwig.git add some more DocComments / type hints --- diff --git a/lib/Twig/CompilerInterface.php b/lib/Twig/CompilerInterface.php index c03407e..cc9a03c 100644 --- a/lib/Twig/CompilerInterface.php +++ b/lib/Twig/CompilerInterface.php @@ -22,7 +22,7 @@ interface Twig_CompilerInterface * * @param Twig_NodeInterface $node The node to compile * - * @return Twig_Compiler The current compiler instance + * @return Twig_CompilerInterface The current compiler instance */ function compile(Twig_NodeInterface $node); diff --git a/lib/Twig/ExpressionParser.php b/lib/Twig/ExpressionParser.php index 0bf3d8a..2e2b4b1 100644 --- a/lib/Twig/ExpressionParser.php +++ b/lib/Twig/ExpressionParser.php @@ -228,7 +228,7 @@ class Twig_ExpressionParser return $node; } - public function getFunctionNode($node) + public function getFunctionNode(Twig_Node_Expression_Name $node) { $args = $this->parseArguments(); diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index 01962b0..553be47 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -171,18 +171,18 @@ class Twig_Extension_Core extends Twig_Extension ); } - public function parseNotTestExpression($parser, $node) + public function parseNotTestExpression(Twig_Parser $parser, $node) { return new Twig_Node_Expression_Unary_Not($this->parseTestExpression($parser, $node), $parser->getCurrentToken()->getLine()); } - public function parseTestExpression($parser, $node) + public function parseTestExpression(Twig_Parser $parser, $node) { $stream = $parser->getStream(); $name = $stream->expect(Twig_Token::NAME_TYPE); $arguments = null; if ($stream->test(Twig_Token::PUNCTUATION_TYPE, '(')) { - $arguments = $parser->getExpressionParser()->parseArguments($node); + $arguments = $parser->getExpressionParser()->parseArguments(); } return new Twig_Node_Expression_Test($node, $name->getValue(), $arguments, $parser->getCurrentToken()->getLine()); diff --git a/lib/Twig/FilterInterface.php b/lib/Twig/FilterInterface.php index eb6ac57..8320517 100644 --- a/lib/Twig/FilterInterface.php +++ b/lib/Twig/FilterInterface.php @@ -26,6 +26,8 @@ interface Twig_FilterInterface function needsEnvironment(); + function needsContext(); + function getSafe(Twig_Node $filterArgs); function getPreEscape(); diff --git a/lib/Twig/FunctionInterface.php b/lib/Twig/FunctionInterface.php index 01d3566..ccc9fd9 100644 --- a/lib/Twig/FunctionInterface.php +++ b/lib/Twig/FunctionInterface.php @@ -27,5 +27,7 @@ interface Twig_FunctionInterface function needsEnvironment(); + function needsContext(); + function getSafe(Twig_Node $filterArgs); } diff --git a/lib/Twig/NodeTraverser.php b/lib/Twig/NodeTraverser.php index e7335f0..737934c 100644 --- a/lib/Twig/NodeTraverser.php +++ b/lib/Twig/NodeTraverser.php @@ -68,7 +68,7 @@ class Twig_NodeTraverser return $node; } - protected function traverseForVisitor($visitor, Twig_NodeInterface $node = null) + protected function traverseForVisitor(Twig_NodeVisitorInterface $visitor, Twig_NodeInterface $node = null) { if (null === $node) { return null; diff --git a/lib/Twig/Parser.php b/lib/Twig/Parser.php index 2e64595..e7ea3fc 100644 --- a/lib/Twig/Parser.php +++ b/lib/Twig/Parser.php @@ -245,6 +245,11 @@ class Twig_Parser implements Twig_ParserInterface array_shift($this->importedFunctions); } + /** + * Gets the expression parser. + * + * @return Twig_ExpressionParser The expression parser + */ public function getExpressionParser() { return $this->expressionParser; @@ -260,11 +265,21 @@ class Twig_Parser implements Twig_ParserInterface $this->parent = $parent; } + /** + * Gets the token stream. + * + * @return Twig_TokenStream The token stream + */ public function getStream() { return $this->stream; } + /** + * Gets the current token. + * + * @return Twig_Token The current token + */ public function getCurrentToken() { return $this->stream->getCurrent(); diff --git a/lib/Twig/Token.php b/lib/Twig/Token.php index a581bb2..c5fc156 100644 --- a/lib/Twig/Token.php +++ b/lib/Twig/Token.php @@ -59,16 +59,14 @@ class Twig_Token } /** - * Tests the current token for a type. + * Tests the current token for a type and/or a value. * - * The first argument is the type - * of the token (if not given Twig_Token::NAME_TYPE), the second the - * value of the token (if not given value is not checked). + * Parameters may be: + * * just type + * * type and value (or array of possible values) + * * just value (or array of possible values) (NAME_TYPE is used as type) * - * The token value can be an array if multiple checks should be - * performed. - * - * @param integer $type The type to test + * @param array|integer $type The type to test * @param array|string|null $values The token value * * @return Boolean diff --git a/lib/Twig/TokenParser/AutoEscape.php b/lib/Twig/TokenParser/AutoEscape.php index 324ee60..59180c1 100644 --- a/lib/Twig/TokenParser/AutoEscape.php +++ b/lib/Twig/TokenParser/AutoEscape.php @@ -41,7 +41,7 @@ class Twig_TokenParser_AutoEscape extends Twig_TokenParser return new Twig_Node_AutoEscape($value, $body, $lineno, $this->getTag()); } - public function decideBlockEnd($token) + public function decideBlockEnd(Twig_Token $token) { return $token->test('endautoescape'); } diff --git a/lib/Twig/TokenParser/Block.php b/lib/Twig/TokenParser/Block.php index 5ff104d..92028a1 100644 --- a/lib/Twig/TokenParser/Block.php +++ b/lib/Twig/TokenParser/Block.php @@ -55,7 +55,7 @@ class Twig_TokenParser_Block extends Twig_TokenParser return new Twig_Node_BlockReference($name, $lineno, $this->getTag()); } - public function decideBlockEnd($token) + public function decideBlockEnd(Twig_Token $token) { return $token->test('endblock'); } diff --git a/lib/Twig/TokenParser/Filter.php b/lib/Twig/TokenParser/Filter.php index f702154..b15d375 100644 --- a/lib/Twig/TokenParser/Filter.php +++ b/lib/Twig/TokenParser/Filter.php @@ -34,7 +34,7 @@ class Twig_TokenParser_Filter extends Twig_TokenParser return new Twig_Node_Print($filter, $token->getLine(), $this->getTag()); } - public function decideBlockEnd($token) + public function decideBlockEnd(Twig_Token $token) { return $token->test('endfilter'); } diff --git a/lib/Twig/TokenParser/For.php b/lib/Twig/TokenParser/For.php index 8364362..20740d4 100644 --- a/lib/Twig/TokenParser/For.php +++ b/lib/Twig/TokenParser/For.php @@ -46,12 +46,12 @@ class Twig_TokenParser_For extends Twig_TokenParser return new Twig_Node_For($keyTarget, $valueTarget, $seq, $body, $else, $lineno, $this->getTag()); } - public function decideForFork($token) + public function decideForFork(Twig_Token $token) { return $token->test(array('else', 'endfor')); } - public function decideForEnd($token) + public function decideForEnd(Twig_Token $token) { return $token->test('endfor'); } diff --git a/lib/Twig/TokenParser/If.php b/lib/Twig/TokenParser/If.php index 1621c13..59c5773 100644 --- a/lib/Twig/TokenParser/If.php +++ b/lib/Twig/TokenParser/If.php @@ -57,12 +57,12 @@ class Twig_TokenParser_If extends Twig_TokenParser return new Twig_Node_If(new Twig_Node($tests), $else, $lineno, $this->getTag()); } - public function decideIfFork($token) + public function decideIfFork(Twig_Token $token) { return $token->test(array('elseif', 'else', 'endif')); } - public function decideIfEnd($token) + public function decideIfEnd(Twig_Token $token) { return $token->test(array('endif')); } diff --git a/lib/Twig/TokenParser/Macro.php b/lib/Twig/TokenParser/Macro.php index 9cc0886..1f2210d 100644 --- a/lib/Twig/TokenParser/Macro.php +++ b/lib/Twig/TokenParser/Macro.php @@ -42,7 +42,7 @@ class Twig_TokenParser_Macro extends Twig_TokenParser return null; } - public function decideBlockEnd($token) + public function decideBlockEnd(Twig_Token $token) { return $token->test('endmacro'); } diff --git a/lib/Twig/TokenParser/Sandbox.php b/lib/Twig/TokenParser/Sandbox.php index a4b6f33..964fe6f 100644 --- a/lib/Twig/TokenParser/Sandbox.php +++ b/lib/Twig/TokenParser/Sandbox.php @@ -26,7 +26,7 @@ class Twig_TokenParser_Sandbox extends Twig_TokenParser return new Twig_Node_Sandbox($body, $token->getLine(), $this->getTag()); } - public function decideBlockEnd($token) + public function decideBlockEnd(Twig_Token $token) { return $token->test('endsandbox'); } diff --git a/lib/Twig/TokenParser/Set.php b/lib/Twig/TokenParser/Set.php index 0cc1960..eb5e5fe 100644 --- a/lib/Twig/TokenParser/Set.php +++ b/lib/Twig/TokenParser/Set.php @@ -49,7 +49,7 @@ class Twig_TokenParser_Set extends Twig_TokenParser return new Twig_Node_Set($capture, $names, $values, $lineno, $this->getTag()); } - public function decideBlockEnd($token) + public function decideBlockEnd(Twig_Token $token) { return $token->test('endset'); } diff --git a/lib/Twig/TokenParser/Spaceless.php b/lib/Twig/TokenParser/Spaceless.php index bd533c2..ac20439 100644 --- a/lib/Twig/TokenParser/Spaceless.php +++ b/lib/Twig/TokenParser/Spaceless.php @@ -28,7 +28,7 @@ class Twig_TokenParser_Spaceless extends Twig_TokenParser return new Twig_Node_Spaceless($body, $lineno, $this->getTag()); } - public function decideSpacelessEnd($token) + public function decideSpacelessEnd(Twig_Token $token) { return $token->test('endspaceless'); } diff --git a/lib/Twig/TokenParserBroker.php b/lib/Twig/TokenParserBroker.php index 9434c7b..3178585 100644 --- a/lib/Twig/TokenParserBroker.php +++ b/lib/Twig/TokenParserBroker.php @@ -25,8 +25,8 @@ class Twig_TokenParserBroker implements Twig_TokenParserBrokerInterface /** * Constructor. * - * @param array|Iterable $parsers An Iterable of Twig_TokenParserInterface instances - * @param array|Iterable $brokers An Iterable of Twig_TokenParserBrokerInterface instances + * @param array|Traversable $parsers A Traversable of Twig_TokenParserInterface instances + * @param array|Traversable $brokers A Traversable of Twig_TokenParserBrokerInterface instances */ public function __construct($parsers = array(), $brokers = array()) { @@ -97,10 +97,10 @@ class Twig_TokenParserBroker implements Twig_TokenParserBrokerInterface public function setParser(Twig_ParserInterface $parser) { $this->parser = $parser; - foreach($this->parsers as $tokenParser) { + foreach ($this->parsers as $tokenParser) { $tokenParser->setParser($parser); } - foreach($this->brokers as $broker) { + foreach ($this->brokers as $broker) { $broker->setParser($parser); } }