@@ -88,36 +88,42 @@ public function process(File $phpcsFile, $stackPtr)
88
88
return ;
89
89
}
90
90
91
- if (isset (Tokens::$ stringTokens [$ tokens [$ prev ]['code ' ]]) === true
92
- && isset (Tokens::$ stringTokens [$ tokens [$ next ]['code ' ]]) === true
91
+ if (isset (Tokens::$ stringTokens [$ tokens [$ prev ]['code ' ]]) === false
92
+ || isset (Tokens::$ stringTokens [$ tokens [$ next ]['code ' ]]) === false
93
93
) {
94
- if ($ tokens [$ prev ]['content ' ][0 ] === $ tokens [$ next ]['content ' ][0 ]) {
95
- // Before we throw an error for PHP, allow strings to be
96
- // combined if they would have < and ? next to each other because
97
- // this trick is sometimes required in PHP strings.
98
- if ($ phpcsFile ->tokenizerType === 'PHP ' ) {
99
- $ prevChar = substr ($ tokens [$ prev ]['content ' ], -2 , 1 );
100
- $ nextChar = $ tokens [$ next ]['content ' ][1 ];
101
- $ combined = $ prevChar .$ nextChar ;
102
- if ($ combined === '? ' .'> ' || $ combined === '< ' .'? ' ) {
103
- return ;
104
- }
105
- }
106
-
107
- if ($ this ->allowMultiline === true
108
- && $ tokens [$ prev ]['line ' ] !== $ tokens [$ next ]['line ' ]
109
- ) {
110
- return ;
111
- }
112
-
113
- $ error = 'String concat is not required here; use a single string instead ' ;
114
- if ($ this ->error === true ) {
115
- $ phpcsFile ->addError ($ error , $ stackPtr , 'Found ' );
116
- } else {
117
- $ phpcsFile ->addWarning ($ error , $ stackPtr , 'Found ' );
118
- }
119
- }//end if
120
- }//end if
94
+ // Bow out as at least one of the two tokens being concatenated is not a string.
95
+ return ;
96
+ }
97
+
98
+ if ($ tokens [$ prev ]['content ' ][0 ] !== $ tokens [$ next ]['content ' ][0 ]) {
99
+ // Bow out as the two strings are not of the same type.
100
+ return ;
101
+ }
102
+
103
+ // Before we throw an error for PHP, allow strings to be
104
+ // combined if they would have < and ? next to each other because
105
+ // this trick is sometimes required in PHP strings.
106
+ if ($ phpcsFile ->tokenizerType === 'PHP ' ) {
107
+ $ prevChar = substr ($ tokens [$ prev ]['content ' ], -2 , 1 );
108
+ $ nextChar = $ tokens [$ next ]['content ' ][1 ];
109
+ $ combined = $ prevChar .$ nextChar ;
110
+ if ($ combined === '? ' .'> ' || $ combined === '< ' .'? ' ) {
111
+ return ;
112
+ }
113
+ }
114
+
115
+ if ($ this ->allowMultiline === true
116
+ && $ tokens [$ prev ]['line ' ] !== $ tokens [$ next ]['line ' ]
117
+ ) {
118
+ return ;
119
+ }
120
+
121
+ $ error = 'String concat is not required here; use a single string instead ' ;
122
+ if ($ this ->error === true ) {
123
+ $ phpcsFile ->addError ($ error , $ stackPtr , 'Found ' );
124
+ } else {
125
+ $ phpcsFile ->addWarning ($ error , $ stackPtr , 'Found ' );
126
+ }
121
127
122
128
}//end process()
123
129
0 commit comments