diff options
| author | Andreas Fischer <bantu@phpbb.com> | 2015-06-09 21:27:23 +0200 | 
|---|---|---|
| committer | Andreas Fischer <bantu@phpbb.com> | 2015-06-09 21:27:23 +0200 | 
| commit | 1f4976f5909d9203910f6d2c0953c0231b284963 (patch) | |
| tree | 1fbf120d521b229b83a10c362ff079a58950489d /build/code_sniffer/phpbb/Sniffs/ControlStructures/OpeningParenthesisSniff.php | |
| parent | 00c15c76c30719773dab26949445a143870ddbee (diff) | |
| parent | 1fae4152efd10c3eeb0e5e21d30a109c3ca9a36d (diff) | |
| download | forums-1f4976f5909d9203910f6d2c0953c0231b284963.tar forums-1f4976f5909d9203910f6d2c0953c0231b284963.tar.gz forums-1f4976f5909d9203910f6d2c0953c0231b284963.tar.bz2 forums-1f4976f5909d9203910f6d2c0953c0231b284963.tar.xz forums-1f4976f5909d9203910f6d2c0953c0231b284963.zip  | |
Merge pull request #3696 from marc1706/ticket/13930-master
[ticket/13930] Check for correct spacing between keyword & parenthesis
* marc1706/ticket/13930-master:
  [ticket/13930] Add missing space to mssql_extractor
  [ticket/13930] Add missing spaces to code
  [ticket/13930] Use OpeningParenthesisSniff in legacy ruleset
  [ticket/13930] Remove not needed return statements
  [ticket/13930] Add missing spaces to code
  [ticket/13930] Check for correct spacing between keyword & parenthesis
Diffstat (limited to 'build/code_sniffer/phpbb/Sniffs/ControlStructures/OpeningParenthesisSniff.php')
| -rw-r--r-- | build/code_sniffer/phpbb/Sniffs/ControlStructures/OpeningParenthesisSniff.php | 60 | 
1 files changed, 60 insertions, 0 deletions
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'); +		} +	} +}  | 
