Conditions | 10 |
Paths | 13 |
Total Lines | 39 |
Code Lines | 25 |
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 |
||
50 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
51 | { |
||
52 | if ($this->supportsAbove('5.4') === false) { |
||
53 | return; |
||
54 | } |
||
55 | |||
56 | $tokens = $phpcsFile->getTokens(); |
||
57 | $nextSemicolonToken = $phpcsFile->findNext(T_SEMICOLON, ($stackPtr), null, false); |
||
58 | $isError = false; |
||
59 | $errorType = ''; |
||
60 | for ($curToken = $stackPtr + 1; $curToken < $nextSemicolonToken; $curToken++) { |
||
61 | if ($tokens[$curToken]['type'] === 'T_STRING') { |
||
62 | // If the next non-whitespace token after the string |
||
63 | // is an opening parenthesis then it's a function call. |
||
64 | $openBracket = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $curToken + 1, null, true); |
||
65 | if ($tokens[$openBracket]['code'] === T_OPEN_PARENTHESIS) { |
||
66 | $isError = true; |
||
67 | $errorType = self::ERROR_TYPE_VARIABLE; |
||
68 | break; |
||
69 | } |
||
70 | } |
||
71 | else if (in_array($tokens[$curToken]['type'], array('T_VARIABLE', 'T_FUNCTION', 'T_CLOSURE'), true)) { |
||
72 | $isError = true; |
||
73 | $errorType = self::ERROR_TYPE_VARIABLE; |
||
74 | break; |
||
75 | } |
||
76 | else if ($tokens[$curToken]['type'] === 'T_LNUMBER' && $tokens[$curToken]['content'] === '0') { |
||
77 | $isError = true; |
||
78 | $errorType = self::ERROR_TYPE_ZERO; |
||
79 | break; |
||
80 | } |
||
81 | } |
||
82 | |||
83 | if ($isError === true && !empty($errorType)) { |
||
84 | $error = 'Using ' . $errorType . ' on break or continue is forbidden since PHP 5.4'; |
||
85 | $phpcsFile->addError($error, $stackPtr); |
||
86 | } |
||
87 | |||
88 | }//end process() |
||
89 | |||
91 |