Skip to content

Commit 0b4f97e

Browse files
committed
Generic/UnnecessaryStringConcat: simplify condition
This commit simplifies a condition and improves code readability by reducing its nesting level. It also adds code comments, making the reason for each of the two remaining checks explicit.
1 parent c45549d commit 0b4f97e

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/Standards/Generic/Sniffs/Strings/UnnecessaryStringConcatSniff.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,14 @@ public function register()
7070
*/
7171
public function process(File $phpcsFile, $stackPtr)
7272
{
73-
// Work out which type of file this is for.
7473
$tokens = $phpcsFile->getTokens();
75-
if ($tokens[$stackPtr]['code'] === T_STRING_CONCAT) {
76-
if ($phpcsFile->tokenizerType === 'JS') {
77-
return;
78-
}
79-
} else {
80-
if ($phpcsFile->tokenizerType === 'PHP') {
81-
return;
82-
}
74+
75+
if ($tokens[$stackPtr]['code'] === T_STRING_CONCAT && $phpcsFile->tokenizerType === 'JS') {
76+
// JS uses T_PLUS for string concatenation, not T_STRING_CONCAT.
77+
return;
78+
} else if ($tokens[$stackPtr]['code'] === T_PLUS && $phpcsFile->tokenizerType === 'PHP') {
79+
// PHP uses T_STRING_CONCAT for string concatenation, not T_PLUS.
80+
return;
8381
}
8482

8583
$prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);

0 commit comments

Comments
 (0)