mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 22:28:51 +00:00
[ticket/13402] Code sniffer, unused use, check the function doc blocks
PHPBB3-13402
This commit is contained in:
parent
ac8b07ddd9
commit
c5227ab2a5
1 changed files with 62 additions and 0 deletions
|
@ -145,6 +145,68 @@ class phpbb_Sniffs_Namespaces_UnusedUseSniff implements PHP_CodeSniffer_Sniff
|
||||||
{
|
{
|
||||||
$old_function_declaration = $function_declaration;
|
$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));
|
$end_function = $phpcsFile->findNext(array(T_CLOSE_PARENTHESIS), ($function_declaration + 1));
|
||||||
$old_argument = $function_declaration;
|
$old_argument = $function_declaration;
|
||||||
while (($argument = $phpcsFile->findNext(T_VARIABLE, ($old_argument + 1), $end_function)) !== false)
|
while (($argument = $phpcsFile->findNext(T_VARIABLE, ($old_argument + 1), $end_function)) !== false)
|
||||||
|
|
Loading…
Add table
Reference in a new issue