| Conditions | 13 |
| Paths | 11 |
| Total Lines | 42 |
| Code Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| Bugs | 4 | 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 |
||
| 50 | public function extract(&$n, TokenCollection $tokens) |
||
| 51 | { |
||
| 52 | |||
| 53 | $token = $tokens[$n]; |
||
| 54 | $call = null; |
||
| 55 | switch($token->getType()) { |
||
| 56 | case T_PAAMAYIM_NEKUDOTAYIM: |
||
| 57 | $prev = $n - 1; |
||
| 58 | $value = $this->searcher->getUnder(array('::'), $prev, $tokens); |
||
| 59 | |||
| 60 | switch(true) { |
||
| 61 | case $value == 'parent' && $this->currentClass: |
||
| 62 | return $this->currentClass->getParent(); |
||
| 63 | |||
| 64 | case $value == 'parent': |
||
| 65 | // we try to get the name of the parent class |
||
| 66 | $extendPosition = $this->searcher->getExtendPosition($tokens, $n); |
||
| 67 | return $this->searcher->getFollowingName($extendPosition, $tokens); |
||
| 68 | |||
| 69 | case ($value == 'static' ||$value === 'self')&& $this->currentClass: |
||
| 70 | return $this->currentClass->getFullname(); |
||
| 71 | |||
| 72 | case ($value == 'static' ||$value === 'self'): |
||
| 73 | $extendPosition = $this->searcher->getClassNamePosition($tokens); |
||
| 74 | return $this->searcher->getFollowingName($extendPosition, $tokens); |
||
| 75 | |||
| 76 | default: |
||
| 77 | return $value; |
||
| 78 | } |
||
| 79 | |||
| 80 | case T_NEW: |
||
| 81 | $call = $this->searcher->getFollowingName($n, $tokens); |
||
| 82 | if(preg_match('!^(\w+)!', $call, $matches)) { // fixes PHP 5.4: (new MyClass)->foo() |
||
| 83 | $call = $matches[1]; |
||
| 84 | } |
||
| 85 | break; |
||
| 86 | } |
||
| 87 | if(null === $call) { |
||
| 88 | throw new \LogicException('Classname of call not found'); |
||
| 89 | } |
||
| 90 | return $call; |
||
| 91 | } |
||
| 92 | }; |