Conditions | 7 |
Paths | 20 |
Total Lines | 56 |
Code Lines | 36 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
67 | public function process(File $phpcsFile, $stackPtr): void |
||
68 | { |
||
69 | $tokens = $phpcsFile->getTokens(); |
||
70 | $current = $tokens[$stackPtr]; |
||
71 | |||
72 | if (T_ARRAY === $current['code']) { |
||
73 | $arrayType = 'parenthesis'; |
||
74 | $start = $current['parenthesis_opener']; |
||
75 | $end = $current['parenthesis_closer']; |
||
76 | } else { |
||
77 | $arrayType = 'bracket'; |
||
78 | $start = $current['bracket_opener']; |
||
79 | $end = $current['bracket_closer']; |
||
80 | } |
||
81 | |||
82 | if ($tokens[$start]['line'] === $tokens[$end]['line']) { |
||
83 | return; |
||
84 | } |
||
85 | |||
86 | if ($tokens[($start + 2)]['line'] === $tokens[$start]['line']) { |
||
87 | $fixable = $phpcsFile->addFixableError( |
||
88 | \sprintf( |
||
89 | 'opening %s of multi line array must be followed by newline', |
||
90 | $arrayType |
||
91 | ), |
||
92 | $start, |
||
93 | 'OpeningMustBeFollowedByNewline' |
||
94 | ); |
||
95 | |||
96 | if (true === $fixable) { |
||
97 | $phpcsFile->fixer->beginChangeset(); |
||
98 | $phpcsFile->fixer->addNewline($start); |
||
99 | $phpcsFile->fixer->endChangeset(); |
||
100 | } |
||
101 | } |
||
102 | |||
103 | if ($tokens[($end - 2)]['line'] !== $tokens[$end]['line']) { |
||
104 | return; |
||
105 | } |
||
106 | |||
107 | $fixable = $phpcsFile->addFixableError( |
||
108 | \sprintf( |
||
109 | 'closing %s of multi line array must in own line', |
||
110 | $arrayType |
||
111 | ), |
||
112 | $end, |
||
113 | 'ClosingMustBeInOwnLine' |
||
114 | ); |
||
115 | |||
116 | if (true !== $fixable) { |
||
117 | return; |
||
118 | } |
||
119 | |||
120 | $phpcsFile->fixer->beginChangeset(); |
||
121 | $phpcsFile->fixer->addNewlineBefore($end); |
||
122 | $phpcsFile->fixer->endChangeset(); |
||
123 | } |
||
125 |