3
* Squiz_Sniffs_Classes_ClassFileNameSniff.
8
* @package PHP_CodeSniffer
9
* @author Greg Sherwood <gsherwood@squiz.net>
10
* @author Marc McIntyre <mmcintyre@squiz.net>
11
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
12
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
13
* @version CVS: $Id: ClassFileNameSniff.php,v 1.2 2007/07/23 01:47:53 squiz Exp $
14
* @link http://pear.php.net/package/PHP_CodeSniffer
18
* Squiz_Sniffs_Classes_ClassFileNameSniff.
20
* Tests that the file name and the name of the class contained within the file
24
* @package PHP_CodeSniffer
25
* @author Greg Sherwood <gsherwood@squiz.net>
26
* @author Marc McIntyre <mmcintyre@squiz.net>
27
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
28
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
29
* @version Release: 1.0.1
30
* @link http://pear.php.net/package/PHP_CodeSniffer
32
class Squiz_Sniffs_Classes_ClassFileNameSniff implements PHP_CodeSniffer_Sniff
37
* Returns an array of tokens this test wants to listen for.
41
public function register()
52
* Processes this test, when one of its tokens is encountered.
54
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
55
* @param int $stackPtr The position of the current token in the
56
* stack passed in $tokens.
60
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
62
$tokens = $phpcsFile->getTokens();
63
$decName = $phpcsFile->findNext(T_STRING, $stackPtr);
64
$fullPath = basename($phpcsFile->getFilename());
65
$fileName = substr($fullPath, 0, strrpos($fullPath, '.'));
67
if ($tokens[$decName]['content'] !== $fileName) {
68
$error = ucfirst($tokens[$stackPtr]['content']);
69
$error .= ' name doesn\'t match filename. Expected ';
70
$error .= '"'.$tokens[$stackPtr]['content'].' ';
71
$error .= $fileName.'".';
72
$phpcsFile->addError($error, $stackPtr);