1<?php 2/** 3 * Generic_Sniffs_Files_LowercasedFilenameSniff. 4 * 5 * PHP version 5 6 * 7 * @category PHP 8 * @package PHP_CodeSniffer 9 * @author Andy Grunwald <andygrunwald@gmail.com> 10 * @copyright 2010-2014 Andy Grunwald 11 * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence 12 * @link http://pear.php.net/package/PHP_CodeSniffer 13 */ 14 15/** 16 * Checks that all file names are lowercased. 17 * 18 * @category PHP 19 * @package PHP_CodeSniffer 20 * @author Andy Grunwald <andygrunwald@gmail.com> 21 * @copyright 2010-2014 Andy Grunwald 22 * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence 23 * @version Release: @package_version@ 24 * @link http://pear.php.net/package/PHP_CodeSniffer 25 */ 26class Generic_Sniffs_Files_LowercasedFilenameSniff implements PHP_CodeSniffer_Sniff 27{ 28 29 30 /** 31 * Returns an array of tokens this test wants to listen for. 32 * 33 * @return array 34 */ 35 public function register() 36 { 37 return array(T_OPEN_TAG); 38 39 }//end register() 40 41 42 /** 43 * Processes this sniff, when one of its tokens is encountered. 44 * 45 * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. 46 * @param int $stackPtr The position of the current token in 47 * the stack passed in $tokens. 48 * 49 * @return int 50 */ 51 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) 52 { 53 $filename = $phpcsFile->getFilename(); 54 if ($filename === 'STDIN') { 55 return; 56 } 57 58 $filename = basename($filename); 59 $lowercaseFilename = strtolower($filename); 60 if ($filename !== $lowercaseFilename) { 61 $data = array( 62 $filename, 63 $lowercaseFilename, 64 ); 65 $error = 'Filename "%s" doesn\'t match the expected filename "%s"'; 66 $phpcsFile->addError($error, $stackPtr, 'NotFound', $data); 67 $phpcsFile->recordMetric($stackPtr, 'Lowercase filename', 'no'); 68 } else { 69 $phpcsFile->recordMetric($stackPtr, 'Lowercase filename', 'yes'); 70 } 71 72 // Ignore the rest of the file. 73 return ($phpcsFile->numTokens + 1); 74 75 }//end process() 76 77 78}//end class 79