Skip to content
Snippets Groups Projects
Commit e13f0580 authored by Klaus Purer's avatar Klaus Purer
Browse files

fix(GlobalFunction): Use core version as string and return number of token to...

fix(GlobalFunction): Use core version as string and return number of token to skip files for performance
parent 9514bd49
No related branches found
No related tags found
No related merge requests found
......@@ -43,7 +43,7 @@ class GlobalConstantSniff implements Sniff
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
* @return void|int
*/
public function process(File $phpcsFile, $stackPtr)
{
......@@ -56,7 +56,8 @@ class GlobalConstantSniff implements Sniff
$coreVersion = Project::getCoreVersion($phpcsFile);
if ($coreVersion !== '8.x') {
return;
// No need to check this file again, mark it as done.
return ($phpcsFile->numTokens + 1);
}
// Allow constants if they are deprecated.
......
......@@ -47,7 +47,7 @@ class GlobalDefineSniff extends FunctionCall
* @param int $closeBracket The position of the closing
* parenthesis in the stack.
*
* @return void
* @return void|int
*/
public function processFunctionCall(
File $phpcsFile,
......@@ -64,7 +64,8 @@ class GlobalDefineSniff extends FunctionCall
$coreVersion = Project::getCoreVersion($phpcsFile);
if ($coreVersion !== '8.x') {
return;
// No need to check this file again, mark it as done.
return ($phpcsFile->numTokens + 1);
}
// Allow constants if they are deprecated.
......
......@@ -47,7 +47,7 @@ class DbQuerySniff extends FunctionCall
* @param int $closeBracket The position of the closing
* parenthesis in the stack.
*
* @return void
* @return void|int
*/
public function processFunctionCall(
File $phpcsFile,
......@@ -57,7 +57,7 @@ class DbQuerySniff extends FunctionCall
) {
// This check only applies to Drupal 7, not Drupal 6.
if (Project::getCoreVersion($phpcsFile) !== '7.x') {
return;
return ($phpcsFile->numTokens + 1);
}
$tokens = $phpcsFile->getTokens();
......
......@@ -34,19 +34,19 @@ class HookInitCssSniff extends FunctionDefinition
* @param int $functionPtr The position of the function keyword
* in the stack.
*
* @return void
* @return void|int
*/
public function processFunction(File $phpcsFile, $stackPtr, $functionPtr)
{
$fileExtension = strtolower(substr($phpcsFile->getFilename(), -6));
// Only check in *.module files.
if ($fileExtension !== 'module') {
return;
return ($phpcsFile->numTokens + 1);
}
// This check only applies to Drupal 7, not Drupal 6.
if (Project::getCoreVersion($phpcsFile) !== '7.x') {
return;
return ($phpcsFile->numTokens + 1);
}
$fileName = substr(basename($phpcsFile->getFilename()), 0, -7);
......
......@@ -34,14 +34,14 @@ class InstallTSniff extends FunctionDefinition
* @param int $functionPtr The position of the function keyword
* in the stack.
*
* @return void
* @return void|int
*/
public function processFunction(File $phpcsFile, $stackPtr, $functionPtr)
{
$fileExtension = strtolower(substr($phpcsFile->getFilename(), -7));
// Only check in *.install files.
if ($fileExtension !== 'install') {
return;
return ($phpcsFile->numTokens + 1);
}
$fileName = substr(basename($phpcsFile->getFilename()), 0, -8);
......@@ -54,7 +54,7 @@ class InstallTSniff extends FunctionDefinition
// This check only applies to Drupal 7, not Drupal 8.
if (Project::getCoreVersion($phpcsFile) !== '7.x') {
return;
return ($phpcsFile->numTokens + 1);
}
// Search in the function body for t() calls.
......
......@@ -63,15 +63,16 @@ class GlobalFunctionSniff extends FunctionCall
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
* @return void|int
*/
public function process(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
// Only run this sniff on Drupal 8+.
if (Project::getCoreVersion($phpcsFile) < 8) {
return;
if (Project::getCoreVersion($phpcsFile) !== '8.x') {
// No need to check this file again, mark it as done.
return ($phpcsFile->numTokens + 1);
}
// We just want to listen on function calls, nothing else.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment