| Conditions | 14 |
| Paths | 19 |
| Total Lines | 67 |
| Code Lines | 30 |
| Lines | 6 |
| Ratio | 8.96 % |
| 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 |
||
| 58 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
| 59 | { |
||
| 60 | if ($this->supportsBelow('5.2') === false) { |
||
| 61 | return; |
||
| 62 | } |
||
| 63 | |||
| 64 | $tokens = $phpcsFile->getTokens(); |
||
| 65 | ini_set( 'xdebug.overload_var_dump', 1 ); |
||
| 66 | |||
| 67 | static $dumped = false; |
||
| 68 | if($dumped === false) { |
||
| 69 | echo "\n"; |
||
| 70 | foreach( $tokens as $ptr => $token ) { |
||
| 71 | echo $ptr . ' :: L' . $token['line'] . ' :: C' . $token['column'] . ' :: ' . $token['type'] . ' :: (' . strlen($token['content']) . ') :: ' . $token['content'] . "\n"; |
||
| 72 | // if ( $token['code'] === T_WHILE || $token['code'] === T_DO || $token['code'] === T_FUNCTION ) { |
||
| 73 | // var_dump( $token ); |
||
| 74 | // } |
||
| 75 | } |
||
| 76 | unset( $ptr, $token ); |
||
| 77 | $dumped = true; |
||
| 78 | var_dump( $tokens[$stackPtr] ); |
||
| 79 | } |
||
| 80 | |||
| 81 | /* |
||
| 82 | * In PHP 5.2 the T_NOWDOC tokens aren't recognized yet and PHPCS does not |
||
| 83 | * backfill for it, so we have to sniff for a specific combination of tokens. |
||
| 84 | */ |
||
| 85 | if ($tokens[$stackPtr]['code'] === T_SL) { |
||
| 86 | View Code Duplication | if (isset($tokens[($stackPtr+1)]) === false || $tokens[($stackPtr + 1)]['code'] !== T_LESS_THAN) { |
|
|
1 ignored issue
–
show
|
|||
| 87 | return; |
||
| 88 | } |
||
| 89 | |||
| 90 | View Code Duplication | if (isset($tokens[($stackPtr+2)]) === false || $tokens[($stackPtr + 2)]['code'] !== T_CONSTANT_ENCAPSED_STRING) { |
|
|
1 ignored issue
–
show
|
|||
| 91 | return; |
||
| 92 | } |
||
| 93 | |||
| 94 | /* |
||
| 95 | * Heredoc and nowdoc naming rules: |
||
| 96 | * "it must contain only alphanumeric characters and underscores and |
||
| 97 | * must start with a non-digit character or underscore" |
||
| 98 | * @link http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc |
||
| 99 | */ |
||
| 100 | if (preg_match('`^\'([a-z][a-z0-9_]*)\'$`iD', $tokens[($stackPtr + 2)]['content'], $matches) < 1) { |
||
| 101 | return; |
||
| 102 | } |
||
| 103 | |||
| 104 | $closer = $phpcsFile->findNext(T_STRING, ($stackPtr + 3), null, false, $matches[1], true); |
||
| 105 | // The closing identifier must begin in the first column of the line. |
||
| 106 | if ($closer === false || $tokens[($closer - 1)]['column'] !== 1) { |
||
| 107 | return; |
||
| 108 | } |
||
| 109 | |||
| 110 | // The closing identifier must be the only content on that line, except for maybe a semi-colon. |
||
| 111 | $next = $phpcsFile->findNext(array(T_WHITESPACE, T_SEMICOLON), ($closer + 1), null, true); |
||
| 112 | if ($tokens[$closer]['line'] === $tokens[$next]['line']) { |
||
| 113 | return; |
||
| 114 | } |
||
| 115 | } |
||
| 116 | |||
| 117 | $phpcsFile->addError('Nowdocs are not present in PHP version 5.2 or earlier.', $stackPtr, 'Found'); |
||
| 118 | |||
| 119 | if (isset($closer) !== false) { |
||
| 120 | $phpcsFile->addError('Nowdocs are not present in PHP version 5.2 or earlier.', $closer, 'Found'); |
||
|
1 ignored issue
–
show
|
|||
| 121 | return ($closer + 1); |
||
| 122 | } |
||
| 123 | |||
| 124 | }//end process() |
||
| 125 | |||
| 127 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.