Conditions | 11 |
Paths | 21 |
Total Lines | 34 |
Lines | 8 |
Ratio | 23.53 % |
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 |
||
21 | private static function removeGenericDocBlocks($tokens, $absFilePath) |
||
22 | { |
||
23 | foreach ($tokens as $i => $token) { |
||
24 | if ($token[0] == T_DOC_COMMENT) { |
||
25 | if (Str::contains($token[1], [ |
||
26 | 'Remove the specified resource from storage.', |
||
27 | 'Update the specified resource in storage.', |
||
28 | 'Store a newly created resource in storage.', |
||
29 | 'Display the specified resource.', |
||
30 | 'Display a listing of the resource.', |
||
31 | 'Show the form for creating a new resource.', |
||
32 | 'Show the form for editing the specified resource.', |
||
33 | ])) { |
||
34 | unset($tokens[$i]); |
||
35 | if ($tokens[$i + 1][0] == T_WHITESPACE) { |
||
36 | unset($tokens[$i + 1]); |
||
37 | } |
||
38 | Refactor::saveTokens($absFilePath, $tokens); |
||
39 | } |
||
40 | } |
||
41 | |||
42 | if (\in_array($token[0], [T_PUBLIC, T_PRIVATE, T_PROTECTED]) && ($tokens[$i - 1][0] == T_WHITESPACE)) { |
||
43 | View Code Duplication | if (($tokens[$i - 2][0] == '}') && $tokens[$i - 1][1] != "\n\n ") { |
|
44 | $tokens[$i - 1][1] = "\n\n "; |
||
45 | Refactor::saveTokens($absFilePath, $tokens); |
||
46 | } |
||
47 | |||
48 | View Code Duplication | if (($tokens[$i - 2][0] == '{') && $tokens[$i - 1][1] != "\n ") { |
|
49 | $tokens[$i - 1][1] = "\n "; |
||
50 | Refactor::saveTokens($absFilePath, $tokens); |
||
51 | } |
||
52 | } |
||
53 | } |
||
54 | } |
||
55 | } |
||
56 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.