Skip to content

Commit 86fbbac

Browse files
committed
#92 : checkWhiteSpaceBefore {, unless it's in
1 parent c4ea75c commit 86fbbac

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

src/PHPCheckstyle/PHPCheckstyle.php

+40-4
Original file line numberDiff line numberDiff line change
@@ -1171,9 +1171,10 @@ private function _processToken($token) {
11711171
break;
11721172

11731173
case T_BRACES_OPEN: // {
1174-
$this->_processBracesOpen($token);
1174+
if (!$this->_checkComplexVariable2($token)) {
1175+
$this->_processBracesOpen($token);
1176+
}
11751177
break;
1176-
11771178
case T_BRACES_CLOSE: // }
11781179
$this->_processBracesClose($token);
11791180
break;
@@ -1234,8 +1235,9 @@ private function _processToken($token) {
12341235
$this->_inString = !$this->_inString;
12351236
break;
12361237
case T_DOLLAR:
1237-
$this->_checkComplexVariable($token);
1238-
$this->_checkVariableVariable($token);
1238+
if (!$this->_checkComplexVariable($token)) {
1239+
$this->_checkVariableVariable($token);
1240+
}
12391241
break;
12401242
case T_ARRAY:
12411243
$this->_processArray($token);
@@ -3747,8 +3749,42 @@ private function _checkComplexVariable($token) {
37473749

37483750
// Skip the analysis of the content of the variable.
37493751
$this->tokenizer->setCurrentPosition($closePos + 1);
3752+
3753+
return true;
37503754
}
37513755
}
3756+
3757+
return false;
3758+
}
3759+
3760+
/**
3761+
* Check the use of a complex variable {$.
3762+
*
3763+
* Skip the analysis inside the variable.
3764+
* Should be the token T_CURLY_OPEN but can also be T_BRACES_OPEN + T_DOLLAR
3765+
*
3766+
* Called when the current token is a single {.
3767+
*
3768+
* @param TokenInfo $token
3769+
*/
3770+
private function _checkComplexVariable2($token) {
3771+
3772+
// Right after the { there is a $ with no space between
3773+
if ($this->tokenizer->checkNextToken(T_DOLLAR) || ($this->tokenizer->checkNextToken(T_VARIABLE))) {
3774+
3775+
// Detect the end of the complexe variable
3776+
$closePos = $this->tokenizer->findNextTokenPosition(T_BRACES_CLOSE);
3777+
3778+
if ($closePos !== null) {
3779+
3780+
// Skip the analysis of the content of the variable.
3781+
$this->tokenizer->setCurrentPosition($closePos + 1);
3782+
3783+
return true;
3784+
}
3785+
}
3786+
3787+
return false;
37523788
}
37533789

37543790
/**

test/sample/good_unused.php

-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ function testUnused() {
2020
$a = 2;
2121
$result = $a + $this->toto;
2222

23-
echo ${$a}; // This should not generate a warning
24-
2523
return $result;
2624

2725
}

0 commit comments

Comments
 (0)