| Conditions | 7 |
| Paths | 11 |
| Total Lines | 52 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 28 | public function parse(Twig_Token $token) |
||
| 29 | { |
||
| 30 | $lineno = $token->getLine(); |
||
| 31 | $stream = $this->parser->getStream(); |
||
| 32 | $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue(); |
||
| 33 | if ($this->parser->hasBlock($name)) { |
||
| 34 | throw new Twig_Error_Syntax(sprintf("The block '%s' has already been defined line %d.", $name, $this->parser->getBlock($name)->getTemplateLine()), $stream->getCurrent()->getLine(), $stream->getSourceContext()); |
||
| 35 | } |
||
| 36 | $this->parser->setBlock($name, $block = new Twig_Node_Block($name, new Twig_Node(array()), $lineno)); |
||
| 37 | $this->parser->pushLocalScope(); |
||
| 38 | $this->parser->pushBlockStack($name); |
||
| 39 | |||
| 40 | if ($stream->nextIf(Twig_Token::BLOCK_END_TYPE)) { |
||
| 41 | $body = $this->parser->subparse(array($this, 'decideBlockEnd'), true); |
||
| 42 | if ($token = $stream->nextIf(Twig_Token::NAME_TYPE)) { |
||
| 43 | $value = $token->getValue(); |
||
| 44 | |||
| 45 | if ($value !== $name) { |
||
| 46 | throw new Twig_Error_Syntax(sprintf('Expected endblock for block "%s" (but "%s" given).', $name, $value), $stream->getCurrent()->getLine(), $stream->getSourceContext()); |
||
| 47 | } |
||
| 48 | } |
||
| 49 | } else { |
||
| 50 | $body = new Twig_Node(array( |
||
| 51 | new Twig_Node_Print($this->parser->getExpressionParser()->parseExpression(), $lineno), |
||
| 52 | )); |
||
| 53 | } |
||
| 54 | $stream->expect(Twig_Token::BLOCK_END_TYPE); |
||
| 55 | |||
| 56 | $block->setNode('body', $body); |
||
| 57 | $this->parser->popBlockStack(); |
||
| 58 | $this->parser->popLocalScope(); |
||
| 59 | |||
| 60 | $blockReference = new Twig_Node_BlockReference($name, $lineno, $this->getTag()); |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @var Twig_Node_Block $block |
||
| 64 | */ |
||
| 65 | $block = $this->parser->getBlock($blockReference->getAttribute('name')); |
||
| 66 | |||
| 67 | // prepare block |
||
| 68 | NodeHelper::removeTextNodesRecursively($block, $this->parser); |
||
| 69 | NodeHelper::fixMacroCallsRecursively($block); |
||
| 70 | |||
| 71 | // mark for syntax checks |
||
| 72 | foreach ($block->getIterator() as $node) { |
||
| 73 | if ($node instanceof Twig_Node_Block) { |
||
|
|
|||
| 74 | $node->setAttribute('twigExcelBundle', true); |
||
| 75 | } |
||
| 76 | } |
||
| 77 | |||
| 78 | return $blockReference; |
||
| 79 | } |
||
| 80 | |||
| 98 |