|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* CodingStandard_Sniffs_NamingConventions_ValidInterfaceNameSniff. |
|
4
|
|
|
* |
|
5
|
|
|
* PHP version 5 |
|
6
|
|
|
* |
|
7
|
|
|
* @category PHP |
|
8
|
|
|
* @package PHP_CodeSniffer |
|
9
|
|
|
* @author Symfony2-phpcs-authors <[email protected]> |
|
10
|
|
|
* @author Alexander Obuhovich <[email protected]> |
|
11
|
|
|
* @license https://github.com/aik099/CodingStandard/blob/master/LICENSE BSD 3-Clause |
|
12
|
|
|
* @link https://github.com/aik099/CodingStandard |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace CodingStandard\Sniffs\NamingConventions; |
|
16
|
|
|
|
|
17
|
|
|
use PHP_CodeSniffer\Files\File; |
|
18
|
|
|
use PHP_CodeSniffer\Sniffs\Sniff; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* CodingStandard_Sniffs_NamingConventions_ValidInterfaceNameSniff. |
|
22
|
|
|
* |
|
23
|
|
|
* Throws errors if interface names are not prefixed with "I". |
|
24
|
|
|
* |
|
25
|
|
|
* @category PHP |
|
26
|
|
|
* @package PHP_CodeSniffer |
|
27
|
|
|
* @author Alexander Obuhovich <[email protected]> |
|
28
|
|
|
* @license https://github.com/aik099/CodingStandard/blob/master/LICENSE BSD 3-Clause |
|
29
|
|
|
* @link https://github.com/aik099/CodingStandard |
|
30
|
|
|
*/ |
|
31
|
|
|
class ValidInterfaceNameSniff implements Sniff |
|
32
|
|
|
{ |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* A list of tokenizers this sniff supports. |
|
36
|
|
|
* |
|
37
|
|
|
* @var array |
|
38
|
|
|
*/ |
|
39
|
|
|
public $supportedTokenizers = array('PHP'); |
|
40
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Returns an array of tokens this test wants to listen for. |
|
44
|
|
|
* |
|
45
|
|
|
* @return integer[] |
|
46
|
|
|
*/ |
|
47
|
1 |
|
public function register() |
|
48
|
|
|
{ |
|
49
|
1 |
|
return array(T_INTERFACE); |
|
50
|
|
|
}//end register() |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Processes this test, when one of its tokens is encountered. |
|
55
|
|
|
* |
|
56
|
|
|
* @param File $phpcsFile The file being scanned. |
|
57
|
|
|
* @param int $stackPtr The position of the current token in the |
|
58
|
|
|
* stack passed in $tokens. |
|
59
|
|
|
* |
|
60
|
|
|
* @return void |
|
61
|
|
|
*/ |
|
62
|
1 |
|
public function process(File $phpcsFile, $stackPtr) |
|
63
|
|
|
{ |
|
64
|
1 |
|
$interfaceName = $phpcsFile->getDeclarationName($stackPtr); |
|
65
|
1 |
|
$firstLetter = $interfaceName[0]; |
|
66
|
1 |
|
$secondLetter = $interfaceName[1]; |
|
67
|
|
|
|
|
68
|
1 |
|
if ($firstLetter !== 'I' || $secondLetter === strtolower($secondLetter)) { |
|
69
|
1 |
|
$phpcsFile->addError( |
|
70
|
1 |
|
'Interface name is not prefixed with "I"', |
|
71
|
1 |
|
$stackPtr, |
|
72
|
|
|
'WrongPrefix' |
|
73
|
1 |
|
); |
|
74
|
1 |
|
} |
|
75
|
1 |
|
}//end process() |
|
76
|
|
|
}//end class |
|
77
|
|
|
|