| Conditions | 11 |
| Paths | 13 |
| Total Lines | 58 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
| 68 | { |
||
| 69 | $tokens = $phpcsFile->getTokens(); |
||
| 70 | |||
| 71 | $ignore = array( |
||
| 72 | T_DOUBLE_COLON, |
||
| 73 | T_OBJECT_OPERATOR, |
||
| 74 | T_FUNCTION, |
||
| 75 | T_CONST, |
||
| 76 | ); |
||
| 77 | |||
| 78 | $prevToken = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); |
||
| 79 | if (in_array($tokens[$prevToken]['code'], $ignore) === true) { |
||
| 80 | // Not a call to a PHP function. |
||
| 81 | return; |
||
| 82 | } |
||
| 83 | |||
| 84 | $function = strtolower($tokens[$stackPtr]['content']); |
||
| 85 | |||
| 86 | if (isset($this->functionParameters[$function]) === false) { |
||
| 87 | return; |
||
| 88 | } |
||
| 89 | |||
| 90 | $parameterCount = $this->getFunctionCallParameterCount($phpcsFile, $stackPtr); |
||
| 91 | if ($parameterCount === 0) { |
||
| 92 | return; |
||
| 93 | } |
||
| 94 | |||
| 95 | // If the parameter count returned > 0, we know there will be valid open parenthesis. |
||
| 96 | $openParenthesis = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true); |
||
| 97 | $parameterOffsetFound = $parameterCount - 1; |
||
| 98 | $requiredVersion = null; |
||
| 99 | $parameterName = null; |
||
| 100 | |||
| 101 | foreach($this->functionParameters[$function] as $offset => $parameterDetails) { |
||
| 102 | if ($offset > $parameterOffsetFound) { |
||
| 103 | foreach ($parameterDetails as $version => $present) { |
||
| 104 | if ($version !== 'name' && $present === true && $this->supportsBelow($version)) { |
||
| 105 | $requiredVersion = $version; |
||
| 106 | $parameterName = $parameterDetails['name']; |
||
| 107 | } |
||
| 108 | } |
||
| 109 | } |
||
| 110 | } |
||
| 111 | |||
| 112 | if (isset($requiredVersion, $parameterName)) { |
||
| 113 | |||
| 114 | $error = 'The "%s" parameter for function %s is missing, but was required for PHP version %s and lower'; |
||
| 115 | $errorCode = 'MissingRequiredParameter'; |
||
| 116 | $data = array( |
||
| 117 | $parameterName, |
||
| 118 | $function, |
||
| 119 | $requiredVersion, |
||
| 120 | ); |
||
| 121 | $phpcsFile->addError($error, $openParenthesis, $errorCode, $data); |
||
| 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.