1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-01-17 22:28:46 +01:00

[ticket/14948] Update codesniffer files to be compatible with phpcs 3.x

PHPBB3-14948
This commit is contained in:
Marc Alexander 2018-12-30 14:41:24 +01:00
parent e76c673e2e
commit 9223781797
No known key found for this signature in database
GPG Key ID: 50E0D2423696F995
5 changed files with 74 additions and 54 deletions

View File

@ -81,28 +81,36 @@
--ignore=${project.basedir}/phpBB/phpbb/db/migration/data/v30x/*
phpBB/phpbb"
dir="." returnProperty="retval-php-strict" passthru="true" />
<php function="preg_replace" returnProperty="sniffIgnoreList">
<param value="/\s+/"/>
<param value=""/>
<param value="${project.basedir}/phpBB/cache/*,
${project.basedir}/phpBB/develop/*,
${project.basedir}/phpBB/ext/*,
${project.basedir}/phpBB/includes/diff/*.php,
${project.basedir}/phpBB/includes/sphinxapi.php,
${project.basedir}/phpBB/includes/utf/data/*,
${project.basedir}/phpBB/install/data/*,
${project.basedir}/phpBB/install/database_update.php,
${project.basedir}/phpBB/phpbb/*,
${project.basedir}/phpBB/vendor/*,
${project.basedir}/phpBB/vendor-ext/*,
${project.basedir}/phpBB/config.php,
${project.basedir}/phpBB/config_dev.php,
${project.basedir}/phpBB/config_test.php"/>
</php>
<exec command="phpBB/vendor/bin/phpcs
-s -p
--extensions=php
--standard=build/code_sniffer/ruleset-php-legacy-core.xml
--ignore=${project.basedir}/phpBB/cache/*
--ignore=${project.basedir}/phpBB/develop/*
--ignore=${project.basedir}/phpBB/ext/*
--ignore=${project.basedir}/phpBB/includes/diff/*.php
--ignore=${project.basedir}/phpBB/includes/sphinxapi.php
--ignore=${project.basedir}/phpBB/includes/utf/data/*
--ignore=${project.basedir}/phpBB/install/data/*
--ignore=${project.basedir}/phpBB/install/database_update.php
--ignore=${project.basedir}/phpBB/phpbb/*
--ignore=${project.basedir}/phpBB/vendor/*
--ignore=${sniffIgnoreList}
phpBB"
dir="." returnProperty="retval-php-legacy" passthru="true" />
<exec command="phpBB/vendor/bin/phpcs
-s -p
--extensions=php
--standard=build/code_sniffer/ruleset-php-extensions.xml
--ignore=${project.basedir}/phpBB/ext/*/tests/*
--ignore=${project.basedir}/phpBB/ext/*/vendor/*
--ignore=${project.basedir}/phpBB/ext/*/tests/*,${project.basedir}/phpBB/ext/*/vendor/*
phpBB/ext"
dir="." returnProperty="retval-php-ext" passthru="true" />
<if>

View File

@ -11,6 +11,9 @@
*
*/
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;
/**
* Checks that each PHP source file contains a valid header as defined by the
* phpBB Coding Guidelines.
@ -18,7 +21,7 @@
* @package code_sniffer
* @author Manuel Pichler <mapi@phpundercontrol.org>
*/
class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff
class phpbb_Sniffs_Commenting_FileCommentSniff implements Sniff
{
/**
* Returns an array of tokens this test wants to listen for.
@ -33,13 +36,13 @@ class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return null
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
public function process(File $phpcsFile, $stackPtr): void
{
// We are only interested in the first file comment.
if ($stackPtr !== 0)
@ -62,7 +65,7 @@ class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff
// Mark as error if this is not a doc comment
else if ($start === false || $tokens[$start]['code'] !== T_DOC_COMMENT_OPEN_TAG)
{
$phpcsFile->addError('Missing required file doc comment.', $stackPtr);
$phpcsFile->addError('Missing required file doc comment.', $stackPtr, 'MissingComment');
return;
}
@ -82,7 +85,7 @@ class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff
if ($tokens[$token]['column'] === 1 && (($tokens[$token]['content'] !== '*' && $tokens[$token]['content'] !== ' ') || ($tokens[$token]['content'] === ' ' && $tokens[$token + 1]['content'] !== '*')))
{
$message = 'The file doc comment should not be indented.';
$phpcsFile->addWarning($message, $token);
$phpcsFile->addWarning($message, $token, 'CommentIndented');
}
}
@ -95,13 +98,13 @@ class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff
if (!(($tokens[$start + 2]['content'] !== '*' && $tokens[$start + 4]['content'] !== '*') || ($tokens[$start + 3]['content'] !== '*' && $tokens[$start + 6]['content'] !== '*')))
{
$message = 'The first file comment line should be empty.';
$phpcsFile->addWarning($message, ($start + 1));
$phpcsFile->addWarning($message, ($start + 1), 'CommentFirstNotEmpty');
}
if ($tokens[$end - 3]['content'] !== '*' && $tokens[$end - 6]['content'] !== '*')
{
$message = 'The last file comment line should be empty.';
$phpcsFile->addWarning($message, $end - 1);
$phpcsFile->addWarning($message, $end - 1, 'CommentLastNotEmpty');
}
//$this->processPackage($phpcsFile, $start, $tags);
@ -113,59 +116,59 @@ class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff
/**
* Checks that the tags array contains a valid package tag
*
* @param PHP_CodeSniffer_File $phpcsFile The context source file instance.
* @param File $phpcsFile The context source file instance.
* @param integer The stack pointer for the first comment token.
* @param array(string=>array) $tags The found file doc comment tags.
*
* @return null
* @return void
*/
protected function processPackage(PHP_CodeSniffer_File $phpcsFile, $ptr, $tags)
protected function processPackage(File $phpcsFile, $ptr, $tags): void
{
if (!isset($tags['package']))
{
$message = 'Missing require @package tag in file doc comment.';
$phpcsFile->addError($message, $ptr);
$phpcsFile->addError($message, $ptr, 'MissingTagPackage');
}
else if (preg_match('/^([\w]+)$/', $tags['package'][0]) === 0)
{
$message = 'Invalid content found for @package tag.';
$phpcsFile->addWarning($message, $tags['package'][1]);
$phpcsFile->addWarning($message, $tags['package'][1], 'InvalidTagPackage');
}
}
/**
* Checks that the tags array contains a valid version tag
*
* @param PHP_CodeSniffer_File $phpcsFile The context source file instance.
* @param File $phpcsFile The context source file instance.
* @param integer The stack pointer for the first comment token.
* @param array(string=>array) $tags The found file doc comment tags.
*
* @return null
* @return void
*/
protected function processVersion(PHP_CodeSniffer_File $phpcsFile, $ptr, $tags)
protected function processVersion(File $phpcsFile, $ptr, $tags): void
{
if (!isset($tags['version']))
{
$message = 'Missing require @version tag in file doc comment.';
$phpcsFile->addError($message, $ptr);
$phpcsFile->addError($message, $ptr, 'MissingTagVersion');
}
else if (preg_match('/^\$Id:[^\$]+\$$/', $tags['version'][0]) === 0)
{
$message = 'Invalid content found for @version tag, use "$Id: $".';
$phpcsFile->addError($message, $tags['version'][1]);
$phpcsFile->addError($message, $tags['version'][1], 'InvalidTagVersion');
}
}
/**
* Checks that the tags array contains a valid copyright tag
*
* @param PHP_CodeSniffer_File $phpcsFile The context source file instance.
* @param File $phpcsFile The context source file instance.
* @param integer The stack pointer for the first comment token.
* @param array(string=>array) $tags The found file doc comment tags.
*
* @return null
* @return void
*/
protected function processCopyright(PHP_CodeSniffer_File $phpcsFile, $ptr, $tags)
protected function processCopyright(File $phpcsFile, $ptr, $tags): void
{
$copyright = '(c) phpBB Limited <https://www.phpbb.com>';
$tokens = $phpcsFile->getTokens();
@ -177,7 +180,7 @@ class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff
if ($tokens[$tag + 2]['content'] !== $copyright)
{
$message = 'Invalid content found for the first @copyright tag, use "' . $copyright . '".';
$phpcsFile->addError($message, $tags['copyright'][0][1]);
$phpcsFile->addError($message, $tags['copyright'][0][1], 'InvalidTagCopyright');
}
return;
@ -185,19 +188,19 @@ class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff
}
$message = 'Missing require @copyright tag in file doc comment.';
$phpcsFile->addError($message, $ptr);
$phpcsFile->addError($message, $ptr, 'MissingTagCopyright');
}
/**
* Checks that the tags array contains a valid license tag
*
* @param PHP_CodeSniffer_File $phpcsFile The context source file instance.
* @param File $phpcsFile The context source file instance.
* @param integer The stack pointer for the first comment token.
* @param array(string=>array) $tags The found file doc comment tags.
*
* @return null
* @return void
*/
protected function processLicense(PHP_CodeSniffer_File $phpcsFile, $ptr, $tags)
protected function processLicense(File $phpcsFile, $ptr, $tags): void
{
$license = 'GNU General Public License, version 2 (GPL-2.0)';
$tokens = $phpcsFile->getTokens();
@ -210,7 +213,7 @@ class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff
if ($found)
{
$message = 'It must be only one @license tag in file doc comment.';
$phpcsFile->addError($message, $ptr);
$phpcsFile->addError($message, $ptr, 'MultiTagVersion');
}
$found = true;
@ -218,7 +221,7 @@ class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff
if ($tokens[$tag + 2]['content'] !== $license)
{
$message = 'Invalid content found for @license tag, use "' . $license . '".';
$phpcsFile->addError($message, $tags['license'][0][1]);
$phpcsFile->addError($message, $tags['license'][0][1], 'InvalidTagLicense');
}
}
}
@ -226,7 +229,7 @@ class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff
if (!$found)
{
$message = 'Missing require @license tag in file doc comment.';
$phpcsFile->addError($message, $ptr);
$phpcsFile->addError($message, $ptr, 'MissingTagLicense');
}
}
}

View File

@ -11,11 +11,14 @@
*
*/
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;
/**
* Checks that the opening brace of a control structures is on the line after.
* From Generic_Sniffs_Functions_OpeningFunctionBraceBsdAllmanSniff
*/
class phpbb_Sniffs_ControlStructures_OpeningBraceBsdAllmanSniff implements PHP_CodeSniffer_Sniff
class phpbb_Sniffs_ControlStructures_OpeningBraceBsdAllmanSniff implements Sniff
{
/**
* Registers the tokens that this sniff wants to listen for.
@ -36,13 +39,13 @@ class phpbb_Sniffs_ControlStructures_OpeningBraceBsdAllmanSniff implements PHP_C
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @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(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
public function process(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();

View File

@ -11,11 +11,14 @@
*
*/
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;
/**
* Checks that there is exactly one space between the keyword and the opening
* parenthesis of a control structures.
*/
class phpbb_Sniffs_ControlStructures_OpeningParenthesisSniff implements PHP_CodeSniffer_Sniff
class phpbb_Sniffs_ControlStructures_OpeningParenthesisSniff implements Sniff
{
/**
* Registers the tokens that this sniff wants to listen for.
@ -36,13 +39,13 @@ class phpbb_Sniffs_ControlStructures_OpeningParenthesisSniff implements PHP_Code
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @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(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
public function process(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();

View File

@ -11,10 +11,13 @@
*
*/
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;
/**
* Checks that each use statement is used.
*/
class phpbb_Sniffs_Namespaces_UnusedUseSniff implements PHP_CodeSniffer_Sniff
class phpbb_Sniffs_Namespaces_UnusedUseSniff implements Sniff
{
/**
* {@inheritdoc}
@ -24,7 +27,7 @@ class phpbb_Sniffs_Namespaces_UnusedUseSniff implements PHP_CodeSniffer_Sniff
return array(T_USE);
}
protected function check($phpcsFile, $found_name, $full_name, $short_name, $line)
protected function check(File $phpcsFile, $found_name, $full_name, $short_name, $line)
{
if ($found_name === $full_name)
@ -44,7 +47,7 @@ class phpbb_Sniffs_Namespaces_UnusedUseSniff implements PHP_CodeSniffer_Sniff
/**
* {@inheritdoc}
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
public function process(File $phpcsFile, $stackPtr)
{
if ($this->should_ignore_use($phpcsFile, $stackPtr) === true)
{
@ -179,13 +182,13 @@ class phpbb_Sniffs_Namespaces_UnusedUseSniff implements PHP_CodeSniffer_Sniff
/**
* Check if this use statement is part of the namespace block.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token in
* the stack passed in $tokens.
*
* @return bool
*/
private function should_ignore_use(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
private function should_ignore_use(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
@ -207,7 +210,7 @@ class phpbb_Sniffs_Namespaces_UnusedUseSniff implements PHP_CodeSniffer_Sniff
}
/**
* @param PHP_CodeSniffer_File $phpcsFile
* @param File $phpcsFile
* @param int $field
* @param array $tokens
* @param string $class_name_full
@ -216,7 +219,7 @@ class phpbb_Sniffs_Namespaces_UnusedUseSniff implements PHP_CodeSniffer_Sniff
*
* @return bool
*/
private function checkDocblock(PHP_CodeSniffer_File $phpcsFile, $comment_end, $tokens, $class_name_full, $class_name_short)
private function checkDocblock(File $phpcsFile, $comment_end, $tokens, $class_name_full, $class_name_short)
{
$ok = false;