Skip to content

Instantly share code, notes, and snippets.

@nickvergessen
Last active September 12, 2016 09:53
Show Gist options
  • Save nickvergessen/410854dfd01963bc786cdb92947f2749 to your computer and use it in GitHub Desktop.
Save nickvergessen/410854dfd01963bc786cdb92947f2749 to your computer and use it in GitHub Desktop.
<?php use OCP\IUser;
function($u, IU $e, $d, IUser $i){};
diff --git a/build/codesniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php b/build/codesniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php
index 832b94c..48767ef 100644
--- a/build/codesniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php
+++ b/build/codesniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php
@@ -155,6 +155,29 @@ class phpbb_Sniffs_Namespaces_UnusedUseSniff implements PHP_CodeSniffer_Sniff
}
}
+ $old_closure_declaration = $stackPtr;
+ while (($closure_declaration = $phpcsFile->findNext(T_CLOSURE, ($old_closure_declaration + 1))) !== false) {
+ $old_closure_declaration = $closure_declaration;
+
+ $parameter_start = $phpcsFile->findNext(array(T_OPEN_PARENTHESIS), ($closure_declaration + 1));
+
+ if ($parameter_start === false) {
+ continue;
+ }
+
+ $parameter_end = $phpcsFile->findNext(array(T_CLOSE_PARENTHESIS), ($parameter_start + 1));
+
+ if ($parameter_end === false) {
+ continue;
+ }
+
+ $type_hint_start = $parameter_start;
+ while ($type_hint_start = $phpcsFile->findNext(array(T_STRING), ($type_hint_start + 1), $parameter_end)) {
+ $type_hint_class_name = trim($phpcsFile->getTokensAsString($type_hint_start, 1));
+ $ok = $this->check($phpcsFile, $type_hint_class_name, $class_name_full, $class_name_short, $parameter_start) ? true : $ok;
+ }
+ }
+
// Checks in catch blocks
$old_catch = $stackPtr;
while (($catch = $phpcsFile->findNext(T_CATCH, ($old_catch + 1))) !== false)
<?php use OCP\DB\QueryBuilder\IQueryBuilder;
/* @var IQueryBuilder $qb */
diff --git a/build/codesniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php b/build/codesniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php
index 48767ef..7096124 100644
--- a/build/codesniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php
+++ b/build/codesniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php
@@ -141,6 +141,24 @@ class phpbb_Sniffs_Namespaces_UnusedUseSniff implements PHP_CodeSniffer_Sniff
$ok = $this->checkDocblock($phpcsFile, $docblock, $tokens, $class_name_full, $class_name_short) ? true : $ok;
}
+ $old_docline = $stackPtr;
+ while (($docline = $phpcsFile->findNext(T_COMMENT, ($old_docline + 1))) !== false)
+ {
+ $old_docline = $docline;
+ $content = $phpcsFile->getTokensAsString($docline, 1);
+ $content = str_replace("\t", ' ', $content);
+ $content = explode(' ', $content);
+
+ // E.g. /* @var Class $var */
+ if ($content[1] === '@var') {
+ $classes = explode('|', str_replace('[]', '', $content[2]));
+ foreach ($classes as $class)
+ {
+ $ok = $this->check($phpcsFile, $class, $class_name_full, $class_name_short, $docline) ? true : $ok;
+ }
+ }
+ }
+
// Checks in type hinting
$old_function_declaration = $stackPtr;
while (($function_declaration = $phpcsFile->findNext(T_FUNCTION, ($old_function_declaration + 1))) !== false)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment