| Conditions | 13 |
| Paths | 16 |
| Total Lines | 56 |
| Code Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| Bugs | 1 | 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 |
||
| 27 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
| 28 | { |
||
| 29 | if ($this->supportsAbove('7.0') === false) { |
||
| 30 | return; |
||
| 31 | } |
||
| 32 | |||
| 33 | if ($this->determineNamespace($phpcsFile, $stackPtr) !== '') { |
||
| 34 | /* |
||
| 35 | * Namespaced methods with the same name as the class are treated as |
||
| 36 | * regular methods, so we can bow out if we're in a namespace. |
||
| 37 | * |
||
| 38 | * Note: the exception to this is PHP 5.3.0-5.3.2. This is currently |
||
| 39 | * not dealt with. |
||
| 40 | */ |
||
| 41 | return; |
||
| 42 | } |
||
| 43 | |||
| 44 | $tokens = $phpcsFile->getTokens(); |
||
| 45 | |||
| 46 | $class = $tokens[$stackPtr]; |
||
| 47 | |||
| 48 | if(!IsSet($class['scope_closer'])) { |
||
| 49 | return; |
||
| 50 | } |
||
| 51 | |||
| 52 | $scopeCloser = $class['scope_closer']; |
||
| 53 | $className = $phpcsFile->getDeclarationName($stackPtr); |
||
| 54 | |||
| 55 | if (empty($className) || is_string($className) === false) { |
||
| 56 | return; |
||
| 57 | } |
||
| 58 | |||
| 59 | $nextFunc = $stackPtr; |
||
| 60 | $newConstructorFound = false; |
||
| 61 | $oldConstructorFound = false; |
||
| 62 | $oldConstructorPos = false; |
||
| 63 | while (($nextFunc = $phpcsFile->findNext(T_FUNCTION, ($nextFunc + 1), $scopeCloser)) !== false) { |
||
| 64 | $funcName = $phpcsFile->getDeclarationName($nextFunc); |
||
| 65 | if (empty($funcName) || is_string($funcName) === false) { |
||
| 66 | continue; |
||
| 67 | } |
||
| 68 | |||
| 69 | if ($funcName === '__construct') { |
||
| 70 | $newConstructorFound = true; |
||
| 71 | } |
||
| 72 | |||
| 73 | if ($funcName === $className) { |
||
| 74 | $oldConstructorFound = true; |
||
| 75 | $oldConstructorPos = $phpcsFile->findNext(T_STRING, $nextFunc); |
||
| 76 | } |
||
| 77 | } |
||
| 78 | |||
| 79 | if ($newConstructorFound === false && $oldConstructorFound === true) { |
||
| 80 | $phpcsFile->addError('Deprecated PHP4 style constructor are not supported since PHP7', $oldConstructorPos); |
||
| 81 | } |
||
| 82 | } |
||
| 83 | } |
||
| 84 |
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.