diff options
author | Tristan Darricau <tristan.darricau@sensiolabs.com> | 2015-04-28 01:01:09 +0200 |
---|---|---|
committer | Nicofuma <github@nicofuma.fr> | 2015-05-19 22:19:18 +0200 |
commit | a462f14aa367e9b8f94c4d2da35458353bad8c0f (patch) | |
tree | 42f63b1695580b5bb50e664b5af70838e88944f1 /build/code_sniffer/phpbb | |
parent | 73a0988f59058bfce9b42cb416acf68fc2544f63 (diff) | |
download | forums-a462f14aa367e9b8f94c4d2da35458353bad8c0f.tar forums-a462f14aa367e9b8f94c4d2da35458353bad8c0f.tar.gz forums-a462f14aa367e9b8f94c4d2da35458353bad8c0f.tar.bz2 forums-a462f14aa367e9b8f94c4d2da35458353bad8c0f.tar.xz forums-a462f14aa367e9b8f94c4d2da35458353bad8c0f.zip |
[ticket/13790] Update phpcs
PHPBB3-13790
Diffstat (limited to 'build/code_sniffer/phpbb')
-rw-r--r-- | build/code_sniffer/phpbb/Sniffs/Commenting/FileCommentSniff.php | 94 | ||||
-rw-r--r-- | build/code_sniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php | 51 |
2 files changed, 72 insertions, 73 deletions
diff --git a/build/code_sniffer/phpbb/Sniffs/Commenting/FileCommentSniff.php b/build/code_sniffer/phpbb/Sniffs/Commenting/FileCommentSniff.php index 8337cf02ee..8c0ec853ff 100644 --- a/build/code_sniffer/phpbb/Sniffs/Commenting/FileCommentSniff.php +++ b/build/code_sniffer/phpbb/Sniffs/Commenting/FileCommentSniff.php @@ -60,14 +60,14 @@ class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff return; } // Mark as error if this is not a doc comment - else if ($start === false || $tokens[$start]['code'] !== T_DOC_COMMENT) + else if ($start === false || $tokens[$start]['code'] !== T_DOC_COMMENT_OPEN_TAG) { $phpcsFile->addError('Missing required file doc comment.', $stackPtr); return; } // Find comment end token - $end = $phpcsFile->findNext(T_DOC_COMMENT, $start + 1, null, true) - 1; + $end = $tokens[$start]['comment_closer']; // If there is no end, skip processing here if ($end === false) @@ -75,38 +75,30 @@ class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff return; } - // List of found comment tags - $tags = array(); - // check comment lines without the first(/**) an last(*/) line - for ($i = $start + 1, $c = $end - 1; $i <= $c; ++$i) + for ($token = $start + 1, $c = $end - 2; $token <= $c; ++$token) { - $line = $tokens[$i]['content']; - // Check that each line starts with a '*' - if (substr($line, 0, 1) !== '*' && substr($line, 0, 2) !== ' *') + if ($tokens[$token]['column'] === 1 && (($tokens[$token]['content'] !== '*' && $tokens[$token]['content'] !== ' ') || ($tokens[$token]['content'] === ' ' && $tokens[$token + 1]['content'] !== '*'))) { $message = 'The file doc comment should not be indented.'; - $phpcsFile->addWarning($message, $i); - } - else if (preg_match('/^[ ]?\*\s+@([\w]+)\s+(.*)$/', $line, $match) !== 0) - { - if (!isset($tags[$match[1]])) - { - $tags[$match[1]] = array(); - } - - $tags[$match[1]][] = array($match[2], $i); + $phpcsFile->addWarning($message, $token); } } // Check that the first and last line is empty - if (trim($tokens[$start + 1]['content']) !== '*') + // /**T_WHITESPACE + // (T_WHITESPACE)*T_WHITESPACE + // (T_WHITESPACE)* ... + // (T_WHITESPACE)*T_WHITESPACE + // T_WHITESPACE*/ + if (!(($tokens[$start + 2]['content'] !== '*' && $tokens[$start + 4]['content'] !== '*') || ($tokens[$start + 3]['content'] !== '*' && $tokens[$start + 6]['content'] !== '*'))) { $message = 'The first file comment line should be empty.'; $phpcsFile->addWarning($message, ($start + 1)); } - if (trim($tokens[$end - 1]['content']) !== '*') + + if ($tokens[$end - 3]['content'] !== '*' && $tokens[$end - 6]['content'] !== '*') { $message = 'The last file comment line should be empty.'; $phpcsFile->addWarning($message, $end - 1); @@ -114,8 +106,8 @@ class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff //$this->processPackage($phpcsFile, $start, $tags); //$this->processVersion($phpcsFile, $start, $tags); - $this->processCopyright($phpcsFile, $start, $tags); - $this->processLicense($phpcsFile, $start, $tags); + $this->processCopyright($phpcsFile, $start, $tokens[$start]['comment_tags']); + $this->processLicense($phpcsFile, $start, $tokens[$start]['comment_tags']); } /** @@ -176,17 +168,24 @@ class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff protected function processCopyright(PHP_CodeSniffer_File $phpcsFile, $ptr, $tags) { $copyright = '(c) phpBB Limited <https://www.phpbb.com>'; + $tokens = $phpcsFile->getTokens(); - if (!isset($tags['copyright'])) + foreach ($tags as $tag) { - $message = 'Missing require @copyright tag in file doc comment.'; - $phpcsFile->addError($message, $ptr); - } - else if ($tags['copyright'][0][0] !== $copyright) - { - $message = 'Invalid content found for the first @copyright tag, use "' . $copyright . '".'; - $phpcsFile->addError($message, $tags['copyright'][0][1]); + if ($tokens[$tag]['content'] === '@copyright') + { + if ($tokens[$tag + 2]['content'] !== $copyright) + { + $message = 'Invalid content found for the first @copyright tag, use "' . $copyright . '".'; + $phpcsFile->addError($message, $tags['copyright'][0][1]); + } + + return; + } } + + $message = 'Missing require @copyright tag in file doc comment.'; + $phpcsFile->addError($message, $ptr); } /** @@ -201,22 +200,33 @@ class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff protected function processLicense(PHP_CodeSniffer_File $phpcsFile, $ptr, $tags) { $license = 'GNU General Public License, version 2 (GPL-2.0)'; + $tokens = $phpcsFile->getTokens(); - if (!isset($tags['license'])) + $found = false; + foreach ($tags as $tag) { - $message = 'Missing require @license tag in file doc comment.'; - $phpcsFile->addError($message, $ptr); + if ($tokens[$tag]['content'] === '@license') + { + if ($found) + { + $message = 'It must be only one @license tag in file doc comment.'; + $phpcsFile->addError($message, $ptr); + } + + $found = true; + + if ($tokens[$tag + 2]['content'] !== $license) + { + $message = 'Invalid content found for @license tag, use "' . $license . '".'; + $phpcsFile->addError($message, $tags['license'][0][1]); + } + } } - else if (sizeof($tags['license']) !== 1) + + if (!$found) { - $message = 'It must be only one @license tag in file doc comment.'; + $message = 'Missing require @license tag in file doc comment.'; $phpcsFile->addError($message, $ptr); } - else if (trim($tags['license'][0][0]) !== $license) - { - $message = 'Invalid content found for @license tag, use ' - . '"' . $license . '".'; - $phpcsFile->addError($message, $tags['license'][0][1]); - } } } diff --git a/build/code_sniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php b/build/code_sniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php index 18cb8ba82e..30ca1c3c24 100644 --- a/build/code_sniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php +++ b/build/code_sniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php @@ -138,6 +138,7 @@ class phpbb_Sniffs_Namespaces_UnusedUseSniff implements PHP_CodeSniffer_Sniff // Check docblocks $find = array( T_COMMENT, + T_DOC_COMMENT_CLOSE_TAG, T_DOC_COMMENT, T_CLASS, T_FUNCTION, @@ -147,43 +148,31 @@ class phpbb_Sniffs_Namespaces_UnusedUseSniff implements PHP_CodeSniffer_Sniff $comment_end = $phpcsFile->findPrevious($find, ($function_declaration - 1)); if ($comment_end !== false) { - if (!$tokens[$comment_end]['code'] !== T_DOC_COMMENT) + if ($tokens[$comment_end]['code'] === T_DOC_COMMENT_CLOSE_TAG) { - $comment_start = ($phpcsFile->findPrevious(T_DOC_COMMENT, ($comment_end - 1), null, true) + 1); - $comment = $phpcsFile->getTokensAsString($comment_start, ($comment_end - $comment_start + 1)); - - try - { - $comment_parser = new PHP_CodeSniffer_CommentParser_FunctionCommentParser($comment, $phpcsFile); - $comment_parser->parse(); - - // Check @param - foreach ($comment_parser->getParams() as $param) { - $type = $param->getType(); - $types = explode('|', str_replace('[]', '', $type)); - foreach ($types as $type) - { - $ok = $this->check($phpcsFile, $type, $class_name_full, $class_name_short, $param->getLine() + $comment_start) ? true : $ok; - } + $comment_start = $tokens[$comment_end]['comment_opener']; + foreach ($tokens[$comment_start]['comment_tags'] as $tag) { + if ($tokens[$tag]['content'] !== '@param' && $tokens[$tag]['content'] !== '@return' && $tokens[$tag]['content'] !== '@throws') { + continue; } - // Check @return - $return = $comment_parser->getReturn(); - if ($return !== null) + $classes = $tokens[($tag + 2)]['content']; + $space = strpos($classes, ' '); + if ($space !== false) { + $classes = substr($classes, 0, $space); + } + + $tab = strpos($classes, "\t"); + if ($tab !== false) { + $classes = substr($classes, 0, $tab); + } + + $classes = explode('|', str_replace('[]', '', $classes)); + foreach ($classes as $class) { - $type = $return->getValue(); - $types = explode('|', str_replace('[]', '', $type)); - foreach ($types as $type) - { - $ok = $this->check($phpcsFile, $type, $class_name_full, $class_name_short, $return->getLine() + $comment_start) ? true : $ok; - } + $ok = $this->check($phpcsFile, $class, $class_name_full, $class_name_short, $tokens[$tag + 2]['line']) ? true : $ok; } } - catch (PHP_CodeSniffer_CommentParser_ParserException $e) - { - $line = ($e->getLineWithinComment() + $comment_start); - $phpcsFile->addError($e->getMessage(), $line, 'FailedParse'); - } } } |