Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * Squiz_Sniffs_Classes_ClassFileNameSniff.
4
 *
5
 * PHP version 5
6
 *
7
 * @category  PHP
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 240175 2007-07-23 01:47:54Z squiz $
14
 * @link      http://pear.php.net/package/PHP_CodeSniffer
15
 */
16
 
17
/**
18
 * Squiz_Sniffs_Classes_ClassFileNameSniff.
19
 *
20
 * Tests that the file name and the name of the class contained within the file
21
 * match.
22
 *
23
 * @category  PHP
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.2.1
30
 * @link      http://pear.php.net/package/PHP_CodeSniffer
31
 */
32
class Squiz_Sniffs_Classes_ClassFileNameSniff implements PHP_CodeSniffer_Sniff
33
{
34
 
35
 
36
    /**
37
     * Returns an array of tokens this test wants to listen for.
38
     *
39
     * @return array
40
     */
41
    public function register()
42
    {
43
        return array(
44
                T_CLASS,
45
                T_INTERFACE,
46
               );
47
 
48
    }//end register()
49
 
50
 
51
    /**
52
     * Processes this test, when one of its tokens is encountered.
53
     *
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.
57
     *
58
     * @return void
59
     */
60
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
61
    {
62
        $tokens   = $phpcsFile->getTokens();
63
        $decName  = $phpcsFile->findNext(T_STRING, $stackPtr);
64
        $fullPath = basename($phpcsFile->getFilename());
65
        $fileName = substr($fullPath, 0, strrpos($fullPath, '.'));
66
 
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);
73
        }
74
 
75
    }//end process()
76
 
77
 
78
}//end class
79
 
80
?>