Skip to content

Commit d58c8be

Browse files
committed
minor #4698 Add throw tag to parse methods (VincentLanglet)
This PR was merged into the 3.x branch. Discussion ---------- Add throw tag to parse methods Hi `@fabpot`, with PHPStan improving every day his exception checking, it's useful to have well documented method. I didn't update all of them (there are too many), and focus on the one I have issue with: - Almost all the InfixExpressionParserInterface/PrefixExpressionParserInterface implements throws a SyntaxError in parse method - Parser::parse method is catching SyntaxError and rethrowing them so it should be added to the phpdoc - Since Parser::parse catch Parser::subparse, it would be useful to add the phpdoc to subparse Commits ------- 790eee7 Add throw tag to parse methods
2 parents 2996f0b + 790eee7 commit d58c8be

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

src/ExpressionParser/InfixExpressionParserInterface.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@
1111

1212
namespace Twig\ExpressionParser;
1313

14+
use Twig\Error\SyntaxError;
1415
use Twig\Node\Expression\AbstractExpression;
1516
use Twig\Parser;
1617
use Twig\Token;
1718

1819
interface InfixExpressionParserInterface extends ExpressionParserInterface
1920
{
21+
/**
22+
* @throws SyntaxError
23+
*/
2024
public function parse(Parser $parser, AbstractExpression $left, Token $token): AbstractExpression;
2125

2226
public function getAssociativity(): InfixAssociativity;

src/ExpressionParser/PrefixExpressionParserInterface.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@
1111

1212
namespace Twig\ExpressionParser;
1313

14+
use Twig\Error\SyntaxError;
1415
use Twig\Node\Expression\AbstractExpression;
1516
use Twig\Parser;
1617
use Twig\Token;
1718

1819
interface PrefixExpressionParserInterface extends ExpressionParserInterface
1920
{
21+
/**
22+
* @throws SyntaxError
23+
*/
2024
public function parse(Parser $parser, Token $token): AbstractExpression;
2125
}

src/Parser.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ public function getVarName(): string
7676
return \sprintf('__internal_parse_%d', $this->varNameSalt++);
7777
}
7878

79+
/**
80+
* @throws SyntaxError
81+
*/
7982
public function parse(TokenStream $stream, $test = null, bool $dropNeedle = false): ModuleNode
8083
{
8184
$vars = get_object_vars($this);
@@ -158,6 +161,9 @@ public function subparseIgnoreUnknownTwigCallables($test, bool $dropNeedle = fal
158161
}
159162
}
160163

164+
/**
165+
* @throws SyntaxError
166+
*/
161167
public function subparse($test, bool $dropNeedle = false): Node
162168
{
163169
$lineno = $this->getCurrentToken()->getLine();

0 commit comments

Comments
 (0)