aboutsummaryrefslogtreecommitdiffstats
path: root/build/code_sniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php
diff options
context:
space:
mode:
authorTristan Darricau <github@nicofuma.fr>2016-04-12 22:06:36 +0200
committerTristan Darricau <github@nicofuma.fr>2016-04-12 22:26:57 +0200
commit96bdcedacdac770f9864ca36b0cf2df22d9d2f22 (patch)
tree60d34d7765bfb6511671c03c99f10c5dda6b018c /build/code_sniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php
parent58dfff38fadba08bd10ba064e8fd4faaf2b6d47a (diff)
downloadforums-96bdcedacdac770f9864ca36b0cf2df22d9d2f22.tar
forums-96bdcedacdac770f9864ca36b0cf2df22d9d2f22.tar.gz
forums-96bdcedacdac770f9864ca36b0cf2df22d9d2f22.tar.bz2
forums-96bdcedacdac770f9864ca36b0cf2df22d9d2f22.tar.xz
forums-96bdcedacdac770f9864ca36b0cf2df22d9d2f22.zip
[ticket/14598] Support vars docblock in sniffer
PHPBB3-14598
Diffstat (limited to 'build/code_sniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php')
-rw-r--r--build/code_sniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php93
1 files changed, 52 insertions, 41 deletions
diff --git a/build/code_sniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php b/build/code_sniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php
index 7ffd1aadd6..3125e4f05f 100644
--- a/build/code_sniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php
+++ b/build/code_sniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php
@@ -129,53 +129,19 @@ class phpbb_Sniffs_Namespaces_UnusedUseSniff implements PHP_CodeSniffer_Sniff
}
}
+ $old_docblock = $stackPtr;
+ while (($docblock = $phpcsFile->findNext(T_DOC_COMMENT_CLOSE_TAG, ($old_docblock + 1))) !== false)
+ {
+ $old_docblock = $docblock;
+ $ok = $this->checkDocblock($phpcsFile, $docblock, $tokens, $class_name_full, $class_name_short) ? true : $ok;
+ }
+
// Checks in type hinting
$old_function_declaration = $stackPtr;
while (($function_declaration = $phpcsFile->findNext(T_FUNCTION, ($old_function_declaration + 1))) !== false)
{
$old_function_declaration = $function_declaration;
- // Check docblocks
- $find = array(
- T_COMMENT,
- T_DOC_COMMENT_CLOSE_TAG,
- 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_CLOSE_TAG)
- {
- $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;
- }
-
- $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)
- {
- $ok = $this->check($phpcsFile, $class, $class_name_full, $class_name_short, $tokens[$tag + 2]['line']) ? true : $ok;
- }
- }
- }
- }
-
// Check type hint
$params = $phpcsFile->getMethodParameters($function_declaration);
foreach ($params as $param)
@@ -234,4 +200,49 @@ class phpbb_Sniffs_Namespaces_UnusedUseSniff implements PHP_CodeSniffer_Sniff
return false;
}
+
+ /**
+ * @param PHP_CodeSniffer_File $phpcsFile
+ * @param int $field
+ * @param array $tokens
+ * @param string $class_name_full
+ * @param string $class_name_short
+ * @param bool $ok
+ *
+ * @return bool
+ */
+ private function checkDocblock(PHP_CodeSniffer_File $phpcsFile, $comment_end, $tokens, $class_name_full, $class_name_short)
+ {
+ $ok = false;
+
+ $comment_start = $tokens[$comment_end]['comment_opener'];
+ foreach ($tokens[$comment_start]['comment_tags'] as $tag)
+ {
+ if (!in_array($tokens[$tag]['content'], array('@param', '@var', '@return', '@throws'), true))
+ {
+ continue;
+ }
+
+ $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)
+ {
+ $ok = $this->check($phpcsFile, $class, $class_name_full, $class_name_short, $tokens[$tag + 2]['line']) ? true : $ok;
+ }
+ }
+
+ return $ok;
+ }
}