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_CSS_OpacitySniff.
4
 *
5
 * PHP version 5
6
 *
7
 * @category  PHP
8
 * @package   PHP_CodeSniffer
9
 * @author    Greg Sherwood <gsherwood@squiz.net>
10
 * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
11
 * @license   http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
12
 * @version   CVS: $Id: OpacitySniff.php 288186 2009-09-09 05:46:31Z squiz $
13
 * @link      http://pear.php.net/package/PHP_CodeSniffer
14
 */
15
 
16
/**
17
 * Squiz_Sniffs_CSS_OpacitySniff.
18
 *
19
 * Ensure that opacity values start with a 0 if it is not a whole number.
20
 *
21
 * @category  PHP
22
 * @package   PHP_CodeSniffer
23
 * @author    Greg Sherwood <gsherwood@squiz.net>
24
 * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
25
 * @license   http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
26
 * @version   Release: 1.2.1
27
 * @link      http://pear.php.net/package/PHP_CodeSniffer
28
 */
29
class Squiz_Sniffs_CSS_OpacitySniff implements PHP_CodeSniffer_Sniff
30
{
31
 
32
    /**
33
     * A list of tokenizers this sniff supports.
34
     *
35
     * @var array
36
     */
37
    public $supportedTokenizers = array('CSS');
38
 
39
 
40
    /**
41
     * Returns the token types that this sniff is interested in.
42
     *
43
     * @return array(int)
44
     */
45
    public function register()
46
    {
47
        return array(T_STYLE);
48
 
49
    }//end register()
50
 
51
 
52
    /**
53
     * Processes the tokens that this sniff is interested in.
54
     *
55
     * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
56
     * @param int                  $stackPtr  The position in the stack where
57
     *                                        the token was found.
58
     *
59
     * @return void
60
     */
61
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
62
    {
63
        $tokens = $phpcsFile->getTokens();
64
 
65
        if ($tokens[$stackPtr]['content'] !== 'opacity') {
66
            return;
67
        }
68
 
69
        $next    = $phpcsFile->findNext(array(T_COLON, T_WHITESPACE), ($stackPtr + 1), null, true);
70
        $numbers = array(
71
                    T_DNUMBER,
72
                    T_LNUMBER,
73
                   );
74
 
75
        if ($next === false || in_array($tokens[$next]['code'], $numbers) === false) {
76
            return;
77
        }
78
 
79
        $value = $tokens[$next]['content'];
80
        if ($tokens[$next]['code'] === T_LNUMBER) {
81
            if ($value !== '0' && $value !== '1') {
82
                $error = 'Opacity values must be between 0 and 1';
83
                $phpcsFile->addError($error, $next);
84
            }
85
        } else {
86
            if (strlen($value) > 3) {
87
                $error = 'Opacity values must have a single value after the decimal point';
88
                $phpcsFile->addError($error, $next);
89
            } else if ($value === '0.0' || $value === '1.0') {
90
                $error = 'Opacity value does not require decimal point; use '.$value{0}.' instead';
91
                $phpcsFile->addError($error, $next);
92
            } else if ($value{0} === '.') {
93
                $error = 'Opacity values must not start with a decimal point; use 0'.$value.' instead';
94
                $phpcsFile->addError($error, $next);
95
            } else if ($value{0} !== '0') {
96
                $error = 'Opacity values must be between 0 and 1';
97
                $phpcsFile->addError($error, $next);
98
            }
99
        }//end if
100
 
101
    }//end process()
102
 
103
 
104
}//end class
105
 
106
?>