/
ExtraneousClassSniff.php
48 lines (43 loc) · 1.4 KB
/
ExtraneousClassSniff.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
class PHPUnitStandard_Sniffs_Testing_ExtraneousClassSniff
implements PHP_CodeSniffer_Sniff {
/**
* Returns the token types that this sniff is interested in.
*
* @return array(int)
*/
public function register() {
return array(
T_CLASS,
);
}
/**
* Processes the tokens that this sniff is interested in.
*
* @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
* @param int $stackPtr The position in the stack where
* the token was found.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) {
$filename = $phpcsFile->getFileName();
if(!preg_match("@.*/tests/phpunit/(.*).php@", $filename, $matches)) {
$phpcsFile->addWarning(
'Filepath does not match expected convention',
$stackPtr
);
return;
}
$expected = str_replace("/", "_", $matches[1]);
$declarationName = $phpcsFile->getDeclarationName($stackPtr);
if ($declarationName != $expected) {
$phpcsFile->addError(
'Unexpected extraneous class found: %s. Expected: %s',
$stackPtr,
'Found',
array($declarationName, $expected)
);
}
}
}