Completed
Pull Request — master (#110)
by Wim
03:06
created

NewGroupUseDeclarationsSniff   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 33
rs 10
wmc 4
lcom 0
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 6 2
A register() 0 8 2
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 (version_compare(PHP_CodeSniffer::VERSION, '2.3.4') >= 0) {
29
            return array(T_OPEN_USE_GROUP);
30
        } else {
31
            return array();
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->supportsAbove('7.0')) {
48
            $phpcsFile->addError('Group use declarations are not allowed in PHP 5.6 or earlier', $stackPtr);
49
        }
50
    }//end process()
51
}//end class
52