| Conditions | 8 |
| Paths | 96 |
| Total Lines | 63 |
| Lines | 7 |
| Ratio | 11.11 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 50 | public function parse(\Twig\Token $token) |
||
| 51 | { |
||
| 52 | $lineno = $token->getLine(); |
||
| 53 | $stream = $this->parser->getStream(); |
||
| 54 | |||
| 55 | $variable = $this->parser->getExpressionParser()->parseAssignmentExpression(); |
||
| 56 | $stream->expect(\Twig\Token::NAME_TYPE, 'from'); |
||
| 57 | $collectionType = $this->parser->getExpressionParser()->parseAssignmentExpression(); |
||
| 58 | |||
| 59 | $collectionFilters = null; |
||
| 60 | if ($stream->test(\Twig\Token::PUNCTUATION_TYPE, '|')) { |
||
| 61 | $collectionFilters = $this->parser->getExpressionParser()->parsePostfixExpression($collectionType); |
||
| 62 | } |
||
| 63 | |||
| 64 | $withParameters = null; |
||
| 65 | if ($stream->nextIf(\Twig\Token::NAME_TYPE, 'with')) { |
||
| 66 | $withParameters = $this->parser->getExpressionParser()->parseExpression(); |
||
| 67 | } |
||
| 68 | |||
| 69 | $withoutParameters = null; |
||
| 70 | if ($stream->nextIf(\Twig\Token::NAME_TYPE, 'without')) { |
||
| 71 | $withoutParameters = $this->parser->getExpressionParser()->parseExpression(); |
||
| 72 | } |
||
| 73 | |||
| 74 | $ignoreContext = null; |
||
| 75 | View Code Duplication | if ($stream->nextIf(\Twig\Token::NAME_TYPE, 'ignoreContext')) { |
|
| 76 | if ($stream->test(\Twig\Token::PUNCTUATION_TYPE, '[')) { |
||
| 77 | $ignoreContext = $this->parser->getExpressionParser()->parseExpression(); |
||
| 78 | } else { |
||
| 79 | $ignoreContext = new \Twig\Node\Expression\ArrayExpression([], $token->getLine()); |
||
| 80 | } |
||
| 81 | } |
||
| 82 | |||
| 83 | $ifExpression = null; |
||
| 84 | if ($stream->nextIf(\Twig\Token::NAME_TYPE, 'if')) { |
||
| 85 | $ifExpression = $this->parser->getExpressionParser()->parseExpression(); |
||
| 86 | } |
||
| 87 | |||
| 88 | $stream->expect(\Twig\Token::BLOCK_END_TYPE); |
||
| 89 | $body = $this->parser->subparse([$this, 'decideGimmeListFork']); |
||
| 90 | if ('else' === $stream->next()->getValue()) { |
||
| 91 | $stream->expect(\Twig\Token::BLOCK_END_TYPE); |
||
| 92 | $else = $this->parser->subparse([$this, 'decideGimmeListEnd'], true); |
||
| 93 | } else { |
||
| 94 | $else = null; |
||
| 95 | } |
||
| 96 | |||
| 97 | $stream->expect(\Twig\Token::BLOCK_END_TYPE); |
||
| 98 | |||
| 99 | return new GimmeListNode( |
||
| 100 | $variable, |
||
| 101 | $collectionType, |
||
| 102 | $collectionFilters, |
||
| 103 | $withParameters, |
||
| 104 | $withoutParameters, |
||
| 105 | $ignoreContext, |
||
| 106 | $ifExpression, |
||
| 107 | $else, |
||
| 108 | $body, |
||
| 109 | $lineno, |
||
| 110 | $this->getTag() |
||
| 111 | ); |
||
| 112 | } |
||
| 113 | } |
||
| 114 |