File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * Class for a sniff to oblige whitespaces before and after a concatenation operator
5+ *
6+ * This Sniff check if a whitespace is missing before or after any concatenation
7+ * operator.
8+ * The concatenation operator is identified by the PHP token T_STRING_CONCAT
9+ * The whitespace is identified by the PHP token T_WHITESPACE
10+ *
11+ * @since 2.0.2
12+ */
13+ class Yii2_Sniffs_Files_SpacesAroundConcatSniff implements PHP_CodeSniffer_Sniff
14+ {
15+ public function register ()
16+ {
17+ return [T_STRING_CONCAT ];
18+ }
19+
20+ public function process (PHP_CodeSniffer_File $ phpcsFile , $ stackPtr )
21+ {
22+ $ tokens = $ phpcsFile ->getTokens ();
23+
24+ if ($ tokens [$ stackPtr -1 ]['type ' ] !== 'T_WHITESPACE ' ) {
25+ $ error = 'Whitespace is expected before any concat operator "." ' ;
26+ $ fix = $ phpcsFile ->addFixableError ($ error , $ stackPtr , 'NoSpace ' );
27+ if ($ fix === true ) {
28+ $ phpcsFile ->fixer ->addContentBefore ($ stackPtr , ' ' );
29+ }
30+ }
31+ if ($ tokens [$ stackPtr +1 ]['type ' ] !== 'T_WHITESPACE ' ) {
32+ $ error = 'Whitespace is expected after any concat operator "." ' ;
33+ $ fix = $ phpcsFile ->addFixableError ($ error , $ stackPtr , 'NoSpace ' );
34+ if ($ fix === true ) {
35+ $ phpcsFile ->fixer ->addContent ($ stackPtr , ' ' );
36+ }
37+ }
38+ }
39+ }
You can’t perform that action at this time.
0 commit comments