Completed
Pull Request — master (#382)
by Juliette
02:08
created

CaseSensitiveKeywordsSniff   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 45
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 8 1
A process() 0 18 3
1
<?php
2
/**
3
 * PHPCompatibility_Sniffs_PHP_CaseSensitiveKeywordsSniff.
4
 *
5
 * PHP version 5.5
6
 *
7
 * @category PHP
8
 * @package  PHPCompatibility
9
 * @author   Juliette Reinders Folmer <[email protected]>
10
 */
11
12
/**
13
 * PHPCompatibility_Sniffs_PHP_CaseSensitiveKeywordsSniff.
14
 *
15
 * Prior to PHP 5.5, cases existed where the self, parent, and static keywords
16
 * were treated in a case sensitive fashion.
17
 *
18
 * PHP version 5.5
19
 *
20
 * @category PHP
21
 * @package  PHPCompatibility
22
 * @author   Juliette Reinders Folmer <[email protected]>
23
 */
24
class PHPCompatibility_Sniffs_PHP_CaseSensitiveKeywordsSniff extends PHPCompatibility_Sniff
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

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.

Loading history...
25
{
26
27
    /**
28
     * Returns an array of tokens this test wants to listen for.
29
     *
30
     * @return array
31
     */
32
    public function register()
33
    {
34
        return array(
35
			T_SELF,
36
			T_STATIC,
37
			T_PARENT,
38
		);
39
    }
40
41
    /**
42
     * Processes this test, when one of its tokens is encountered.
43
     *
44
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
45
     * @param int                  $stackPtr  The position of the current token in the
46
     *                                        stack passed in $tokens.
47
     *
48
     * @return void
49
     */
50
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
51
    {
52
        if ($this->supportsBelow('5.4') === false) {
53
			return;
54
		}
55
56
        $tokens         = $phpcsFile->getTokens();
57
        $tokenContentLC = strtolower($tokens[$stackPtr]['content']);
58
        
59
        if ($tokenContentLC !== $tokens[$stackPtr]['content']) {
60
            $phpcsFile->addError(
61
                'The keyword \'%s\' was treated in a case-sensitive fashion in certain cases in PHP 5.4 or earlier. Use the lowercase version for consistent support.',
62
                $stackPtr,
63
                'NonLowercaseFound',
64
                array($tokenContentLC)
65
            );
66
        }
67
    }
68
}
69