Conditions | 13 |
Paths | 9 |
Total Lines | 44 |
Code Lines | 26 |
Lines | 0 |
Ratio | 0 % |
Changes | 5 | ||
Bugs | 1 | 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 |
||
22 | public function getFunctions() |
||
23 | { |
||
24 | $count = count($this->tokens); |
||
25 | $bufferFunctions = array(); |
||
26 | $functions = array(); |
||
27 | |||
28 | for ($k = 0; $k < $count; ++$k) { |
||
29 | $value = $this->tokens[$k]; |
||
30 | |||
31 | //close the current function |
||
32 | if (is_string($value)) { |
||
33 | if ($value === ')' && isset($bufferFunctions[0])) { |
||
34 | $functions[] = array_shift($bufferFunctions); |
||
35 | } |
||
36 | |||
37 | continue; |
||
38 | } |
||
39 | |||
40 | switch ($value[0]) { |
||
41 | case T_CONSTANT_ENCAPSED_STRING: |
||
42 | //add an argument to the current function |
||
43 | if (isset($bufferFunctions[0])) { |
||
44 | $bufferFunctions[0][2][] = \Gettext\Extractors\PhpCode::convertString($value[1]); |
||
45 | } |
||
46 | break; |
||
47 | case T_STRING: |
||
48 | //new function found |
||
49 | for ($j = $k + 1; $j < $count; $j++) { |
||
50 | $nextToken = $this->tokens[$j]; |
||
51 | if (is_array($nextToken) && ($nextToken[0] === T_COMMENT || $nextToken[0] === T_WHITESPACE)) { |
||
52 | continue; |
||
53 | } |
||
54 | if ($nextToken === '(') { |
||
55 | array_unshift($bufferFunctions, array($value[1], $value[2], array())); |
||
56 | $k = $j; |
||
57 | } |
||
58 | break; |
||
59 | } |
||
60 | break; |
||
61 | } |
||
62 | } |
||
63 | |||
64 | return $functions; |
||
65 | } |
||
66 | } |
||
67 |