mirror of
https://github.com/phpbb/phpbb.git
synced 2025-03-14 12:40:13 +01:00
[ticket/16736] Add sniffer for visibilitiy qualifiers before static keyword
PHPBB3-16736
This commit is contained in:
parent
f6b4031a96
commit
0897d3e381
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
use PHP_CodeSniffer\Sniffs\Sniff;
|
||||
|
||||
/**
|
||||
* Checks that the visibility qualifiers are placed after the static keyword
|
||||
* according to the coding guidelines
|
||||
*/
|
||||
class phpbb_Sniffs_ControlStructures_StaticKeywordSniff implements Sniff
|
||||
{
|
||||
/**
|
||||
* Registers the tokens that this sniff wants to listen for.
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return [
|
||||
T_STATIC,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes this test, when one of its tokens is encountered.
|
||||
*
|
||||
* @param File $phpcsFile The file being scanned.
|
||||
* @param int $stackPtr The position of the current token in the stack passed in $tokens.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
$disallowed_before_tokens = [
|
||||
T_PUBLIC,
|
||||
T_PROTECTED,
|
||||
T_PRIVATE,
|
||||
];
|
||||
|
||||
if (in_array($tokens[$stackPtr - 2]['code'], $disallowed_before_tokens))
|
||||
{
|
||||
$error = 'Access specifier (e.g. public) should follow static scope attribute. Encountered "' . $tokens[$stackPtr - 2]['content'] . '" before static';
|
||||
$phpcsFile->addError($error, $stackPtr, 'InvalidStaticFunctionDeclaration');
|
||||
}
|
||||
}
|
||||
}
|
@ -89,4 +89,7 @@
|
||||
<!-- There MUST be one space between control structure and opening parenthesis -->
|
||||
<rule ref="./phpbb/Sniffs/ControlStructures/OpeningParenthesisSniff.php" />
|
||||
|
||||
<!-- Static qualifier MUST be placed before the visibility qualifiers. -->
|
||||
<rule ref="./phpbb/Sniffs/ControlStructures/StaticKeywordSniff.php" />
|
||||
|
||||
</ruleset>
|
||||
|
Loading…
x
Reference in New Issue
Block a user