Skip to content
Snippets Groups Projects
Unverified Commit e4e05ca7 authored by Klaus Purer's avatar Klaus Purer Committed by GitHub
Browse files

fix(UseGlobalClass): Fix false positive with closure use statements (#3217297)

parent 0f9e1819
Branches
Tags
No related merge requests found
......@@ -11,6 +11,7 @@ namespace Drupal\Sniffs\Classes;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Util\Tokens;
/**
* Checks non-namespaced classes are referenced by FQN, not imported.
......@@ -54,6 +55,12 @@ class UseGlobalClassSniff implements Sniff
$tokens = $phpcsFile->getTokens();
// Make sure this is not a closure USE group.
$next = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
if ($tokens[$next]['code'] === T_OPEN_PARENTHESIS) {
return;
}
// Find the first declaration, marking the end of the use statements.
$bodyStart = $phpcsFile->findNext([T_CLASS, T_INTERFACE, T_TRAIT, T_FUNCTION], 0);
......
......@@ -85,3 +85,26 @@ class Example extends Test implements Test, Alias, MultiLineAlias {
abstract public function test9(): ?Test;
}
$getMapOnlyLatestRevision = function ($tableName, $baseField, $idField, $preValidIds = []) use ($db): ?array {
if (empty($tableName) || empty($baseField) || empty($idField)) {
return NULL;
}
$ids = [];
$map = [];
if (empty($preValidIds)) {
$ids = $db->query("SELECT MAX($idField) FROM $tableName GROUP BY $baseField")->fetchCol();
}
else {
$ids = $db->query("SELECT MAX($idField) FROM $tableName WHERE $idField IN (:ids[]) GROUP BY $baseField", [
':ids[]' => $preValidIds,
])->fetchCol();
}
if (empty($ids)) {
return NULL;
}
$map = $db->query("SELECT * FROM $tableName WHERE $idField IN (:ids[])", [
':ids[]' => $ids,
])->fetchAllAssoc($idField);
return $map;
};
......@@ -80,3 +80,26 @@ class Example extends \Test implements \Test, \Test1, \MultiLine {
abstract public function test9(): ?\Test;
}
$getMapOnlyLatestRevision = function ($tableName, $baseField, $idField, $preValidIds = []) use ($db): ?array {
if (empty($tableName) || empty($baseField) || empty($idField)) {
return NULL;
}
$ids = [];
$map = [];
if (empty($preValidIds)) {
$ids = $db->query("SELECT MAX($idField) FROM $tableName GROUP BY $baseField")->fetchCol();
}
else {
$ids = $db->query("SELECT MAX($idField) FROM $tableName WHERE $idField IN (:ids[]) GROUP BY $baseField", [
':ids[]' => $preValidIds,
])->fetchCol();
}
if (empty($ids)) {
return NULL;
}
$map = $db->query("SELECT * FROM $tableName WHERE $idField IN (:ids[])", [
':ids[]' => $ids,
])->fetchAllAssoc($idField);
return $map;
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment