diff options
Diffstat (limited to 'build/code_sniffer')
-rw-r--r-- | build/code_sniffer/phpbb/Sniffs/Commenting/FileCommentSniff.php | 225 | ||||
-rw-r--r-- | build/code_sniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php | 209 | ||||
-rw-r--r-- | build/code_sniffer/phpbb/Tests/Commenting/FileCommentUnitTest.inc | 19 | ||||
-rw-r--r-- | build/code_sniffer/phpbb/Tests/Commenting/FileCommentUnitTest.php | 54 | ||||
-rw-r--r-- | build/code_sniffer/phpbb/build.xml | 23 | ||||
-rw-r--r-- | build/code_sniffer/phpbb/phpbbCodingStandard.php | 46 | ||||
-rw-r--r-- | build/code_sniffer/ruleset-php-extensions.xml | 8 | ||||
-rw-r--r-- | build/code_sniffer/ruleset-php-legacy-core.xml | 11 | ||||
-rw-r--r-- | build/code_sniffer/ruleset-php-legacy.xml | 30 | ||||
-rw-r--r-- | build/code_sniffer/ruleset-php-strict-core.xml | 9 | ||||
-rw-r--r-- | build/code_sniffer/ruleset-php-strict.xml | 9 |
11 files changed, 393 insertions, 250 deletions
diff --git a/build/code_sniffer/phpbb/Sniffs/Commenting/FileCommentSniff.php b/build/code_sniffer/phpbb/Sniffs/Commenting/FileCommentSniff.php index fcf53b5061..fa7d3b40c1 100644 --- a/build/code_sniffer/phpbb/Sniffs/Commenting/FileCommentSniff.php +++ b/build/code_sniffer/phpbb/Sniffs/Commenting/FileCommentSniff.php @@ -12,9 +12,8 @@ */ /** -* Checks that each source file contains the standard header. -* -* Based on Coding Guidelines 1.ii File Header. +* 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> @@ -47,10 +46,10 @@ class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff { if ($phpcsFile->findPrevious(T_OPEN_TAG, $stackPtr - 1) !== false) { - return; + return; } } - + // Fetch next non whitespace token $tokens = $phpcsFile->getTokens(); $start = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, null, true); @@ -66,65 +65,68 @@ class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff $phpcsFile->addError('Missing required file doc comment.', $stackPtr); return; } - + // Find comment end token $end = $phpcsFile->findNext(T_DOC_COMMENT, $start + 1, null, true) - 1; - + // If there is no end, skip processing here if ($end === false) { return; } - + // List of found comment tags $tags = array(); - + // check comment lines without the first(/**) an last(*/) line - for ($i = $start + 1, $c = ($end - $start); $i <= $c; ++$i) + for ($i = $start + 1, $c = $end - 1; $i <= $c; ++$i) { $line = $tokens[$i]['content']; // Check that each line starts with a '*' if (substr($line, 0, 1) !== '*') { - $message = 'The file doc comment should not be idented.'; + $message = 'The file doc comment should not be idented.'; $phpcsFile->addWarning($message, $i); } else if (preg_match('/^\*\s+@([\w]+)\s+(.*)$/', $line, $match) !== 0) { - $tags[$match[1]] = array($match[2], $i); + if (!isset($tags[$match[1]])) + { + $tags[$match[1]] = array(); + } + + $tags[$match[1]][] = array($match[2], $i); } } - + // Check that the first and last line is empty if (trim($tokens[$start + 1]['content']) !== '*') { $message = 'The first file comment line should be empty.'; - $phpcsFile->addWarning($message, ($start + 1)); - } - if (trim($tokens[$end - $start]['content']) !== '*') - { - $message = 'The last file comment line should be empty.'; - $phpcsFile->addWarning($message, ($end - $start)); - } - - $this->processPackage($phpcsFile, $start, $tags); - $this->processVersion($phpcsFile, $start, $tags); - $this->processCopyright($phpcsFile, $start, $tags); - $this->processLicense($phpcsFile, $start, $tags); - - //print_r($tags); + $phpcsFile->addWarning($message, ($start + 1)); + } + if (trim($tokens[$end - 1]['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, $tags); + $this->processLicense($phpcsFile, $start, $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 - */ + * 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'])) @@ -134,80 +136,87 @@ class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff } else if (preg_match('/^([\w]+)$/', $tags['package'][0]) === 0) { - $message = 'Invalid content found for @package tag.'; - $phpcsFile->addWarning($message, $tags['package'][1]); + $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 - */ + * 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) - { - if (!isset($tags['copyright'])) - { - $message = 'Missing require @copyright tag in file doc comment.'; - $phpcsFile->addError($message, $ptr); - } - else if (preg_match('/^\(c\) 2[0-9]{3} phpBB Group\s*$/', $tags['copyright'][0]) === 0) - { - $message = 'Invalid content found for @copyright tag, use "(c) <year> phpBB Group".'; - $phpcsFile->addError($message, $tags['copyright'][1]); - } - } - - /** - * 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 = 'http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2'; - - if (!isset($tags['license'])) - { - $message = 'Missing require @license tag in file doc comment.'; - $phpcsFile->addError($message, $ptr); - } - else if (trim($tags['license'][0]) !== $license) - { - $message = 'Invalid content found for @license tag, use ' - . '"' . $license . '".'; - $phpcsFile->addError($message, $tags['license'][1]); - } - } + { + 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>'; + + if (!isset($tags['copyright'])) + { + $message = 'Missing require @copyright tag in file doc comment.'; + $phpcsFile->addError($message, $ptr); + } + else if ($tags['copyright'][0][0] !== $copyright) + { + $message = 'Invalid content found for the first @copyright tag, use "' . $copyright . '".'; + $phpcsFile->addError($message, $tags['copyright'][0][1]); + } + } + + /** + * 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)'; + + if (!isset($tags['license'])) + { + $message = 'Missing require @license tag in file doc comment.'; + $phpcsFile->addError($message, $ptr); + } + else if (sizeof($tags['license']) !== 1) + { + $message = 'It must be only one @license tag in file doc comment.'; + $phpcsFile->addError($message, $ptr); + } + else if (trim($tags['license'][0][0]) !== $license) + { + $message = 'Invalid content found for @license tag, use ' + . '"' . $license . '".'; + $phpcsFile->addError($message, $tags['license'][0][1]); + } + } } 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..16e3427bd9 --- /dev/null +++ b/build/code_sniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php @@ -0,0 +1,209 @@ +<?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); + } + + /** + * {@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))); + + if ($simple_class_name === $class_name_full) + { + $error = 'Either use statement or full name must be used.'; + $phpcsFile->addError($error, $simple_statement, 'FullName'); + } + + if ($simple_class_name === $class_name_short) + { + $ok = true; + } + } + } + + // 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))); + + if ($paamayim_nekudotayim_class_name === $class_name_full) + { + $error = 'Either use statement or full name must be used.'; + $phpcsFile->addError($error, $paamayim_nekudotayim, 'FullName'); + } + + if ($paamayim_nekudotayim_class_name === $class_name_short) + { + $ok = true; + } + } + + // 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))); + + if ($implements_class_name === $class_name_full) + { + $error = 'Either use statement or full name must be used.'; + $phpcsFile->addError($error, $implements, 'FullName'); + } + + if ($implements_class_name === $class_name_short) + { + $ok = true; + } + } + } + + // 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; + + $end_function = $phpcsFile->findNext(array(T_CLOSE_PARENTHESIS), ($function_declaration + 1)); + $old_argument = $function_declaration; + while (($argument = $phpcsFile->findNext(T_VARIABLE, ($old_argument + 1), $end_function)) !== false) + { + $old_argument = $argument; + + $start_argument = $phpcsFile->findPrevious(array(T_OPEN_PARENTHESIS, T_COMMA), $argument); + $argument_class_name_start = $phpcsFile->findNext(array(T_NS_SEPARATOR, T_STRING), ($start_argument + 1), $argument); + $argument_class_name_end = $phpcsFile->findNext($find, ($argument_class_name_start + 1), null, true); + + $argument_class_name = $phpcsFile->getTokensAsString($argument_class_name_start, ($argument_class_name_end - $argument_class_name_start - 1)); + + if ($argument_class_name === $class_name_full) + { + $error = 'Either use statement or full name must be used.'; + $phpcsFile->addError($error, $function_declaration, 'FullName'); + } + + if ($argument_class_name === $class_name_short) + { + $ok = true; + } + } + } + + 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; + + } +} diff --git a/build/code_sniffer/phpbb/Tests/Commenting/FileCommentUnitTest.inc b/build/code_sniffer/phpbb/Tests/Commenting/FileCommentUnitTest.inc deleted file mode 100644 index 0ace1c1bda..0000000000 --- a/build/code_sniffer/phpbb/Tests/Commenting/FileCommentUnitTest.inc +++ /dev/null @@ -1,19 +0,0 @@ -<?php -/** -* -* @package code_sniffer³ -* @version $Id: $ -* @copyright (c) 2008 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php BSD License - * -*/ -?> -<?php -/** -* Broken but not first file doc comment. -* -* @version @package_version@ -* @license http://www.opensource.org/licenses/bsd-license.php BSD License -* @copyright (c) 2007 phpBB Group -* -*/ diff --git a/build/code_sniffer/phpbb/Tests/Commenting/FileCommentUnitTest.php b/build/code_sniffer/phpbb/Tests/Commenting/FileCommentUnitTest.php deleted file mode 100644 index 23aaa45bd3..0000000000 --- a/build/code_sniffer/phpbb/Tests/Commenting/FileCommentUnitTest.php +++ /dev/null @@ -1,54 +0,0 @@ -<?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. -* -*/ - -/** -* Unit test class for the EmptyStatement sniff. -* -* @package code_sniffer -* @author Manuel Pichler <mapi@phpundercontrol.org> -*/ -class phpbb_Tests_Commenting_FileCommentUnitTest extends AbstractSniffUnitTest -{ - - /** - * Returns the lines where errors should occur. - * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) - */ - public function getErrorList() - { - return array( - 7 => 1 // BSD License error :) - ); - }//end getErrorList() - - - /** - * Returns the lines where warnings should occur. - * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) - */ - public function getWarningList() - { - return array( - 4 => 1, - 8 => 1 - ); - }//end getWarningList() -} diff --git a/build/code_sniffer/phpbb/build.xml b/build/code_sniffer/phpbb/build.xml deleted file mode 100644 index b6d3bf6451..0000000000 --- a/build/code_sniffer/phpbb/build.xml +++ /dev/null @@ -1,23 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project name="code_sniffer" basedir="." default="install"> - - <property name="working.dir" value="${basedir}" /> - <property name="target.dir" value="/usr/share/php/PHP/CodeSniffer/Standards" /> - - <!-- - Install phpbb sniff - --> - <target name="install"> - <delete dir="${target.dir}/phpbb" /> - <mkdir dir="${target.dir}/phpbb"/> - - <copy todir="${target.dir}/phpbb"> - <fileset file="${working.dir}/phpbbCodingStandard.php" /> - </copy> - <copy todir="${target.dir}/phpbb/Sniffs"> - <fileset dir="${working.dir}/Sniffs" /> - </copy> - - </target> - -</project> diff --git a/build/code_sniffer/phpbb/phpbbCodingStandard.php b/build/code_sniffer/phpbb/phpbbCodingStandard.php deleted file mode 100644 index b94186ab6c..0000000000 --- a/build/code_sniffer/phpbb/phpbbCodingStandard.php +++ /dev/null @@ -1,46 +0,0 @@ -<?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. -* -*/ - -/** - * @ignore - */ -if (class_exists('PHP_CodeSniffer_Standards_CodingStandard', true) === false) { - throw new PHP_CodeSniffer_Exception( - 'Class PHP_CodeSniffer_Standards_CodingStandard not found' - ); -} - -/** - * Primary class for the phpbb coding standard. - * - * @package code_sniffer - */ -class PHP_CodeSniffer_Standards_phpbb_phpbbCodingStandard extends PHP_CodeSniffer_Standards_CodingStandard -{ - /** - * Return a list of external sniffs to include with this standard. - * - * External locations can be single sniffs, a whole directory of sniffs, or - * an entire coding standard. Locations start with the standard name. For - * example: - * PEAR => include all sniffs in this standard - * PEAR/Sniffs/Files => include all sniffs in this dir - * PEAR/Sniffs/Files/LineLengthSniff => include this single sniff - * - * @return array - */ - public function getIncludedSniffs() - { - return array(); - } -} 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 index 65eb0a8622..b0110e8b12 100644 --- a/build/code_sniffer/ruleset-php-legacy.xml +++ b/build/code_sniffer/ruleset-php-legacy.xml @@ -20,6 +20,16 @@ <!-- 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" /> @@ -32,6 +42,20 @@ <!-- 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"> @@ -41,6 +65,12 @@ </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" /> 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 index f2d5b86dd1..9e2f0664d8 100644 --- a/build/code_sniffer/ruleset-php-strict.xml +++ b/build/code_sniffer/ruleset-php-strict.xml @@ -22,6 +22,9 @@ <!-- 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" /> @@ -36,4 +39,10 @@ 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> |