diff options
author | Tristan Darricau <github@nicofuma.fr> | 2014-11-29 18:41:39 +0100 |
---|---|---|
committer | Tristan Darricau <github@nicofuma.fr> | 2014-11-29 19:17:52 +0100 |
commit | c5227ab2a5d173dba881a275077e434afbe405a9 (patch) | |
tree | e1d821beeaadb9010f18b9ab11a7dd91bfc5669c /build | |
parent | ac8b07ddd934c9bcda0d5ce38fb7e438083afc7b (diff) | |
download | forums-c5227ab2a5d173dba881a275077e434afbe405a9.tar forums-c5227ab2a5d173dba881a275077e434afbe405a9.tar.gz forums-c5227ab2a5d173dba881a275077e434afbe405a9.tar.bz2 forums-c5227ab2a5d173dba881a275077e434afbe405a9.tar.xz forums-c5227ab2a5d173dba881a275077e434afbe405a9.zip |
[ticket/13402] Code sniffer, unused use, check the function doc blocks
PHPBB3-13402
Diffstat (limited to 'build')
-rw-r--r-- | build/code_sniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/build/code_sniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php b/build/code_sniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php index f81ec46579..1f961e102f 100644 --- a/build/code_sniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php +++ b/build/code_sniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php @@ -145,6 +145,68 @@ class phpbb_Sniffs_Namespaces_UnusedUseSniff implements PHP_CodeSniffer_Sniff { $old_function_declaration = $function_declaration; + // Check docblocks + $find = array( + T_COMMENT, + T_DOC_COMMENT, + T_CLASS, + T_FUNCTION, + T_OPEN_TAG, + ); + + $comment_end = $phpcsFile->findPrevious($find, ($function_declaration - 1)); + if ($comment_end !== false) + { + if (!$tokens[$comment_end]['code'] !== T_DOC_COMMENT) + { + $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(); + + foreach ($comment_parser->getParams() as $param) { + $type = $param->getType(); + + if ($type === $class_name_full) + { + $error = 'Either use statement or full name must be used.'; + $phpcsFile->addError($error, $param->getLine() + $comment_start, 'FullName'); + } + + if ($type === $class_name_short) + { + $ok = true; + } + } + + $return = $comment_parser->getReturn(); + if ($return !== null) + { + $type = $return->getValue(); + + if ($type === $class_name_full) + { + $error = 'Either use statement or full name must be used.'; + $phpcsFile->addError($error, $return->getLine() + $comment_start, 'FullName'); + } + + if ($type === $class_name_short) + { + $ok = true; + } + } + } + catch (PHP_CodeSniffer_CommentParser_ParserException $e) + { + $line = ($e->getLineWithinComment() + $comment_start); + $phpcsFile->addError($e->getMessage(), $line, 'FailedParse'); + } + } + } + $end_function = $phpcsFile->findNext(array(T_CLOSE_PARENTHESIS), ($function_declaration + 1)); $old_argument = $function_declaration; while (($argument = $phpcsFile->findNext(T_VARIABLE, ($old_argument + 1), $end_function)) !== false) |