From 7fb3676957fa8e489a49dc446c356fef888b4d60 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 27 Oct 2013 17:14:20 +0100 Subject: [task/code-sniffer] Move code sniffer below build folder. PHPBB3-11980 --- .../phpbb/Sniffs/Commenting/FileCommentSniff.php | 210 +++++++++++++++++++++ .../phpbb/Tests/Commenting/FileCommentUnitTest.inc | 19 ++ .../phpbb/Tests/Commenting/FileCommentUnitTest.php | 51 +++++ build/code_sniffer/phpbb/build.xml | 23 +++ build/code_sniffer/phpbb/phpbbCodingStandard.php | 43 +++++ .../phpbb/Sniffs/Commenting/FileCommentSniff.php | 210 --------------------- .../phpbb/Tests/Commenting/FileCommentUnitTest.inc | 19 -- .../phpbb/Tests/Commenting/FileCommentUnitTest.php | 51 ----- code_sniffer/phpbb/build.xml | 23 --- code_sniffer/phpbb/phpbbCodingStandard.php | 43 ----- 10 files changed, 346 insertions(+), 346 deletions(-) create mode 100644 build/code_sniffer/phpbb/Sniffs/Commenting/FileCommentSniff.php create mode 100644 build/code_sniffer/phpbb/Tests/Commenting/FileCommentUnitTest.inc create mode 100644 build/code_sniffer/phpbb/Tests/Commenting/FileCommentUnitTest.php create mode 100644 build/code_sniffer/phpbb/build.xml create mode 100644 build/code_sniffer/phpbb/phpbbCodingStandard.php delete mode 100644 code_sniffer/phpbb/Sniffs/Commenting/FileCommentSniff.php delete mode 100644 code_sniffer/phpbb/Tests/Commenting/FileCommentUnitTest.inc delete mode 100644 code_sniffer/phpbb/Tests/Commenting/FileCommentUnitTest.php delete mode 100644 code_sniffer/phpbb/build.xml delete mode 100644 code_sniffer/phpbb/phpbbCodingStandard.php diff --git a/build/code_sniffer/phpbb/Sniffs/Commenting/FileCommentSniff.php b/build/code_sniffer/phpbb/Sniffs/Commenting/FileCommentSniff.php new file mode 100644 index 0000000000..68e9e6bb86 --- /dev/null +++ b/build/code_sniffer/phpbb/Sniffs/Commenting/FileCommentSniff.php @@ -0,0 +1,210 @@ + +*/ +class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff +{ + /** + * Returns an array of tokens this test wants to listen for. + * + * @return array + */ + public function register() + { + return array(T_OPEN_TAG); + } + + /** + * Processes this test, when one of its tokens is encountered. + * + * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. + * + * @return null + */ + public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + { + // We are only interested in the first file comment. + if ($stackPtr !== 0) + { + if ($phpcsFile->findPrevious(T_OPEN_TAG, $stackPtr - 1) !== false) + { + return; + } + } + + // Fetch next non whitespace token + $tokens = $phpcsFile->getTokens(); + $start = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, null, true); + + // Skip empty files + if ($tokens[$start]['code'] === T_CLOSE_TAG) + { + return; + } + // Mark as error if this is not a doc comment + else if ($start === false || $tokens[$start]['code'] !== T_DOC_COMMENT) + { + $phpcsFile->addError('Missing required file doc comment.', $stackPtr); + return; + } + + // Find comment end token + $end = $phpcsFile->findNext(T_DOC_COMMENT, $start + 1, null, true) - 1; + + // If there is no end, skip processing here + if ($end === false) + { + return; + } + + // List of found comment tags + $tags = array(); + + // check comment lines without the first(/**) an last(*/) line + for ($i = $start + 1, $c = ($end - $start); $i <= $c; ++$i) + { + $line = $tokens[$i]['content']; + + // Check that each line starts with a '*' + if (substr($line, 0, 1) !== '*') + { + $message = 'The file doc comment should not be idented.'; + $phpcsFile->addWarning($message, $i); + } + else if (preg_match('/^\*\s+@([\w]+)\s+(.*)$/', $line, $match) !== 0) + { + $tags[$match[1]] = array($match[2], $i); + } + } + + // Check that the first and last line is empty + if (trim($tokens[$start + 1]['content']) !== '*') + { + $message = 'The first file comment line should be empty.'; + $phpcsFile->addWarning($message, ($start + 1)); + } + if (trim($tokens[$end - $start]['content']) !== '*') + { + $message = 'The last file comment line should be empty.'; + $phpcsFile->addWarning($message, ($end - $start)); + } + + $this->processPackage($phpcsFile, $start, $tags); + $this->processVersion($phpcsFile, $start, $tags); + $this->processCopyright($phpcsFile, $start, $tags); + $this->processLicense($phpcsFile, $start, $tags); + + //print_r($tags); + } + + /** + * Checks that the tags array contains a valid package tag + * + * @param PHP_CodeSniffer_File $phpcsFile The context source file instance. + * @param integer The stack pointer for the first comment token. + * @param array(string=>array) $tags The found file doc comment tags. + * + * @return null + */ + protected function processPackage(PHP_CodeSniffer_File $phpcsFile, $ptr, $tags) + { + if (!isset($tags['package'])) + { + $message = 'Missing require @package tag in file doc comment.'; + $phpcsFile->addError($message, $ptr); + } + else if (preg_match('/^([\w]+)$/', $tags['package'][0]) === 0) + { + $message = 'Invalid content found for @package tag.'; + $phpcsFile->addWarning($message, $tags['package'][1]); + } + } + + /** + * Checks that the tags array contains a valid version tag + * + * @param PHP_CodeSniffer_File $phpcsFile The context source file instance. + * @param integer The stack pointer for the first comment token. + * @param array(string=>array) $tags The found file doc comment tags. + * + * @return null + */ + protected function processVersion(PHP_CodeSniffer_File $phpcsFile, $ptr, $tags) + { + if (!isset($tags['version'])) + { + $message = 'Missing require @version tag in file doc comment.'; + $phpcsFile->addError($message, $ptr); + } + else if (preg_match('/^\$Id:[^\$]+\$$/', $tags['version'][0]) === 0) + { + $message = 'Invalid content found for @version tag, use "$Id: $".'; + $phpcsFile->addError($message, $tags['version'][1]); + } + } + + /** + * Checks that the tags array contains a valid copyright tag + * + * @param PHP_CodeSniffer_File $phpcsFile The context source file instance. + * @param integer The stack pointer for the first comment token. + * @param array(string=>array) $tags The found file doc comment tags. + * + * @return null + */ + protected function processCopyright(PHP_CodeSniffer_File $phpcsFile, $ptr, $tags) + { + if (!isset($tags['copyright'])) + { + $message = 'Missing require @copyright tag in file doc comment.'; + $phpcsFile->addError($message, $ptr); + } + else if (preg_match('/^\(c\) 2[0-9]{3} phpBB Group\s*$/', $tags['copyright'][0]) === 0) + { + $message = 'Invalid content found for @copyright tag, use "(c) phpBB Group".'; + $phpcsFile->addError($message, $tags['copyright'][1]); + } + } + + /** + * Checks that the tags array contains a valid license tag + * + * @param PHP_CodeSniffer_File $phpcsFile The context source file instance. + * @param integer The stack pointer for the first comment token. + * @param array(string=>array) $tags The found file doc comment tags. + * + * @return null + */ + protected function processLicense(PHP_CodeSniffer_File $phpcsFile, $ptr, $tags) + { + $license = 'http://opensource.org/licenses/gpl-license.php GNU Public License'; + + if (!isset($tags['license'])) + { + $message = 'Missing require @license tag in file doc comment.'; + $phpcsFile->addError($message, $ptr); + } + else if (trim($tags['license'][0]) !== $license) + { + $message = 'Invalid content found for @license tag, use ' + . '"' . $license . '".'; + $phpcsFile->addError($message, $tags['license'][1]); + } + } +} diff --git a/build/code_sniffer/phpbb/Tests/Commenting/FileCommentUnitTest.inc b/build/code_sniffer/phpbb/Tests/Commenting/FileCommentUnitTest.inc new file mode 100644 index 0000000000..0ace1c1bda --- /dev/null +++ b/build/code_sniffer/phpbb/Tests/Commenting/FileCommentUnitTest.inc @@ -0,0 +1,19 @@ + + +*/ +class phpbb_Tests_Commenting_FileCommentUnitTest extends AbstractSniffUnitTest +{ + + /** + * Returns the lines where errors should occur. + * + * The key of the array should represent the line number and the value + * should represent the number of errors that should occur on that line. + * + * @return array(int => int) + */ + public function getErrorList() + { + return array( + 7 => 1 // BSD License error :) + ); + }//end getErrorList() + + + /** + * Returns the lines where warnings should occur. + * + * The key of the array should represent the line number and the value + * should represent the number of warnings that should occur on that line. + * + * @return array(int => int) + */ + public function getWarningList() + { + return array( + 4 => 1, + 8 => 1 + ); + }//end getWarningList() +} diff --git a/build/code_sniffer/phpbb/build.xml b/build/code_sniffer/phpbb/build.xml new file mode 100644 index 0000000000..b6d3bf6451 --- /dev/null +++ b/build/code_sniffer/phpbb/build.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/build/code_sniffer/phpbb/phpbbCodingStandard.php b/build/code_sniffer/phpbb/phpbbCodingStandard.php new file mode 100644 index 0000000000..adbba9d915 --- /dev/null +++ b/build/code_sniffer/phpbb/phpbbCodingStandard.php @@ -0,0 +1,43 @@ + include all sniffs in this standard + * PEAR/Sniffs/Files => include all sniffs in this dir + * PEAR/Sniffs/Files/LineLengthSniff => include this single sniff + * + * @return array + */ + public function getIncludedSniffs() + { + return array(); + } +} diff --git a/code_sniffer/phpbb/Sniffs/Commenting/FileCommentSniff.php b/code_sniffer/phpbb/Sniffs/Commenting/FileCommentSniff.php deleted file mode 100644 index 68e9e6bb86..0000000000 --- a/code_sniffer/phpbb/Sniffs/Commenting/FileCommentSniff.php +++ /dev/null @@ -1,210 +0,0 @@ - -*/ -class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff -{ - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_OPEN_TAG); - } - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return null - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - // We are only interested in the first file comment. - if ($stackPtr !== 0) - { - if ($phpcsFile->findPrevious(T_OPEN_TAG, $stackPtr - 1) !== false) - { - return; - } - } - - // Fetch next non whitespace token - $tokens = $phpcsFile->getTokens(); - $start = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, null, true); - - // Skip empty files - if ($tokens[$start]['code'] === T_CLOSE_TAG) - { - return; - } - // Mark as error if this is not a doc comment - else if ($start === false || $tokens[$start]['code'] !== T_DOC_COMMENT) - { - $phpcsFile->addError('Missing required file doc comment.', $stackPtr); - return; - } - - // Find comment end token - $end = $phpcsFile->findNext(T_DOC_COMMENT, $start + 1, null, true) - 1; - - // If there is no end, skip processing here - if ($end === false) - { - return; - } - - // List of found comment tags - $tags = array(); - - // check comment lines without the first(/**) an last(*/) line - for ($i = $start + 1, $c = ($end - $start); $i <= $c; ++$i) - { - $line = $tokens[$i]['content']; - - // Check that each line starts with a '*' - if (substr($line, 0, 1) !== '*') - { - $message = 'The file doc comment should not be idented.'; - $phpcsFile->addWarning($message, $i); - } - else if (preg_match('/^\*\s+@([\w]+)\s+(.*)$/', $line, $match) !== 0) - { - $tags[$match[1]] = array($match[2], $i); - } - } - - // Check that the first and last line is empty - if (trim($tokens[$start + 1]['content']) !== '*') - { - $message = 'The first file comment line should be empty.'; - $phpcsFile->addWarning($message, ($start + 1)); - } - if (trim($tokens[$end - $start]['content']) !== '*') - { - $message = 'The last file comment line should be empty.'; - $phpcsFile->addWarning($message, ($end - $start)); - } - - $this->processPackage($phpcsFile, $start, $tags); - $this->processVersion($phpcsFile, $start, $tags); - $this->processCopyright($phpcsFile, $start, $tags); - $this->processLicense($phpcsFile, $start, $tags); - - //print_r($tags); - } - - /** - * Checks that the tags array contains a valid package tag - * - * @param PHP_CodeSniffer_File $phpcsFile The context source file instance. - * @param integer The stack pointer for the first comment token. - * @param array(string=>array) $tags The found file doc comment tags. - * - * @return null - */ - protected function processPackage(PHP_CodeSniffer_File $phpcsFile, $ptr, $tags) - { - if (!isset($tags['package'])) - { - $message = 'Missing require @package tag in file doc comment.'; - $phpcsFile->addError($message, $ptr); - } - else if (preg_match('/^([\w]+)$/', $tags['package'][0]) === 0) - { - $message = 'Invalid content found for @package tag.'; - $phpcsFile->addWarning($message, $tags['package'][1]); - } - } - - /** - * Checks that the tags array contains a valid version tag - * - * @param PHP_CodeSniffer_File $phpcsFile The context source file instance. - * @param integer The stack pointer for the first comment token. - * @param array(string=>array) $tags The found file doc comment tags. - * - * @return null - */ - protected function processVersion(PHP_CodeSniffer_File $phpcsFile, $ptr, $tags) - { - if (!isset($tags['version'])) - { - $message = 'Missing require @version tag in file doc comment.'; - $phpcsFile->addError($message, $ptr); - } - else if (preg_match('/^\$Id:[^\$]+\$$/', $tags['version'][0]) === 0) - { - $message = 'Invalid content found for @version tag, use "$Id: $".'; - $phpcsFile->addError($message, $tags['version'][1]); - } - } - - /** - * Checks that the tags array contains a valid copyright tag - * - * @param PHP_CodeSniffer_File $phpcsFile The context source file instance. - * @param integer The stack pointer for the first comment token. - * @param array(string=>array) $tags The found file doc comment tags. - * - * @return null - */ - protected function processCopyright(PHP_CodeSniffer_File $phpcsFile, $ptr, $tags) - { - if (!isset($tags['copyright'])) - { - $message = 'Missing require @copyright tag in file doc comment.'; - $phpcsFile->addError($message, $ptr); - } - else if (preg_match('/^\(c\) 2[0-9]{3} phpBB Group\s*$/', $tags['copyright'][0]) === 0) - { - $message = 'Invalid content found for @copyright tag, use "(c) phpBB Group".'; - $phpcsFile->addError($message, $tags['copyright'][1]); - } - } - - /** - * Checks that the tags array contains a valid license tag - * - * @param PHP_CodeSniffer_File $phpcsFile The context source file instance. - * @param integer The stack pointer for the first comment token. - * @param array(string=>array) $tags The found file doc comment tags. - * - * @return null - */ - protected function processLicense(PHP_CodeSniffer_File $phpcsFile, $ptr, $tags) - { - $license = 'http://opensource.org/licenses/gpl-license.php GNU Public License'; - - if (!isset($tags['license'])) - { - $message = 'Missing require @license tag in file doc comment.'; - $phpcsFile->addError($message, $ptr); - } - else if (trim($tags['license'][0]) !== $license) - { - $message = 'Invalid content found for @license tag, use ' - . '"' . $license . '".'; - $phpcsFile->addError($message, $tags['license'][1]); - } - } -} diff --git a/code_sniffer/phpbb/Tests/Commenting/FileCommentUnitTest.inc b/code_sniffer/phpbb/Tests/Commenting/FileCommentUnitTest.inc deleted file mode 100644 index 0ace1c1bda..0000000000 --- a/code_sniffer/phpbb/Tests/Commenting/FileCommentUnitTest.inc +++ /dev/null @@ -1,19 +0,0 @@ - - -*/ -class phpbb_Tests_Commenting_FileCommentUnitTest extends AbstractSniffUnitTest -{ - - /** - * Returns the lines where errors should occur. - * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) - */ - public function getErrorList() - { - return array( - 7 => 1 // BSD License error :) - ); - }//end getErrorList() - - - /** - * Returns the lines where warnings should occur. - * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) - */ - public function getWarningList() - { - return array( - 4 => 1, - 8 => 1 - ); - }//end getWarningList() -} diff --git a/code_sniffer/phpbb/build.xml b/code_sniffer/phpbb/build.xml deleted file mode 100644 index b6d3bf6451..0000000000 --- a/code_sniffer/phpbb/build.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/code_sniffer/phpbb/phpbbCodingStandard.php b/code_sniffer/phpbb/phpbbCodingStandard.php deleted file mode 100644 index adbba9d915..0000000000 --- a/code_sniffer/phpbb/phpbbCodingStandard.php +++ /dev/null @@ -1,43 +0,0 @@ - include all sniffs in this standard - * PEAR/Sniffs/Files => include all sniffs in this dir - * PEAR/Sniffs/Files/LineLengthSniff => include this single sniff - * - * @return array - */ - public function getIncludedSniffs() - { - return array(); - } -} -- cgit v1.2.1