Conditions | 12 |
Paths | 5 |
Total Lines | 34 |
Code Lines | 19 |
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 |
||
24 | public function decorate(array $tokens) |
||
25 | { |
||
26 | if(-1 !== version_compare(PHP_VERSION, '7.0.0')) { |
||
27 | return $tokens; |
||
28 | } |
||
29 | |||
30 | $previous = null; |
||
31 | foreach($tokens as $index => &$token) { |
||
32 | |||
33 | // coalesce operator |
||
34 | if(T_STRING == $token->getType()&&'?' == $token->getValue() |
||
35 | && $index > 0 |
||
36 | && T_STRING == $previous->getType()&&'?' == $previous->getValue() |
||
37 | ) { |
||
38 | unset($tokens[$index]); |
||
39 | $tokens[$index - 1] = new Token(array(T_COALESCE, T_COALESCE)); |
||
40 | continue; |
||
41 | } |
||
42 | |||
43 | |||
44 | // spaceship operator |
||
45 | if($index > 2 |
||
46 | && T_STRING == $tokens[$index]->getType() && '>' === $tokens[$index]->getValue() |
||
47 | && T_IS_SMALLER_OR_EQUAL == $previous->getType() |
||
48 | ) { |
||
49 | unset($tokens[$index]); |
||
50 | $tokens[$index - 1] = new Token(array(T_SPACESHIP, T_SPACESHIP)); |
||
51 | continue; |
||
52 | } |
||
53 | |||
54 | $previous = $token; |
||
55 | } |
||
56 | return array_values($tokens); |
||
57 | } |
||
58 | } |
||
59 |