| Conditions | 10 |
| Paths | 17 |
| Total Lines | 45 |
| Code Lines | 24 |
| 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 |
||
| 54 | public function enterNode($node, VisitorContext $ctx) |
||
| 55 | { |
||
| 56 | if ( |
||
| 57 | !$node instanceof PHP |
||
| 58 | || ( |
||
| 59 | strpos($node->content, self::PHP_MACRO_FUNCTION) === false |
||
| 60 | && strpos($node->content, self::PHP_MARCO_EXISTS_FUNCTION) === false |
||
| 61 | ) |
||
| 62 | ) { |
||
| 63 | return null; |
||
| 64 | } |
||
| 65 | |||
| 66 | $php = new PHPMixin($node->tokens, self::PHP_MACRO_FUNCTION); |
||
| 67 | foreach ($this->blocks->getNames() as $name) { |
||
| 68 | $block = $this->blocks->get($name); |
||
| 69 | |||
| 70 | if ($this->isReference($block)) { |
||
| 71 | // resolved on later stage |
||
| 72 | continue; |
||
| 73 | } |
||
| 74 | |||
| 75 | if ($php->has($name)) { |
||
| 76 | $php->set($name, $this->trimPHP($this->blocks->claim($name))); |
||
| 77 | } |
||
| 78 | } |
||
| 79 | |||
| 80 | $node->content = $php->compile(); |
||
| 81 | $node->tokens = token_get_all($node->content); |
||
| 82 | |||
| 83 | $exists = new PHPMixin($node->tokens, self::PHP_MARCO_EXISTS_FUNCTION); |
||
| 84 | foreach ($this->blocks->getNames() as $name) { |
||
| 85 | $block = $this->blocks->get($name); |
||
| 86 | |||
| 87 | if ($this->isReference($block)) { |
||
| 88 | // resolved on later stage |
||
| 89 | continue; |
||
| 90 | } |
||
| 91 | |||
| 92 | if ($exists->has($name)) { |
||
| 93 | $exists->set($name, 'true'); |
||
| 94 | } |
||
| 95 | } |
||
| 96 | |||
| 97 | $node->content = $exists->compile(); |
||
| 98 | $node->tokens = token_get_all($node->content); |
||
| 99 | } |
||
| 205 |