| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * PHPCompatibility_Sniffs_PHP_NewGroupUseDeclarationsSniff. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * PHP version 7.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @category  PHP | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * @package   PHPCompatibility | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * @author    Wim Godden <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * PHPCompatibility_Sniffs_PHP_NewGroupUseDeclarationsSniff. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * @category  PHP | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * @package   PHPCompatibility | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * @author    Wim Godden <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | class PHPCompatibility_Sniffs_PHP_NewGroupUseDeclarationsSniff extends PHPCompatibility_Sniff | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      * Returns an array of tokens this test wants to listen for. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     public function register() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         if (defined('T_OPEN_USE_GROUP')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |             return array(T_OPEN_USE_GROUP); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |             return array(T_USE); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     }//end register() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      * Processes this test, when one of its tokens is encountered. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      * @param int                  $stackPtr  The position of the current token in | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      *                                        the stack passed in $tokens. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      * @return void | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 44 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 45 |  |  |     public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) | 
            
                                                        
            
                                    
            
            
                | 46 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 47 |  |  |         if ($this->supportsBelow('5.6') === false) { | 
            
                                                        
            
                                    
            
            
                | 48 |  |  |             return; | 
            
                                                        
            
                                    
            
            
                | 49 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 51 |  |  |         $tokens = $phpcsFile->getTokens(); | 
            
                                                        
            
                                    
            
            
                | 52 |  |  |         $token  = $tokens[$stackPtr]; | 
            
                                                        
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 54 |  |  |         // Deal with PHPCS pre-2.6.0. | 
            
                                                        
            
                                    
            
            
                | 55 |  |  |         if ($token['code'] === T_USE) { | 
            
                                                        
            
                                    
            
            
                | 56 |  |  |             $hasCurlyBrace = $phpcsFile->findNext(T_OPEN_CURLY_BRACKET, ($stackPtr + 1), null, false, null, true); | 
            
                                                        
            
                                    
            
            
                | 57 |  |  |             if ($hasCurlyBrace === false) { | 
            
                                                        
            
                                    
            
            
                | 58 |  |  |                 return; | 
            
                                                        
            
                                    
            
            
                | 59 |  |  |             } | 
            
                                                        
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 61 |  |  |             $prevToken = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($hasCurlyBrace - 1), null, true); | 
            
                                                        
            
                                    
            
            
                | 62 |  |  |             if ($prevToken === false || $tokens[$prevToken]['code'] !== T_NS_SEPARATOR) { | 
            
                                                        
            
                                    
            
            
                | 63 |  |  | 				return; | 
            
                                                        
            
                                    
            
            
                | 64 |  |  | 			} | 
            
                                                        
            
                                    
            
            
                | 65 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 67 |  |  |         // Still here ? In that case, it is a group use statement. | 
            
                                                        
            
                                    
            
            
                | 68 |  |  |         $phpcsFile->addError( | 
            
                                                        
            
                                    
            
            
                | 69 |  |  |             'Group use declarations are not allowed in PHP 5.6 or earlier', | 
            
                                                        
            
                                    
            
            
                | 70 |  |  |             $stackPtr, | 
            
                                                        
            
                                    
            
            
                | 71 |  |  |             'Found' | 
            
                                                        
            
                                    
            
            
                | 72 |  |  |         ); | 
            
                                                        
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 74 |  |  |     }//end process() | 
            
                                                        
            
                                    
            
            
                | 75 |  |  | }//end class | 
            
                                                        
            
                                    
            
            
                | 76 |  |  |  | 
            
                        
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.