| Conditions | 11 |
| Paths | 17 |
| Total Lines | 68 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 133 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
| 134 | { |
||
| 135 | // Should be removed, the requirement was previously also there, 5.3 just started throwing a warning about it. |
||
| 136 | if ($this->supportsAbove('5.3') === false) { |
||
| 137 | return; |
||
| 138 | } |
||
| 139 | |||
| 140 | $tokens = $phpcsFile->getTokens(); |
||
| 141 | |||
| 142 | if (isset($tokens[$stackPtr]['scope_closer']) === false) { |
||
| 143 | return; |
||
| 144 | } |
||
| 145 | |||
| 146 | $classScopeCloser = $tokens[$stackPtr]['scope_closer']; |
||
| 147 | $functionPtr = $stackPtr; |
||
| 148 | |||
| 149 | // Find all the functions in this class or interface. |
||
| 150 | while ($functionToken = $phpcsFile->findNext(T_FUNCTION, $functionPtr, $classScopeCloser)) { |
||
| 151 | /* |
||
| 152 | * Get the scope closer for this function in order to know how |
||
| 153 | * to advance to the next function. |
||
| 154 | * If no body of function (e.g. for interfaces), there is |
||
| 155 | * no closing curly brace; advance the pointer differently. |
||
| 156 | */ |
||
| 157 | $scopeCloser = isset($tokens[$functionToken]['scope_closer']) |
||
| 158 | ? $tokens[$functionToken]['scope_closer'] |
||
| 159 | : $functionToken + 1; |
||
| 160 | |||
| 161 | |||
| 162 | $methodName = $phpcsFile->getDeclarationName($functionToken); |
||
| 163 | $methodNameLc = strtolower($methodName); |
||
| 164 | if (isset($this->magicMethods[$methodNameLc]) === false) { |
||
| 165 | $functionPtr = $scopeCloser; |
||
| 166 | continue; |
||
| 167 | } |
||
| 168 | |||
| 169 | $methodProperties = $phpcsFile->getMethodProperties($functionToken); |
||
| 170 | |||
| 171 | if (isset($this->magicMethods[$methodNameLc]['visibility']) && $this->magicMethods[$methodNameLc]['visibility'] !== $methodProperties['scope']) { |
||
| 172 | $error = 'Visibility for magic method %s must be %s. Found: %s'; |
||
| 173 | $data = array( |
||
| 174 | $methodName, |
||
| 175 | $this->magicMethods[$methodNameLc]['visibility'], |
||
| 176 | $methodProperties['scope'], |
||
| 177 | ); |
||
| 178 | |||
| 179 | $phpcsFile->addError($error, $functionToken, 'MethodVisibility', $data); |
||
| 180 | } |
||
| 181 | |||
| 182 | if (isset($this->magicMethods[$methodNameLc]['static']) && $this->magicMethods[$methodNameLc]['static'] !== $methodProperties['is_static']) { |
||
| 183 | $error = 'Magic method %s cannot be defined as static.'; |
||
| 184 | $errorCode = 'MethodStatic'; |
||
| 185 | if ( $this->magicMethods[$methodNameLc]['static'] === true ) { |
||
| 186 | $error = 'Magic method %s must be defined as static.'; |
||
| 187 | $errorCode = 'MethodNonStatic'; |
||
| 188 | } |
||
| 189 | $data = array( |
||
| 190 | $methodName, |
||
| 191 | ); |
||
| 192 | |||
| 193 | $phpcsFile->addError($error, $functionToken, $errorCode, $data); |
||
| 194 | } |
||
| 195 | |||
| 196 | // Advance to next function. |
||
| 197 | $functionPtr = $scopeCloser; |
||
| 198 | } |
||
| 199 | |||
| 200 | }//end process() |
||
| 201 | |||
| 204 |
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.