PHP_CodeSniffer
[ class tree: PHP_CodeSniffer ] [ index: PHP_CodeSniffer ] [ all elements ]

Source for file LowercaseStyleDefinitionSniff.php

Documentation is available at LowercaseStyleDefinitionSniff.php

  1. <?php
  2. /**
  3.  * Ensure that all style definitions are in lowercase.
  4.  *
  5.  * @author    Greg Sherwood <gsherwood@squiz.net>
  6.  * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
  7.  * @license   https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
  8.  */
  9.  
  10. namespace PHP_CodeSniffer\Standards\Squiz\Sniffs\CSS;
  11.  
  12. use PHP_CodeSniffer\Sniffs\Sniff;
  13. use PHP_CodeSniffer\Files\File;
  14.  
  15. class LowercaseStyleDefinitionSniff implements Sniff
  16. {
  17.  
  18.     /**
  19.      * A list of tokenizers this sniff supports.
  20.      *
  21.      * @var array 
  22.      */
  23.     public $supportedTokenizers = array('CSS');
  24.  
  25.  
  26.     /**
  27.      * Returns the token types that this sniff is interested in.
  28.      *
  29.      * @return int[] 
  30.      */
  31.     public function register()
  32.     {
  33.         return array(T_OPEN_CURLY_BRACKET);
  34.  
  35.     }//end register()
  36.  
  37.  
  38.     /**
  39.      * Processes the tokens that this sniff is interested in.
  40.      *
  41.      * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where the token was found.
  42.      * @param int                         $stackPtr  The position in the stack where
  43.      *                                                the token was found.
  44.      *
  45.      * @return void 
  46.      */
  47.     public function process(File $phpcsFile$stackPtr)
  48.     {
  49.         $tokens  $phpcsFile->getTokens();
  50.         $start   ($stackPtr + 1);
  51.         $end     ($tokens[$stackPtr]['bracket_closer'- 1);
  52.         $inStyle = null;
  53.  
  54.         for ($i $start$i <= $end$i++{
  55.             // Skip nested definitions as they are checked individually.
  56.             if ($tokens[$i]['code'=== T_OPEN_CURLY_BRACKET{
  57.                 $i $tokens[$i]['bracket_closer'];
  58.                 continue;
  59.             }
  60.  
  61.             if ($tokens[$i]['code'=== T_STYLE{
  62.                 $inStyle $tokens[$i]['content'];
  63.             }
  64.  
  65.             if ($tokens[$i]['code'=== T_SEMICOLON{
  66.                 $inStyle = null;
  67.             }
  68.  
  69.             if ($inStyle === 'progid'{
  70.                 // Special case for IE filters.
  71.                 continue;
  72.             }
  73.  
  74.             if ($tokens[$i]['code'=== T_STYLE
  75.                 || ($inStyle !== null
  76.                 && $tokens[$i]['code'=== T_STRING)
  77.             {
  78.                 $expected strtolower($tokens[$i]['content']);
  79.                 if ($expected !== $tokens[$i]['content']{
  80.                     $error 'Style definitions must be lowercase; expected %s but found %s';
  81.                     $data  = array(
  82.                               $expected,
  83.                               $tokens[$i]['content'],
  84.                              );
  85.  
  86.                     $fix $phpcsFile->addFixableError($error$i'FoundUpper'$data);
  87.                     if ($fix === true{
  88.                         $phpcsFile->fixer->replaceToken($i$expected);
  89.                     }
  90.                 }
  91.             }
  92.         }//end for
  93.  
  94.     }//end process()
  95.  
  96.  
  97. }//end class

Documentation generated on Mon, 11 Mar 2019 15:27:37 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.