| Conditions | 8 |
| Paths | 15 |
| Total Lines | 60 |
| Code Lines | 39 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 31 | public function parse(Twig_Token $token) |
||
| 32 | { |
||
| 33 | $lineno = $token->getLine(); |
||
| 34 | |||
| 35 | $switchExpr = $this->parser->getExpressionParser()->parseExpression(); |
||
| 36 | |||
| 37 | /** @var $stream Twig_TokenStream */ |
||
| 38 | $stream = $this->parser->getStream(); |
||
| 39 | $stream->expect(Twig_Token::BLOCK_END_TYPE); |
||
| 40 | |||
| 41 | |||
| 42 | // skip whitespace between switch and first case |
||
| 43 | while ($stream->test(Twig_Token::TEXT_TYPE)) { |
||
| 44 | if (trim($stream->getCurrent()->getValue()) != '') { |
||
| 45 | $content = $stream->getCurrent()->getValue(); |
||
| 46 | throw new Twig_Error_Syntax("Can not render content '$content' directly after switch", $stream->getCurrent()->getLine()); |
||
| 47 | } |
||
| 48 | $stream->next(); |
||
| 49 | } |
||
| 50 | $stream->expect(Twig_Token::BLOCK_START_TYPE); |
||
| 51 | |||
| 52 | $tests = array(); |
||
| 53 | |||
| 54 | while (!$stream->test('endswitch')) { |
||
| 55 | $token = $stream->expect(Twig_Token::NAME_TYPE, array('case', 'default')); |
||
| 56 | switch ($token->getValue()) { |
||
| 57 | case 'case': |
||
| 58 | $caseExpr = array(); |
||
| 59 | $caseExpr[] = $this->parser->getExpressionParser()->parseExpression(); |
||
| 60 | while ($stream->test(Twig_Token::OPERATOR_TYPE, ',')) { |
||
| 61 | $stream->next(); |
||
| 62 | $caseExpr[] = $this->parser->getExpressionParser()->parseExpression(); |
||
| 63 | } |
||
| 64 | break; |
||
| 65 | case 'default': |
||
| 66 | $caseExpr = null; |
||
| 67 | break; |
||
| 68 | } |
||
| 69 | |||
| 70 | $fallthrough = false; |
||
| 71 | if ($stream->test('fallthrough')) { |
||
| 72 | $stream->next(); |
||
| 73 | $fallthrough = true; |
||
| 74 | } |
||
| 75 | $stream->expect(Twig_Token::BLOCK_END_TYPE); |
||
| 76 | $body = $this->parser->subparse(array($this, 'decideSwitchFork')); |
||
| 77 | |||
| 78 | $tests[] = new SwitchCaseNode( |
||
| 79 | $body, |
||
|
|
|||
| 80 | $caseExpr, |
||
| 81 | $fallthrough, |
||
| 82 | $token->getLine(), |
||
| 83 | $token->getValue() |
||
| 84 | ); |
||
| 85 | } |
||
| 86 | |||
| 87 | $stream->expect('endswitch'); |
||
| 88 | $stream->expect(Twig_Token::BLOCK_END_TYPE); |
||
| 89 | |||
| 90 | return new SwitchNode(new Twig_Node($tests), $switchExpr, $lineno); |
||
| 91 | } |
||
| 105 |