| Conditions | 5 |
| Paths | 4 |
| Total Lines | 23 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 46 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
| 47 | { |
||
| 48 | if ($this->supportsBelow('5.4') === false) { |
||
| 49 | return; |
||
| 50 | } |
||
| 51 | |||
| 52 | $tokens = $phpcsFile->getTokens(); |
||
| 53 | |||
| 54 | if (strtolower($tokens[$stackPtr]['content']) !== 'class') { |
||
| 55 | return; |
||
| 56 | } |
||
| 57 | |||
| 58 | $prevToken = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true, null, true); |
||
| 59 | if ($prevToken === false || $tokens[$prevToken]['code'] !== T_DOUBLE_COLON) { |
||
| 60 | return; |
||
| 61 | } |
||
| 62 | |||
| 63 | $phpcsFile->addError( |
||
| 64 | 'The magic class constant ClassName::class was not available in PHP 5.4 or earlier', |
||
| 65 | $stackPtr, |
||
| 66 | 'Found' |
||
| 67 | ); |
||
| 68 | } |
||
| 69 | } |
||
| 70 |
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.