From 32a2c95f903cbbfad909945887a1cbabd84d5039 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 20 Jun 2014 15:02:08 +0200 Subject: [PATCH 1/6] [ticket/12723] Add Sniff ensuring PHP files use the correct file header PHPBB3-12723 --- build/build.xml | 4 +- .../Sniffs/Commenting/FileCommentSniff.php | 220 +++++++++--------- .../Tests/Commenting/FileCommentUnitTest.inc | 19 -- .../Tests/Commenting/FileCommentUnitTest.php | 54 ----- build/code_sniffer/phpbb/build.xml | 23 -- .../phpbb/phpbbCodingStandard.php | 46 ---- .../code_sniffer/ruleset-phpbb-php-legacy.xml | 13 ++ .../code_sniffer/ruleset-phpbb-php-strict.xml | 9 + phpBB/includes/acp/acp_contact.php | 11 +- phpBB/includes/acp/info/acp_contact.php | 10 +- phpBB/install/phpinfo.php | 11 + phpBB/language/en/plupload.php | 2 +- phpBB/phpbb/console/command/cron/run.php | 2 +- .../data/v310/contact_admin_acp_module.php | 10 +- .../data/v310/contact_admin_form.php | 10 +- phpBB/phpbb/message/admin_form.php | 12 +- phpBB/phpbb/message/form.php | 12 +- phpBB/phpbb/message/message.php | 12 +- phpBB/phpbb/message/topic_form.php | 12 +- phpBB/phpbb/message/user_form.php | 12 +- 20 files changed, 216 insertions(+), 288 deletions(-) delete mode 100644 build/code_sniffer/phpbb/Tests/Commenting/FileCommentUnitTest.inc delete mode 100644 build/code_sniffer/phpbb/Tests/Commenting/FileCommentUnitTest.php delete mode 100644 build/code_sniffer/phpbb/build.xml delete mode 100644 build/code_sniffer/phpbb/phpbbCodingStandard.php create mode 100644 build/code_sniffer/ruleset-phpbb-php-legacy.xml create mode 100644 build/code_sniffer/ruleset-phpbb-php-strict.xml diff --git a/build/build.xml b/build/build.xml index 510e7d0955..455a99fb1d 100644 --- a/build/build.xml +++ b/build/build.xml @@ -77,14 +77,14 @@ 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) 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 '; + + 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/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 @@ - - -* @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 -*/ -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 @@ - - - - - - - - - - - - - - - - - - - - - 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 @@ - -* @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-phpbb-php-legacy.xml b/build/code_sniffer/ruleset-phpbb-php-legacy.xml new file mode 100644 index 0000000000..9f11ce290e --- /dev/null +++ b/build/code_sniffer/ruleset-phpbb-php-legacy.xml @@ -0,0 +1,13 @@ + + + + phpBB legacy coding standard for PHP files + + + + + + + diff --git a/build/code_sniffer/ruleset-phpbb-php-strict.xml b/build/code_sniffer/ruleset-phpbb-php-strict.xml new file mode 100644 index 0000000000..6da9297099 --- /dev/null +++ b/build/code_sniffer/ruleset-phpbb-php-strict.xml @@ -0,0 +1,9 @@ + + + + phpBB legacy coding standard for PHP files + + + + + diff --git a/phpBB/includes/acp/acp_contact.php b/phpBB/includes/acp/acp_contact.php index 13d38d9f29..4e46df21e0 100644 --- a/phpBB/includes/acp/acp_contact.php +++ b/phpBB/includes/acp/acp_contact.php @@ -1,9 +1,14 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* */ /** diff --git a/phpBB/includes/acp/info/acp_contact.php b/phpBB/includes/acp/info/acp_contact.php index b8326f34ea..548eb52816 100644 --- a/phpBB/includes/acp/info/acp_contact.php +++ b/phpBB/includes/acp/info/acp_contact.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/phpBB/install/phpinfo.php b/phpBB/install/phpinfo.php index 83f154933a..1512b00563 100644 --- a/phpBB/install/phpinfo.php +++ b/phpBB/install/phpinfo.php @@ -1,3 +1,14 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ phpinfo(); diff --git a/phpBB/language/en/plupload.php b/phpBB/language/en/plupload.php index c4a8d770a0..15c3955a1a 100644 --- a/phpBB/language/en/plupload.php +++ b/phpBB/language/en/plupload.php @@ -3,8 +3,8 @@ * * This file is part of the phpBB Forum Software package. * -* @copyright (c) 2010-2013 Moxiecode Systems AB * @copyright (c) phpBB Limited +* @copyright (c) 2010-2013 Moxiecode Systems AB * @license GNU General Public License, version 2 (GPL-2.0) * * For full copyright and license information, please see diff --git a/phpBB/phpbb/console/command/cron/run.php b/phpBB/phpbb/console/command/cron/run.php index 32774bebe4..0b365ece67 100644 --- a/phpBB/phpbb/console/command/cron/run.php +++ b/phpBB/phpbb/console/command/cron/run.php @@ -3,7 +3,7 @@ * * This file is part of the phpBB Forum Software package. * -* @copyright (c) phpBB Limited +* @copyright (c) phpBB Limited * @license GNU General Public License, version 2 (GPL-2.0) * * For full copyright and license information, please see diff --git a/phpBB/phpbb/db/migration/data/v310/contact_admin_acp_module.php b/phpBB/phpbb/db/migration/data/v310/contact_admin_acp_module.php index bd682e2f7c..20bd547ac3 100644 --- a/phpBB/phpbb/db/migration/data/v310/contact_admin_acp_module.php +++ b/phpBB/phpbb/db/migration/data/v310/contact_admin_acp_module.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/phpBB/phpbb/db/migration/data/v310/contact_admin_form.php b/phpBB/phpbb/db/migration/data/v310/contact_admin_form.php index e255efb99d..c2dd09ddf6 100644 --- a/phpBB/phpbb/db/migration/data/v310/contact_admin_form.php +++ b/phpBB/phpbb/db/migration/data/v310/contact_admin_form.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/phpBB/phpbb/message/admin_form.php b/phpBB/phpbb/message/admin_form.php index b71b3fc535..93db59880c 100644 --- a/phpBB/phpbb/message/admin_form.php +++ b/phpBB/phpbb/message/admin_form.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ @@ -12,8 +16,6 @@ namespace phpbb\message; /** * Class admin_form * Displays a message to the user and allows him to send an email -* -* @package phpbb\message */ class admin_form extends form { diff --git a/phpBB/phpbb/message/form.php b/phpBB/phpbb/message/form.php index d7a42c4080..076b41dc07 100644 --- a/phpBB/phpbb/message/form.php +++ b/phpBB/phpbb/message/form.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ @@ -11,8 +15,6 @@ namespace phpbb\message; /** * Abstract class form -* -* @package phpbb\message */ abstract class form { diff --git a/phpBB/phpbb/message/message.php b/phpBB/phpbb/message/message.php index 7ba2b2f32d..5fd24b542e 100644 --- a/phpBB/phpbb/message/message.php +++ b/phpBB/phpbb/message/message.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ @@ -12,8 +16,6 @@ namespace phpbb\message; /** * Class message * Holds all information for an email and sends it in the end -* -* @package phpbb\message */ class message { diff --git a/phpBB/phpbb/message/topic_form.php b/phpBB/phpbb/message/topic_form.php index 3a35c35d21..1e0f2a1945 100644 --- a/phpBB/phpbb/message/topic_form.php +++ b/phpBB/phpbb/message/topic_form.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ @@ -12,8 +16,6 @@ namespace phpbb\message; /** * Class topic_form * Form used to send topics as notification emails -* -* @package phpbb\message */ class topic_form extends form { diff --git a/phpBB/phpbb/message/user_form.php b/phpBB/phpbb/message/user_form.php index 7aa4b94def..007e575407 100644 --- a/phpBB/phpbb/message/user_form.php +++ b/phpBB/phpbb/message/user_form.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ @@ -12,8 +16,6 @@ namespace phpbb\message; /** * Class user_form * Allows users to send emails to other users -* -* @package phpbb\message */ class user_form extends form { From e7c6da2c5426a6eaff1a5d572b2b432407eb0dc2 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 22 Jun 2014 01:19:02 +0200 Subject: [PATCH 2/6] [ticket/12723] Use core suffix in filename instead of phpbb in the middle. PHPBB3-12723 --- build/build.xml | 4 ++-- ...leset-phpbb-php-legacy.xml => ruleset-php-legacy-core.xml} | 0 ...leset-phpbb-php-strict.xml => ruleset-php-strict-core.xml} | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename build/code_sniffer/{ruleset-phpbb-php-legacy.xml => ruleset-php-legacy-core.xml} (100%) rename build/code_sniffer/{ruleset-phpbb-php-strict.xml => ruleset-php-strict-core.xml} (80%) diff --git a/build/build.xml b/build/build.xml index 455a99fb1d..9a66853b98 100644 --- a/build/build.xml +++ b/build/build.xml @@ -77,14 +77,14 @@ + From 82c43e258bb7a78f4f17c04ca46d02ea311a077a Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 22 Jun 2014 01:20:49 +0200 Subject: [PATCH 3/6] [ticket/12723] Properly describe new Code Sniffer rulsets. PHPBB3-12723 --- build/code_sniffer/ruleset-php-legacy-core.xml | 4 ++-- build/code_sniffer/ruleset-php-strict-core.xml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build/code_sniffer/ruleset-php-legacy-core.xml b/build/code_sniffer/ruleset-php-legacy-core.xml index 9f11ce290e..a093309a01 100644 --- a/build/code_sniffer/ruleset-php-legacy-core.xml +++ b/build/code_sniffer/ruleset-php-legacy-core.xml @@ -1,7 +1,7 @@ - + - phpBB legacy coding standard for PHP files + phpBB legacy coding standard for PHP files of phpBB core diff --git a/build/code_sniffer/ruleset-php-strict-core.xml b/build/code_sniffer/ruleset-php-strict-core.xml index b60a365ec9..5ca4d0cf1e 100644 --- a/build/code_sniffer/ruleset-php-strict-core.xml +++ b/build/code_sniffer/ruleset-php-strict-core.xml @@ -1,7 +1,7 @@ - + - phpBB legacy coding standard for PHP files + phpBB coding standard for PHP files of phpBB core From 900a5b07c4579fde8353660d1bc605d4749b631e Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 22 Jun 2014 01:28:29 +0200 Subject: [PATCH 4/6] [ticket/12757] Add a Code Sniffer ruleset for PHP files of phpBB extensions PHPBB3-12757 --- build/build.xml | 8 ++++++++ build/code_sniffer/ruleset-php-extensions.xml | 8 ++++++++ 2 files changed, 16 insertions(+) create mode 100644 build/code_sniffer/ruleset-php-extensions.xml diff --git a/build/build.xml b/build/build.xml index 9a66853b98..5354b5d48c 100644 --- a/build/build.xml +++ b/build/build.xml @@ -87,6 +87,7 @@ --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/* @@ -96,10 +97,17 @@ --ignore=${project.basedir}/phpBB/vendor/* phpBB" dir="." returnProperty="retval-php-legacy" passthru="true" /> + + 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 @@ + + + + phpBB coding standard for PHP files of phpBB extensions + + + + From e10bf39d08cd3f613296698cbf7b00536f15e8db Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 22 Jun 2014 01:42:43 +0200 Subject: [PATCH 5/6] [ticket/12723] Do not reference the coding guidelines section. PHPBB3-12723 --- .../phpbb/Sniffs/Commenting/FileCommentSniff.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/build/code_sniffer/phpbb/Sniffs/Commenting/FileCommentSniff.php b/build/code_sniffer/phpbb/Sniffs/Commenting/FileCommentSniff.php index 1f64467d00..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 From ddb35531ac0c6bba1505f2f84f0010239feea3d7 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 22 Jun 2014 01:47:22 +0200 Subject: [PATCH 6/6] [ticket/12723] Do not mention too many details on documentation. PHPBB3-12723 --- build/build.xml | 1 + build/code_sniffer/ruleset-php-legacy-core.xml | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/build/build.xml b/build/build.xml index 5354b5d48c..d3489ab607 100644 --- a/build/build.xml +++ b/build/build.xml @@ -101,6 +101,7 @@ -s --extensions=php --standard=build/code_sniffer/ruleset-php-extensions.xml + --ignore=${project.basedir}/phpBB/ext/*/tests/* phpBB/ext" dir="." returnProperty="retval-php-ext" passthru="true" /> diff --git a/build/code_sniffer/ruleset-php-legacy-core.xml b/build/code_sniffer/ruleset-php-legacy-core.xml index a093309a01..55f2461a04 100644 --- a/build/code_sniffer/ruleset-php-legacy-core.xml +++ b/build/code_sniffer/ruleset-php-legacy-core.xml @@ -5,9 +5,7 @@ - +