| Conditions | 12 |
| Paths | 12 |
| Total Lines | 72 |
| Code Lines | 38 |
| Lines | 3 |
| Ratio | 4.17 % |
| 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 |
||
| 52 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
| 53 | { |
||
| 54 | if ($this->supportsAbove('5.3') === false) { |
||
| 55 | return; |
||
| 56 | } |
||
| 57 | |||
| 58 | $tokens = $phpcsFile->getTokens(); |
||
| 59 | |||
| 60 | // Skip tokens that are the names of functions or classes |
||
| 61 | // within their definitions. For example: function myFunction... |
||
| 62 | // "myFunction" is T_STRING but we should skip because it is not a |
||
| 63 | // function or method *call*. |
||
| 64 | $findTokens = array_merge( |
||
| 65 | PHP_CodeSniffer_Tokens::$emptyTokens, |
||
| 66 | array(T_BITWISE_AND) |
||
| 67 | ); |
||
| 68 | |||
| 69 | $prevNonEmpty = $phpcsFile->findPrevious( |
||
| 70 | $findTokens, |
||
| 71 | ($stackPtr - 1), |
||
| 72 | null, |
||
| 73 | true |
||
| 74 | ); |
||
| 75 | |||
| 76 | if ($prevNonEmpty !== false && in_array($tokens[$prevNonEmpty]['code'], array(T_FUNCTION, T_CLASS, T_INTERFACE, T_TRAIT), true)) { |
||
| 77 | return; |
||
| 78 | } |
||
| 79 | |||
| 80 | // If the next non-whitespace token after the function or method call |
||
| 81 | // is not an opening parenthesis then it can't really be a *call*. |
||
| 82 | $openBracket = $phpcsFile->findNext( |
||
| 83 | PHP_CodeSniffer_Tokens::$emptyTokens, |
||
| 84 | ($stackPtr + 1), |
||
| 85 | null, |
||
| 86 | true |
||
| 87 | ); |
||
| 88 | |||
| 89 | if ($openBracket === false || $tokens[$openBracket]['code'] !== T_OPEN_PARENTHESIS |
||
| 90 | || isset($tokens[$openBracket]['parenthesis_closer']) === false |
||
| 91 | ) { |
||
| 92 | return; |
||
| 93 | } |
||
| 94 | |||
| 95 | // Get the function call parameters. |
||
| 96 | $parameters = $this->getFunctionCallParameters($phpcsFile, $stackPtr); |
||
| 97 | if (count($parameters) === 0) { |
||
| 98 | return; |
||
| 99 | } |
||
| 100 | |||
| 101 | // Which nesting level is the one we are interested in ? |
||
| 102 | $nestedParenthesisCount = 1; |
||
| 103 | View Code Duplication | if (isset($tokens[$openBracket]['nested_parenthesis'])) { |
|
|
1 ignored issue
–
show
|
|||
| 104 | $nestedParenthesisCount = count($tokens[$openBracket]['nested_parenthesis']) + 1; |
||
| 105 | } |
||
| 106 | |||
| 107 | foreach ($parameters as $parameter) { |
||
| 108 | if ($this->isCallTimePassByReferenceParam($phpcsFile, $parameter, $nestedParenthesisCount) === true) { |
||
| 109 | // T_BITWISE_AND represents a pass-by-reference. |
||
| 110 | $error = 'Using a call-time pass-by-reference is deprecated since PHP 5.3'; |
||
| 111 | $isError = false; |
||
| 112 | $errorCode = 'Deprecated'; |
||
| 113 | |||
| 114 | if($this->supportsAbove('5.4')) { |
||
| 115 | $error .= ' and prohibited since PHP 5.4'; |
||
| 116 | $isError = true; |
||
| 117 | $errorCode = 'NotAllowed'; |
||
| 118 | } |
||
| 119 | |||
| 120 | $this->addMessage($phpcsFile, $error, $parameter['start'], $isError, $errorCode); |
||
| 121 | } |
||
| 122 | } |
||
| 123 | }//end process() |
||
| 124 | |||
| 237 |
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.