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_Files_FileExtensionSniff.
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: FileExtensionSniff.php 240175 2007-07-23 01:47:54Z squiz $
14
 * @link      http://pear.php.net/package/PHP_CodeSniffer
15
 */
16
 
17
/**
18
 * Squiz_Sniffs_Files_FileExtensionSniff.
19
 *
20
 * Tests that the stars in a doc comment align correctly.
21
 *
22
 * @category  PHP
23
 * @package   PHP_CodeSniffer
24
 * @author    Greg Sherwood <gsherwood@squiz.net>
25
 * @author    Marc McIntyre <mmcintyre@squiz.net>
26
 * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
27
 * @license   http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
28
 * @version   Release: 1.2.1
29
 * @link      http://pear.php.net/package/PHP_CodeSniffer
30
 */
31
class Squiz_Sniffs_Files_FileExtensionSniff implements PHP_CodeSniffer_Sniff
32
{
33
 
34
 
35
    /**
36
     * Returns an array of tokens this test wants to listen for.
37
     *
38
     * @return array
39
     */
40
    public function register()
41
    {
42
        return array(
43
                T_OPEN_TAG,
44
               );
45
 
46
    }//end register()
47
 
48
 
49
    /**
50
     * Processes this test, when one of its tokens is encountered.
51
     *
52
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
53
     * @param int                  $stackPtr  The position of the current token in the
54
     *                                        stack passed in $tokens.
55
     *
56
     * @return void
57
     */
58
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
59
    {
60
        $tokens = $phpcsFile->getTokens();
61
 
62
        // Make sure this is the first PHP open tag so we don't process
63
        // the same file twice.
64
        $prevOpenTag = $phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1));
65
        if ($prevOpenTag !== false) {
66
            return;
67
        }
68
 
69
        $fileName  = $phpcsFile->getFileName();
70
        $extension = substr($fileName, strrpos($fileName, '.'));
71
        $nextClass = $phpcsFile->findNext(array(T_CLASS, T_INTERFACE), $stackPtr);
72
 
73
        if ($extension === '.php') {
74
            if ($nextClass !== false) {
75
                $error = ucfirst($tokens[$nextClass]['content']).' found in ".php" file; use ".inc" extension instead';
76
                $phpcsFile->addError($error, $stackPtr);
77
            }
78
        } else if ($extension === '.inc') {
79
            if ($nextClass === false) {
80
                $error = 'No interface or class found in ".inc" file; use ".php" extension instead';
81
                $phpcsFile->addError($error, $stackPtr);
82
            }
83
        }
84
 
85
    }//end process()
86
 
87
 
88
}//end class
89
 
90
 
91
?>