Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/Tokenizers/PHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -3212,7 +3212,17 @@ protected function processAdditional()
}

if ($suspectedType === 'return' && $this->tokens[$x]['code'] === T_COLON) {
$confirmed = true;
// Make sure this is not the colon from a parameter name.
for ($y = ($x - 1); $y > 0; $y--) {
if (isset(Tokens::$emptyTokens[$this->tokens[$y]['code']]) === false) {
break;
}
}

if ($this->tokens[$y]['code'] !== T_PARAM_NAME) {
$confirmed = true;
}

break;
}

Expand Down
8 changes: 8 additions & 0 deletions tests/Core/Tokenizer/PHP/DNFTypesTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ list(&$a, &$b) = $array;
/* testParensNoOwnerFunctionCallwithDNFLookALikeParam */
$obj->static((CONST_A&CONST_B)|CONST_C | $var);

/* testParensNoOwnerFunctionCallWithDNFLookALikeNamedParamPlain */
callMe(label: false);

/* testParensNoOwnerFunctionCallWithDNFLookALikeNamedParamUnion */
callMe(label: CONST_A | CONST_B);

/* testParensNoOwnerFunctionCallWithDNFLookALikeNamedParamIntersect */
callMe(label: CONST_A & CONST_B);

/*
* DNF parentheses.
Expand Down
27 changes: 22 additions & 5 deletions tests/Core/Tokenizer/PHP/DNFTypesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,19 @@ public function testNormalParentheses($testMarker, $skipCheckInside=false)
$this->assertSame(T_CLOSE_PARENTHESIS, $closer['code'], 'Token tokenized as '.$closer['type'].', not T_CLOSE_PARENTHESIS (code)');
$this->assertSame('T_CLOSE_PARENTHESIS', $closer['type'], 'Token tokenized as '.$closer['type'].', not T_CLOSE_PARENTHESIS (type)');

for ($i = ($openPtr + 1); $i < $closePtr; $i++) {
// If there are ampersands, make sure these are tokenized as bitwise and.
if ($skipCheckInside === false && $tokens[$i]['content'] === '&') {
$this->assertSame(T_BITWISE_AND, $tokens[$i]['code'], 'Token tokenized as '.$tokens[$i]['type'].', not T_BITWISE_AND (code)');
$this->assertSame('T_BITWISE_AND', $tokens[$i]['type'], 'Token tokenized as '.$tokens[$i]['type'].', not T_BITWISE_AND (type)');
if ($skipCheckInside === false) {
for ($i = ($openPtr + 1); $i < $closePtr; $i++) {
// If there are ampersands, make sure these are tokenized as bitwise and.
if ($tokens[$i]['content'] === '&') {
$this->assertSame(T_BITWISE_AND, $tokens[$i]['code'], 'Token tokenized as '.$tokens[$i]['type'].', not T_BITWISE_AND (code)');
$this->assertSame('T_BITWISE_AND', $tokens[$i]['type'], 'Token tokenized as '.$tokens[$i]['type'].', not T_BITWISE_AND (type)');
}

// If there are pipes, make sure these are tokenized as bitwise or.
if ($tokens[$i]['content'] === '|') {
$this->assertSame(T_BITWISE_OR, $tokens[$i]['code'], 'Token tokenized as '.$tokens[$i]['type'].', not T_BITWISE_OR (code)');
$this->assertSame('T_BITWISE_OR', $tokens[$i]['type'], 'Token tokenized as '.$tokens[$i]['type'].', not T_BITWISE_OR (type)');
}
}
}

Expand Down Expand Up @@ -141,6 +149,15 @@ public static function dataNormalParentheses()
'parens without owner, function call with DNF look-a-like param' => [
'testMarker' => '/* testParensNoOwnerFunctionCallwithDNFLookALikeParam */',
],
'parens without owner, function call, named param' => [
'testMarker' => '/* testParensNoOwnerFunctionCallWithDNFLookALikeNamedParamPlain */',
],
'parens without owner, function call, named param + bitwise or' => [
'testMarker' => '/* testParensNoOwnerFunctionCallWithDNFLookALikeNamedParamUnion */',
],
'parens without owner, function call, named param + bitwise and' => [
'testMarker' => '/* testParensNoOwnerFunctionCallWithDNFLookALikeNamedParamIntersect */',
],

'parens without owner in OO const default value' => [
'testMarker' => '/* testParensNoOwnerOOConstDefaultValue */',
Expand Down