Conditions | 13 |
Paths | 4 |
Total Lines | 42 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
38 | private function detectInfo($file) |
||
39 | { |
||
40 | $fp = fopen($file, 'r'); |
||
41 | $this->class = $this->namespace = $buffer = ''; |
||
42 | $i = 0; |
||
43 | |||
44 | while (!$this->class) { |
||
45 | if (feof($fp)){ |
||
46 | break; |
||
47 | } |
||
48 | |||
49 | $buffer .= fread($fp, 512); |
||
50 | $tokens = token_get_all($buffer); |
||
51 | |||
52 | if (strpos($buffer, '{') === false) { |
||
53 | continue; |
||
54 | } |
||
55 | |||
56 | $totalTokens = count($tokens); |
||
57 | |||
58 | for (; $i < $totalTokens; $i++) { |
||
59 | if ($tokens[$i][0] === T_NAMESPACE) { |
||
60 | for ($j = $i + 1; $j < $totalTokens; $j++) { |
||
61 | if ($tokens[$j][0] === T_STRING) { |
||
62 | $this->namespace .= '\\'.$tokens[$j][1]; |
||
63 | } else if ($tokens[$j] === '{' || $tokens[$j] === ';') { |
||
64 | break; |
||
65 | } |
||
66 | } |
||
67 | } |
||
68 | |||
69 | if ($tokens[$i][0] === T_CLASS) { |
||
70 | for ($j = $i + 1; $j < $totalTokens; $j++) { |
||
71 | if ($tokens[$j] === '{') { |
||
72 | $this->class = $tokens[$i + 2][1]; |
||
73 | } |
||
74 | } |
||
75 | } |
||
76 | |||
77 | } |
||
78 | } |
||
79 | } |
||
80 | } |