aboutsummaryrefslogtreecommitdiffstats
path: root/build/code_sniffer
diff options
context:
space:
mode:
authorMaat <maat-pub@mageia.biz>2020-05-08 18:29:30 +0200
committerMaat <maat-pub@mageia.biz>2020-05-08 21:36:04 +0200
commit36bc1870f21fac04736a1049c1d5b8e127d729f4 (patch)
tree9d102331eeaf1ef3cd23e656320d7c08e65757ed /build/code_sniffer
parent8875d385d0579b451dac4d9bda465172b4f69ee0 (diff)
parent149375253685b3a38996f63015a74b7a0f53aa14 (diff)
downloadforums-36bc1870f21fac04736a1049c1d5b8e127d729f4.tar
forums-36bc1870f21fac04736a1049c1d5b8e127d729f4.tar.gz
forums-36bc1870f21fac04736a1049c1d5b8e127d729f4.tar.bz2
forums-36bc1870f21fac04736a1049c1d5b8e127d729f4.tar.xz
forums-36bc1870f21fac04736a1049c1d5b8e127d729f4.zip
Merge remote-tracking branch 'upstream/prep-release-3.1.11'
Diffstat (limited to 'build/code_sniffer')
-rw-r--r--build/code_sniffer/phpbb/Sniffs/Commenting/FileCommentSniff.php232
-rw-r--r--build/code_sniffer/phpbb/Sniffs/ControlStructures/OpeningBraceBsdAllmanSniff.php143
-rw-r--r--build/code_sniffer/phpbb/Sniffs/ControlStructures/OpeningParenthesisSniff.php60
-rw-r--r--build/code_sniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php248
-rw-r--r--build/code_sniffer/ruleset-minimum.xml18
-rw-r--r--build/code_sniffer/ruleset-php-extensions.xml8
-rw-r--r--build/code_sniffer/ruleset-php-legacy-core.xml11
-rw-r--r--build/code_sniffer/ruleset-php-legacy.xml92
-rw-r--r--build/code_sniffer/ruleset-php-strict-core.xml9
-rw-r--r--build/code_sniffer/ruleset-php-strict.xml48
10 files changed, 869 insertions, 0 deletions
diff --git a/build/code_sniffer/phpbb/Sniffs/Commenting/FileCommentSniff.php b/build/code_sniffer/phpbb/Sniffs/Commenting/FileCommentSniff.php
new file mode 100644
index 0000000000..8c0ec853ff
--- /dev/null
+++ b/build/code_sniffer/phpbb/Sniffs/Commenting/FileCommentSniff.php
@@ -0,0 +1,232 @@
+<?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.
+*
+*/
+
+/**
+* Checks that each PHP source file contains a valid header as defined by the
+* phpBB Coding Guidelines.
+*
+* @package code_sniffer
+* @author Manuel Pichler <mapi@phpundercontrol.org>
+*/
+class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff
+{
+ /**
+ * Returns an array of tokens this test wants to listen for.
+ *
+ * @return array
+ */
+ public function register()
+ {
+ return array(T_OPEN_TAG);
+ }
+
+ /**
+ * Processes this test, when one of its tokens is encountered.
+ *
+ * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
+ * @param int $stackPtr The position of the current token
+ * in the stack passed in $tokens.
+ *
+ * @return null
+ */
+ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
+ {
+ // We are only interested in the first file comment.
+ if ($stackPtr !== 0)
+ {
+ if ($phpcsFile->findPrevious(T_OPEN_TAG, $stackPtr - 1) !== false)
+ {
+ return;
+ }
+ }
+
+ // Fetch next non whitespace token
+ $tokens = $phpcsFile->getTokens();
+ $start = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, null, true);
+
+ // Skip empty files
+ if ($tokens[$start]['code'] === T_CLOSE_TAG)
+ {
+ return;
+ }
+ // 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);
+ return;
+ }
+
+ // Find comment end token
+ $end = $tokens[$start]['comment_closer'];
+
+ // If there is no end, skip processing here
+ if ($end === false)
+ {
+ return;
+ }
+
+ // check comment lines without the first(/**) an last(*/) line
+ for ($token = $start + 1, $c = $end - 2; $token <= $c; ++$token)
+ {
+ // Check that each line starts with a '*'
+ 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);
+ }
+ }
+
+ // Check that the first and last line is empty
+ // /**T_WHITESPACE
+ // (T_WHITESPACE)*T_WHITESPACE
+ // (T_WHITESPACE)* ...
+ // (T_WHITESPACE)*T_WHITESPACE
+ // T_WHITESPACE*/
+ 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));
+ }
+
+ if ($tokens[$end - 3]['content'] !== '*' && $tokens[$end - 6]['content'] !== '*')
+ {
+ $message = 'The last file comment line should be empty.';
+ $phpcsFile->addWarning($message, $end - 1);
+ }
+
+ //$this->processPackage($phpcsFile, $start, $tags);
+ //$this->processVersion($phpcsFile, $start, $tags);
+ $this->processCopyright($phpcsFile, $start, $tokens[$start]['comment_tags']);
+ $this->processLicense($phpcsFile, $start, $tokens[$start]['comment_tags']);
+ }
+
+ /**
+ * Checks that the tags array contains a valid package tag
+ *
+ * @param PHP_CodeSniffer_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
+ */
+ protected function processPackage(PHP_CodeSniffer_File $phpcsFile, $ptr, $tags)
+ {
+ if (!isset($tags['package']))
+ {
+ $message = 'Missing require @package tag in file doc comment.';
+ $phpcsFile->addError($message, $ptr);
+ }
+ else if (preg_match('/^([\w]+)$/', $tags['package'][0]) === 0)
+ {
+ $message = 'Invalid content found for @package tag.';
+ $phpcsFile->addWarning($message, $tags['package'][1]);
+ }
+ }
+
+ /**
+ * Checks that the tags array contains a valid version tag
+ *
+ * @param PHP_CodeSniffer_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
+ */
+ protected function processVersion(PHP_CodeSniffer_File $phpcsFile, $ptr, $tags)
+ {
+ if (!isset($tags['version']))
+ {
+ $message = 'Missing require @version tag in file doc comment.';
+ $phpcsFile->addError($message, $ptr);
+ }
+ else if (preg_match('/^\$Id:[^\$]+\$$/', $tags['version'][0]) === 0)
+ {
+ $message = 'Invalid content found for @version tag, use "$Id: $".';
+ $phpcsFile->addError($message, $tags['version'][1]);
+ }
+ }
+
+ /**
+ * Checks that the tags array contains a valid copyright tag
+ *
+ * @param PHP_CodeSniffer_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
+ */
+ protected function processCopyright(PHP_CodeSniffer_File $phpcsFile, $ptr, $tags)
+ {
+ $copyright = '(c) phpBB Limited <https://www.phpbb.com>';
+ $tokens = $phpcsFile->getTokens();
+
+ foreach ($tags as $tag)
+ {
+ if ($tokens[$tag]['content'] === '@copyright')
+ {
+ if ($tokens[$tag + 2]['content'] !== $copyright)
+ {
+ $message = 'Invalid content found for the first @copyright tag, use "' . $copyright . '".';
+ $phpcsFile->addError($message, $tags['copyright'][0][1]);
+ }
+
+ return;
+ }
+ }
+
+ $message = 'Missing require @copyright tag in file doc comment.';
+ $phpcsFile->addError($message, $ptr);
+ }
+
+ /**
+ * Checks that the tags array contains a valid license tag
+ *
+ * @param PHP_CodeSniffer_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
+ */
+ protected function processLicense(PHP_CodeSniffer_File $phpcsFile, $ptr, $tags)
+ {
+ $license = 'GNU General Public License, version 2 (GPL-2.0)';
+ $tokens = $phpcsFile->getTokens();
+
+ $found = false;
+ foreach ($tags as $tag)
+ {
+ if ($tokens[$tag]['content'] === '@license')
+ {
+ if ($found)
+ {
+ $message = 'It must be only one @license tag in file doc comment.';
+ $phpcsFile->addError($message, $ptr);
+ }
+
+ $found = true;
+
+ if ($tokens[$tag + 2]['content'] !== $license)
+ {
+ $message = 'Invalid content found for @license tag, use "' . $license . '".';
+ $phpcsFile->addError($message, $tags['license'][0][1]);
+ }
+ }
+ }
+
+ if (!$found)
+ {
+ $message = 'Missing require @license tag in file doc comment.';
+ $phpcsFile->addError($message, $ptr);
+ }
+ }
+}
diff --git a/build/code_sniffer/phpbb/Sniffs/ControlStructures/OpeningBraceBsdAllmanSniff.php b/build/code_sniffer/phpbb/Sniffs/ControlStructures/OpeningBraceBsdAllmanSniff.php
new file mode 100644
index 0000000000..885c38c5b4
--- /dev/null
+++ b/build/code_sniffer/phpbb/Sniffs/ControlStructures/OpeningBraceBsdAllmanSniff.php
@@ -0,0 +1,143 @@
+<?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.
+*
+*/
+
+/**
+ * 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
+{
+ /**
+ * Registers the tokens that this sniff wants to listen for.
+ */
+ public function register()
+ {
+ return array(
+ T_IF,
+ T_ELSE,
+ T_FOREACH,
+ T_WHILE,
+ T_DO,
+ T_FOR,
+ T_SWITCH,
+ );
+ }
+
+ /**
+ * Processes this test, when one of its tokens is encountered.
+ *
+ * @param PHP_CodeSniffer_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)
+ {
+ $tokens = $phpcsFile->getTokens();
+
+ if (isset($tokens[$stackPtr]['scope_opener']) === false)
+ {
+ return;
+ }
+
+ /*
+ * ...
+ * }
+ * else if ()
+ * {
+ * ...
+ */
+ if ($tokens[$stackPtr]['code'] === T_ELSE && $tokens[$stackPtr + 2]['code'] === T_IF)
+ {
+ return;
+ }
+
+ $openingBrace = $tokens[$stackPtr]['scope_opener'];
+
+ /*
+ * ...
+ * do
+ * {
+ * <code>
+ * } while();
+ * ...
+ * }
+ * else
+ * {
+ * ...
+ */
+ if ($tokens[$stackPtr]['code'] === T_DO ||$tokens[$stackPtr]['code'] === T_ELSE)
+ {
+ $cs_line = $tokens[$stackPtr]['line'];
+ }
+ else
+ {
+ // The end of the function occurs at the end of the argument list. Its
+ // like this because some people like to break long function declarations
+ // over multiple lines.
+ $cs_line = $tokens[$tokens[$stackPtr]['parenthesis_closer']]['line'];
+ }
+
+ $braceLine = $tokens[$openingBrace]['line'];
+
+ $lineDifference = ($braceLine - $cs_line);
+
+ if ($lineDifference === 0)
+ {
+ $error = 'Opening brace should be on a new line';
+ $phpcsFile->addError($error, $openingBrace, 'BraceOnSameLine');
+ return;
+ }
+
+ if ($lineDifference > 1)
+ {
+ $error = 'Opening brace should be on the line after the declaration; found %s blank line(s)';
+ $data = array(($lineDifference - 1));
+ $phpcsFile->addError($error, $openingBrace, 'BraceSpacing', $data);
+ return;
+ }
+
+ // We need to actually find the first piece of content on this line,
+ // as if this is a method with tokens before it (public, static etc)
+ // or an if with an else before it, then we need to start the scope
+ // checking from there, rather than the current token.
+ $lineStart = $stackPtr;
+ while (($lineStart = $phpcsFile->findPrevious(array(T_WHITESPACE), ($lineStart - 1), null, false)) !== false)
+ {
+ if (strpos($tokens[$lineStart]['content'], $phpcsFile->eolChar) !== false)
+ {
+ break;
+ }
+ }
+
+ // We found a new line, now go forward and find the first non-whitespace
+ // token.
+ $lineStart = $phpcsFile->findNext(array(T_WHITESPACE), $lineStart, null, true);
+
+ // The opening brace is on the correct line, now it needs to be
+ // checked to be correctly indented.
+ $startColumn = $tokens[$lineStart]['column'];
+ $braceIndent = $tokens[$openingBrace]['column'];
+
+ if ($braceIndent !== $startColumn)
+ {
+ $error = 'Opening brace indented incorrectly; expected %s spaces, found %s';
+ $data = array(
+ ($startColumn - 1),
+ ($braceIndent - 1),
+ );
+ $phpcsFile->addError($error, $openingBrace, 'BraceIndent', $data);
+ }
+ }
+}
diff --git a/build/code_sniffer/phpbb/Sniffs/ControlStructures/OpeningParenthesisSniff.php b/build/code_sniffer/phpbb/Sniffs/ControlStructures/OpeningParenthesisSniff.php
new file mode 100644
index 0000000000..349bccbb02
--- /dev/null
+++ b/build/code_sniffer/phpbb/Sniffs/ControlStructures/OpeningParenthesisSniff.php
@@ -0,0 +1,60 @@
+<?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.
+ *
+ */
+
+/**
+ * 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
+{
+ /**
+ * Registers the tokens that this sniff wants to listen for.
+ */
+ public function register()
+ {
+ return array(
+ T_IF,
+ T_FOREACH,
+ T_WHILE,
+ T_FOR,
+ T_SWITCH,
+ T_ELSEIF,
+ T_CATCH,
+ );
+ }
+
+ /**
+ * Processes this test, when one of its tokens is encountered.
+ *
+ * @param PHP_CodeSniffer_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)
+ {
+ $tokens = $phpcsFile->getTokens();
+
+ if ($tokens[$stackPtr + 1]['content'] === '(')
+ {
+ $error = 'There should be exactly one space between the keyword and opening parenthesis';
+ $phpcsFile->addError($error, $stackPtr, 'NoSpaceBeforeOpeningParenthesis');
+ }
+ else if ($tokens[$stackPtr + 1]['content'] !== ' ')
+ {
+ $error = 'There should be exactly one space between the keyword and opening parenthesis';
+ $phpcsFile->addError($error, $stackPtr, 'IncorrectSpaceBeforeOpeningParenthesis');
+ }
+ }
+}
diff --git a/build/code_sniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php b/build/code_sniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php
new file mode 100644
index 0000000000..3125e4f05f
--- /dev/null
+++ b/build/code_sniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php
@@ -0,0 +1,248 @@
+<?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.
+*
+*/
+
+/**
+* Checks that each use statement is used.
+*/
+class phpbb_Sniffs_Namespaces_UnusedUseSniff implements PHP_CodeSniffer_Sniff
+{
+ /**
+ * {@inheritdoc}
+ */
+ public function register()
+ {
+ return array(T_USE);
+ }
+
+ protected function check($phpcsFile, $found_name, $full_name, $short_name, $line)
+ {
+
+ if ($found_name === $full_name)
+ {
+ $error = 'Either use statement or full name must be used.';
+ $phpcsFile->addError($error, $line, 'FullName');
+ }
+
+ if ($found_name === $short_name)
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
+ {
+ if ($this->should_ignore_use($phpcsFile, $stackPtr) === true)
+ {
+ return;
+ }
+
+ $tokens = $phpcsFile->getTokens();
+
+ $class_name_start = $phpcsFile->findNext(array(T_NS_SEPARATOR, T_STRING), ($stackPtr + 1));
+
+ $find = array(
+ T_NS_SEPARATOR,
+ T_STRING,
+ T_WHITESPACE,
+ );
+
+ $class_name_end = $phpcsFile->findNext($find, ($stackPtr + 1), null, true);
+
+ $aliasing_as_position = $phpcsFile->findNext(T_AS, $class_name_end, null, false, null, true);
+ if ($aliasing_as_position !== false)
+ {
+ $alias_position = $phpcsFile->findNext(T_STRING, $aliasing_as_position, null, false, null, true);
+ $class_name_short = $tokens[$alias_position]['content'];
+ $class_name_full = $phpcsFile->getTokensAsString($class_name_start, ($class_name_end - $class_name_start - 1));
+ }
+ else
+ {
+ $class_name_full = $phpcsFile->getTokensAsString($class_name_start, ($class_name_end - $class_name_start));
+ $class_name_short = $tokens[$class_name_end - 1]['content'];
+ }
+
+ $ok = false;
+
+ // Checks in simple statements (new, instanceof and extends)
+ foreach (array(T_INSTANCEOF, T_NEW, T_EXTENDS) as $keyword)
+ {
+ $old_simple_statement = $stackPtr;
+ while (($simple_statement = $phpcsFile->findNext($keyword, ($old_simple_statement + 1))) !== false)
+ {
+ $old_simple_statement = $simple_statement;
+
+ $simple_class_name_start = $phpcsFile->findNext(array(T_NS_SEPARATOR, T_STRING), ($simple_statement + 1));
+ $simple_class_name_end = $phpcsFile->findNext($find, ($simple_statement + 1), null, true);
+
+ $simple_class_name = trim($phpcsFile->getTokensAsString($simple_class_name_start, ($simple_class_name_end - $simple_class_name_start)));
+
+ $ok = $this->check($phpcsFile, $simple_class_name, $class_name_full, $class_name_short, $simple_statement) ? true : $ok;
+ }
+ }
+
+ // Checks paamayim nekudotayim
+ $old_paamayim_nekudotayim = $stackPtr;
+ while (($paamayim_nekudotayim = $phpcsFile->findNext(T_PAAMAYIM_NEKUDOTAYIM, ($old_paamayim_nekudotayim + 1))) !== false)
+ {
+ $old_paamayim_nekudotayim = $paamayim_nekudotayim;
+
+ $paamayim_nekudotayim_class_name_start = $phpcsFile->findPrevious($find, $paamayim_nekudotayim - 1, null, true);
+ $paamayim_nekudotayim_class_name_end = $paamayim_nekudotayim - 1;
+
+ $paamayim_nekudotayim_class_name = trim($phpcsFile->getTokensAsString($paamayim_nekudotayim_class_name_start + 1, ($paamayim_nekudotayim_class_name_end - $paamayim_nekudotayim_class_name_start)));
+
+ $ok = $this->check($phpcsFile, $paamayim_nekudotayim_class_name, $class_name_full, $class_name_short, $paamayim_nekudotayim) ? true : $ok;
+ }
+
+ // Checks in implements
+ $old_implements = $stackPtr;
+ while (($implements = $phpcsFile->findNext(T_IMPLEMENTS, ($old_implements + 1))) !== false)
+ {
+ $old_implements = $implements;
+
+ $old_implemented_class = $implements;
+ while (($implemented_class = $phpcsFile->findNext(T_STRING, ($old_implemented_class + 1), null, false, null, true)) !== false)
+ {
+ $old_implemented_class = $implemented_class;
+
+ $implements_class_name_start = $phpcsFile->findNext(array(T_NS_SEPARATOR, T_STRING), ($implemented_class - 1));
+ $implements_class_name_end = $phpcsFile->findNext($find, ($implemented_class - 1), null, true);
+
+ $implements_class_name = trim($phpcsFile->getTokensAsString($implements_class_name_start, ($implements_class_name_end - $implements_class_name_start)));
+
+ $ok = $this->check($phpcsFile, $implements_class_name, $class_name_full, $class_name_short, $implements) ? true : $ok;
+ }
+ }
+
+ $old_docblock = $stackPtr;
+ while (($docblock = $phpcsFile->findNext(T_DOC_COMMENT_CLOSE_TAG, ($old_docblock + 1))) !== false)
+ {
+ $old_docblock = $docblock;
+ $ok = $this->checkDocblock($phpcsFile, $docblock, $tokens, $class_name_full, $class_name_short) ? true : $ok;
+ }
+
+ // Checks in type hinting
+ $old_function_declaration = $stackPtr;
+ while (($function_declaration = $phpcsFile->findNext(T_FUNCTION, ($old_function_declaration + 1))) !== false)
+ {
+ $old_function_declaration = $function_declaration;
+
+ // Check type hint
+ $params = $phpcsFile->getMethodParameters($function_declaration);
+ foreach ($params as $param)
+ {
+ $ok = $this->check($phpcsFile, $param['type_hint'], $class_name_full, $class_name_short, $function_declaration) ? true : $ok;
+ }
+ }
+
+ // Checks in catch blocks
+ $old_catch = $stackPtr;
+ while (($catch = $phpcsFile->findNext(T_CATCH, ($old_catch + 1))) !== false)
+ {
+ $old_catch = $catch;
+
+ $caught_class_name_start = $phpcsFile->findNext(array(T_NS_SEPARATOR, T_STRING), $catch + 1);
+ $caught_class_name_end = $phpcsFile->findNext($find, $caught_class_name_start + 1, null, true);
+
+ $caught_class_name = trim($phpcsFile->getTokensAsString($caught_class_name_start, ($caught_class_name_end - $caught_class_name_start)));
+
+ $ok = $this->check($phpcsFile, $caught_class_name, $class_name_full, $class_name_short, $catch) ? true : $ok;
+ }
+
+ if (!$ok)
+ {
+ $error = 'There must not be unused USE statements.';
+ $phpcsFile->addError($error, $stackPtr, 'Unused');
+ }
+ }
+
+ /**
+ * Check if this use statement is part of the namespace block.
+ *
+ * @param PHP_CodeSniffer_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)
+ {
+ $tokens = $phpcsFile->getTokens();
+
+ // Ignore USE keywords inside closures.
+ $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
+ if ($tokens[$next]['code'] === T_OPEN_PARENTHESIS)
+ {
+ return true;
+ }
+
+ // Ignore USE keywords for traits.
+ if ($phpcsFile->hasCondition($stackPtr, array(T_CLASS, T_TRAIT)) === true)
+ {
+ return true;
+ }
+
+ return false;
+
+ }
+
+ /**
+ * @param PHP_CodeSniffer_File $phpcsFile
+ * @param int $field
+ * @param array $tokens
+ * @param string $class_name_full
+ * @param string $class_name_short
+ * @param bool $ok
+ *
+ * @return bool
+ */
+ private function checkDocblock(PHP_CodeSniffer_File $phpcsFile, $comment_end, $tokens, $class_name_full, $class_name_short)
+ {
+ $ok = false;
+
+ $comment_start = $tokens[$comment_end]['comment_opener'];
+ foreach ($tokens[$comment_start]['comment_tags'] as $tag)
+ {
+ if (!in_array($tokens[$tag]['content'], array('@param', '@var', '@return', '@throws'), true))
+ {
+ continue;
+ }
+
+ $classes = $tokens[($tag + 2)]['content'];
+ $space = strpos($classes, ' ');
+ if ($space !== false)
+ {
+ $classes = substr($classes, 0, $space);
+ }
+
+ $tab = strpos($classes, "\t");
+ if ($tab !== false)
+ {
+ $classes = substr($classes, 0, $tab);
+ }
+
+ $classes = explode('|', str_replace('[]', '', $classes));
+ foreach ($classes as $class)
+ {
+ $ok = $this->check($phpcsFile, $class, $class_name_full, $class_name_short, $tokens[$tag + 2]['line']) ? true : $ok;
+ }
+ }
+
+ return $ok;
+ }
+}
diff --git a/build/code_sniffer/ruleset-minimum.xml b/build/code_sniffer/ruleset-minimum.xml
new file mode 100644
index 0000000000..13f122cae7
--- /dev/null
+++ b/build/code_sniffer/ruleset-minimum.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0"?>
+<ruleset name="phpBB Minimum Standard">
+
+ <description>phpBB minimum coding standard</description>
+
+ <!-- All code files MUST use only UTF-8 without BOM. -->
+ <rule ref="Generic.Files.ByteOrderMark" />
+
+ <!-- All code files MUST use the Unix LF (linefeed) line ending. -->
+ <rule ref="Generic.Files.LineEndings" />
+
+ <!-- Tabs MUST be used for indentation -->
+ <rule ref="Generic.WhiteSpace.DisallowSpaceIndent" />
+
+ <!-- ALL braces MUST be on their own lines. -->
+ <rule ref="./phpbb/Sniffs/ControlStructures/OpeningBraceBsdAllmanSniff.php" />
+
+</ruleset>
diff --git a/build/code_sniffer/ruleset-php-extensions.xml b/build/code_sniffer/ruleset-php-extensions.xml
new file mode 100644
index 0000000000..2d388103c3
--- /dev/null
+++ b/build/code_sniffer/ruleset-php-extensions.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0"?>
+<ruleset name="phpBB PHP Strict Standard Extensions">
+
+ <description>phpBB coding standard for PHP files of phpBB extensions</description>
+
+ <rule ref="./ruleset-php-strict.xml" />
+
+</ruleset>
diff --git a/build/code_sniffer/ruleset-php-legacy-core.xml b/build/code_sniffer/ruleset-php-legacy-core.xml
new file mode 100644
index 0000000000..55f2461a04
--- /dev/null
+++ b/build/code_sniffer/ruleset-php-legacy-core.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0"?>
+<ruleset name="phpBB PHP Legacy Standard Core">
+
+ <description>phpBB legacy coding standard for PHP files of phpBB core</description>
+
+ <rule ref="./ruleset-php-legacy.xml" />
+
+ <!-- Each file MUST start with a valid header as defined by the Coding Guidelines -->
+ <rule ref="./phpbb/Sniffs/Commenting/FileCommentSniff.php" />
+
+</ruleset>
diff --git a/build/code_sniffer/ruleset-php-legacy.xml b/build/code_sniffer/ruleset-php-legacy.xml
new file mode 100644
index 0000000000..c740c6080f
--- /dev/null
+++ b/build/code_sniffer/ruleset-php-legacy.xml
@@ -0,0 +1,92 @@
+<?xml version="1.0"?>
+<ruleset name="phpBB PHP Legacy Standard">
+
+ <description>phpBB legacy coding standard for PHP files</description>
+
+ <rule ref="./ruleset-minimum.xml" />
+
+ <!-- "for (; bar; )" should be "while (bar)" instead -->
+ <rule ref="Generic.CodeAnalysis.ForLoopShouldBeWhileLoop" />
+
+ <!-- A method MUST not only call its parent -->
+ <rule ref="Generic.CodeAnalysis.UselessOverridingMethod" />
+
+ <!-- The body of each structure MUST be enclosed by braces. -->
+ <rule ref="Generic.ControlStructures.InlineControlStructure" />
+
+ <!-- There MUST not be more than one statement per line. -->
+ <rule ref="Generic.Formatting.DisallowMultipleStatements" />
+
+ <!-- Call-time pass-by-reference MUST not be used. -->
+ <rule ref="Generic.Functions.CallTimePassByReference.NotAllowed" />
+
+ <!-- Filenames MUST be lowercase. -->
+ <rule ref="Generic.Files.LowercasedFilename" />
+
+ <!-- The function brace MUST be on the line following the function declaration
+ and MUST be indented to the same column as the start of the function declaration. -->
+ <rule ref="Generic.Functions.OpeningFunctionBraceBsdAllman" />
+
+ <!-- There MUST be exactly one space after a cast. -->
+ <rule ref="Generic.Formatting.SpaceAfterCast" />
+
+ <!-- Class constants MUST be declared in all upper case with underscore separators. -->
+ <rule ref="Generic.NamingConventions.UpperCaseConstantName" />
+
+ <!-- Only <?php, no short tags. -->
+ <rule ref="Generic.PHP.DisallowShortOpenTag.EchoFound" />
+
+ <!-- Method arguments with default values MUST go at the end of the argument list. -->
+ <rule ref="PEAR.Functions.ValidDefaultValue" />
+
+ <!-- Each file MUST end with exactly one newline character -->
+ <rule ref="PSR2.Files.EndFileNewline" />
+
+ <!-- When referencing arrays there MUST NOT be any whitespace around the opening bracket
+ or before the closing bracket. -->
+ <rule ref="Squiz.Arrays.ArrayBracketSpacing" />
+
+ <!-- The "else if" statement MUST be written with a space between the words else and if. -->
+ <rule ref="Squiz.ControlStructures.ElseIfDeclaration" />
+
+ <!-- There MUST be a space between each element of a foreach loop. -->
+ <rule ref="Squiz.ControlStructures.ForEachLoopDeclaration" />
+
+ <!-- In a for loop declaration, there MUST be no space inside the brackets
+ and there MUST be 0 spaces before and 1 space after semicolons. -->
+ <rule ref="Squiz.ControlStructures.ForLoopDeclaration" />
+
+ <!-- In the argument list, there MUST NOT be a space before each comma,
+ and there MUST be one space after each comma. -->
+ <rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing">
+ <properties>
+ <property name="equalsSpacing" value="1"/>
+ </properties>
+ </rule>
+ <rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingAfterHint" />
+
+ <!-- All built-in PHP functions MUST be called lowercased. -->
+ <rule ref="Squiz.Functions.LowercaseFunctionKeywords" />
+
+ <!-- The eval() function MUST NOT be used. -->
+ <rule ref="Squiz.PHP.Eval" />
+
+ <!-- There MUST NOT be trailing whitespace at the end of lines. -->
+ <rule ref="Squiz.WhiteSpace.SuperfluousWhitespace" />
+
+ <!-- There MUST NOT be whitespace before the first content of a file -->
+ <rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.StartFile" />
+
+ <!-- There MUST NOT be whitespace after the last content of a file -->
+ <rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EndFile" />
+
+ <!-- Functions MUST NOT contain multiple empty lines in a row -->
+ <rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EmptyLines" />
+
+ <!-- The ?> closing tag MUST be omitted from files containing only PHP. -->
+ <rule ref="Zend.Files.ClosingTag" />
+
+ <!-- There MUST be one space between control structure and opening parenthesis -->
+ <rule ref="./phpbb/Sniffs/ControlStructures/OpeningParenthesisSniff.php" />
+
+</ruleset>
diff --git a/build/code_sniffer/ruleset-php-strict-core.xml b/build/code_sniffer/ruleset-php-strict-core.xml
new file mode 100644
index 0000000000..5ca4d0cf1e
--- /dev/null
+++ b/build/code_sniffer/ruleset-php-strict-core.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0"?>
+<ruleset name="phpBB PHP Strict Standard Core">
+
+ <description>phpBB coding standard for PHP files of phpBB core</description>
+
+ <rule ref="./ruleset-php-legacy-core.xml" />
+ <rule ref="./ruleset-php-strict.xml" />
+
+</ruleset>
diff --git a/build/code_sniffer/ruleset-php-strict.xml b/build/code_sniffer/ruleset-php-strict.xml
new file mode 100644
index 0000000000..9e2f0664d8
--- /dev/null
+++ b/build/code_sniffer/ruleset-php-strict.xml
@@ -0,0 +1,48 @@
+<?xml version="1.0"?>
+<ruleset name="phpBB PHP Strict Standard">
+
+ <description>phpBB coding standard for PHP files</description>
+
+ <rule ref="./ruleset-php-legacy.xml" />
+
+ <!-- There SHOULD NOT be more than 80 characters per line
+ There MUST NOT be more than 120 characters per line -->
+ <!--
+ <rule ref="Generic.Files.LineLength">
+ <properties>
+ <property name="lineLimit" value="80"/>
+ <property name="absoluteLineLimit" value="120"/>
+ </properties>
+ </rule>
+ -->
+
+ <!-- The PHP constants true, false, and null MUST be in lower case. -->
+ <rule ref="Generic.PHP.LowerCaseConstant" />
+
+ <!-- PHP keywords MUST be in lower case. -->
+ <rule ref="Generic.PHP.LowerCaseKeyword" />
+
+ <!-- Constructors MUST be called __construct() instead of after the class. -->
+ <rule ref="Generic.NamingConventions.ConstructorName" />
+
+ <!-- Classes etc. MUST be namespaced -->
+ <rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace" />
+
+ <!-- A file MUST not contain more than one class/interface -->
+ <rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses" />
+
+ <!-- Files containing classes MUST not have any side-effects -->
+ <rule ref="PSR1.Files.SideEffects.FoundWithSymbols" />
+
+ <!-- When present, all use declarations MUST go after the namespace declaration.
+ There MUST be one use keyword per declaration.
+ There MUST be one blank line after the use block. -->
+ <rule ref="PSR2.Namespaces.UseDeclaration" />
+
+ <!-- There MUST be one blank line after the namespace declaration -->
+ <rule ref="PSR2.Namespaces.NamespaceDeclaration" />
+
+ <!-- There MUST NOT be unused use statements. -->
+ <rule ref="./phpbb/Sniffs/Namespaces/UnusedUseSniff.php" />
+
+</ruleset>