for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* PHPCompatibility_Sniffs_PHP_NewMagicClassConstantSniff.
*
* PHP version 5.5
* @category PHP
* @package PHPCompatibility
* @author Juliette Reinders Folmer <[email protected]>
*/
* The special ClassName::class constant is available as of PHP 5.5.0, and allows for
* fully qualified class name resolution at compile.
class PHPCompatibility_Sniffs_PHP_NewMagicClassConstantSniff extends PHPCompatibility_Sniff
You can fix this by adding a namespace to your class:
namespace YourVendor; class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.
{
* Returns an array of tokens this test wants to listen for.
* @return array
public function register()
return array(T_STRING);
}
* Processes this test, when one of its tokens is encountered.
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token in the
* stack passed in $tokens.
* @return void
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
if ($this->supportsBelow('5.4') === false) {
return;
$tokens = $phpcsFile->getTokens();
if (strtolower($tokens[$stackPtr]['content']) !== 'class') {
$prevToken = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true, null, true);
if ($prevToken === false || $tokens[$prevToken]['code'] !== T_DOUBLE_COLON) {
$phpcsFile->addError(
'The magic class constant ClassName::class was not available in PHP 5.4 or earlier',
$stackPtr,
'Found'
);
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.