From 80448a1fd83c030302905f2afc4ea5bbec2a68b1 Mon Sep 17 00:00:00 2001 From: Nicolas Giraud Date: Tue, 7 Jan 2014 19:03:20 +0100 Subject: [PATCH 1/2] New phpcs rule for concatenation. Signed-off-by: Hugues Peccatte --- .../Sniffs/Files/SpacesAroundConcatSniff.php | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 PMAStandard/Sniffs/Files/SpacesAroundConcatSniff.php diff --git a/PMAStandard/Sniffs/Files/SpacesAroundConcatSniff.php b/PMAStandard/Sniffs/Files/SpacesAroundConcatSniff.php new file mode 100644 index 0000000000..1d6e276bed --- /dev/null +++ b/PMAStandard/Sniffs/Files/SpacesAroundConcatSniff.php @@ -0,0 +1,82 @@ + + * @since September, the 12th 2013 + */ + +/// {{{ PMAStandard_Sniffs_Files_SpacesAroundConcatSniff +/** + * Sniff to oblige whitespaces before and after a concatenation operator + * + * @category PHP + * @package PHP_CodeSniffer + * @name SpacesAroundConcatSniff + * @author Nicolas Giraud + * @version Release: 1.0 + */ +class PMAStandard_Sniffs_Files_SpacesAroundConcatSniff implements PHP_CodeSniffer_Sniff +{ + + // {{{ register() + + /** + * Returns the token types that this sniff is interested in. + * + * @name register + * @access public + * @see PHP_CodeSniffer_Sniff::register() + * + * @return array(int) + */ + public function register() + { + return array(T_STRING_CONCAT); + + }//end register() + + // }}} + // {{{ process() + + /** + * Processes the tokens that this sniff is interested in. + * + * @name process + * @access public + * @see PHP_CodeSniffer_Sniff::process() + * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. + * @param int $stackPtr The position in the stack where the token was found. + * + * @return void + */ + public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + { + $tokens = $phpcsFile->getTokens(); + if ($tokens[$stackPtr-1]['type'] !== 'T_WHITESPACE') { + $warning = 'Whitespace is expected before any concat operator "."'; + $phpcsFile->addWarning($warning, $stackPtr, 'Found'); + } + if ($tokens[$stackPtr+1]['type'] !== 'T_WHITESPACE') { + $warning = 'Whitespace is expected after any concat operator "."'; + $phpcsFile->addWarning($warning, $stackPtr, 'Found'); + } + }//end process() + + // }}} + +}//end class + +// }}} + +?> From e8ce44761e73bbc05a57601722769bbddbdc9a1d Mon Sep 17 00:00:00 2001 From: Nicolas Giraud Date: Tue, 7 Jan 2014 21:22:55 +0100 Subject: [PATCH 2/2] Remove author. Signed-off-by: Hugues Peccatte --- PMAStandard/Sniffs/Files/SpacesAroundConcatSniff.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/PMAStandard/Sniffs/Files/SpacesAroundConcatSniff.php b/PMAStandard/Sniffs/Files/SpacesAroundConcatSniff.php index 1d6e276bed..c847a60fca 100644 --- a/PMAStandard/Sniffs/Files/SpacesAroundConcatSniff.php +++ b/PMAStandard/Sniffs/Files/SpacesAroundConcatSniff.php @@ -12,7 +12,6 @@ * * @category PHP * @package PHP_CodeSniffer - * @author Nicolas Giraud * @since September, the 12th 2013 */ @@ -23,7 +22,6 @@ * @category PHP * @package PHP_CodeSniffer * @name SpacesAroundConcatSniff - * @author Nicolas Giraud * @version Release: 1.0 */ class PMAStandard_Sniffs_Files_SpacesAroundConcatSniff implements PHP_CodeSniffer_Sniff