| Conditions | 15 |
| Paths | 10 |
| Total Lines | 65 |
| Code Lines | 29 |
| Lines | 35 |
| Ratio | 53.85 % |
| 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 |
||
| 50 | 'property' => 'class properties', |
||
| 51 | 'staticvar' => 'static variables', |
||
| 52 | 'default' => 'default parameter values', |
||
| 53 | ); |
||
| 54 | |||
| 55 | |||
| 56 | /** |
||
| 57 | * Do a version check to determine if this sniff needs to run at all. |
||
| 58 | * |
||
| 59 | * @return bool |
||
| 60 | */ |
||
| 61 | protected function bowOutEarly() |
||
| 62 | { |
||
| 63 | return ($this->supportsBelow('5.2') !== true); |
||
| 64 | } |
||
| 65 | |||
| 66 | |||
| 67 | /** |
||
| 68 | * Is a value declared and does the declared value not contain an heredoc ? |
||
| 69 | * |
||
| 70 | * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
| 71 | * @param int $stackPtr The position of the current token in the |
||
| 72 | * stack passed in $tokens. |
||
| 73 | * @param int $end The end of the value definition. |
||
| 74 | * |
||
| 75 | * @return bool True if no heredoc (or assignment) is found, false otherwise. |
||
| 76 | */ |
||
| 77 | protected function isValidAssignment(\PHP_CodeSniffer_File $phpcsFile, $stackPtr, $end) |
||
| 78 | { |
||
| 79 | $tokens = $phpcsFile->getTokens(); |
||
| 80 | $next = $phpcsFile->findNext(\PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), $end, true); |
||
| 81 | if ($next === false || $tokens[$next]['code'] !== T_EQUAL) { |
||
| 82 | // No value assigned. |
||
| 83 | return true; |
||
| 84 | } |
||
| 85 | |||
| 86 | return ($phpcsFile->findNext(T_START_HEREDOC, ($next + 1), $end, false, null, true) === false); |
||
| 87 | } |
||
| 88 | } |
||
| 89 |